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
ktan2020/legacy-automation
win/Lib/site-packages/wx-3.0-msw/wx/lib/agw/customtreectrl.py
1
311049
# --------------------------------------------------------------------------------- # # CUSTOMTREECTRL wxPython IMPLEMENTATION # Inspired By And Heavily Based On wxGenericTreeCtrl. # # Andrea Gavana, @ 17 May 2006 # Latest Revision: 27 Aug 2012, 21.00 GMT # # # TODO List # # Almost All The Features Of wx.TreeCtrl Are Available, And There Is Practically # No Limit In What Could Be Added To This Class. The First Things That Comes # To My Mind Are: # # 1. Try To Implement A More Flicker-Free Background Image In Cases Like # Centered Or Stretched Image (Now CustomTreeCtrl Supports Only Tiled # Background Images). # # 2. Try To Mimic Windows wx.TreeCtrl Expanding/Collapsing behaviour: CustomTreeCtrl # Suddenly Expands/Collapses The Nodes On Mouse Click While The Native Control # Has Some Kind Of "Smooth" Expanding/Collapsing, Like A Wave. I Don't Even # Know Where To Start To Do That. # # 3. Speed Up General OnPaint Things? I Have No Idea, Here CustomTreeCtrl Is Quite # Fast, But We Should See On Slower Machines. # # # For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please # Write To Me At: # # andrea.gavana@maerskoil.com # andrea.gavana@gmail.com # # Or, Obviously, To The wxPython Mailing List!!! # # # End Of Comments # --------------------------------------------------------------------------------- # """ :class:`CustomTreeCtrl` is a class that mimics the behaviour of :class:`TreeCtrl`, with some more enhancements. Description =========== :class:`CustomTreeCtrl` is a class that mimics the behaviour of :class:`TreeCtrl`, with almost the same base functionalities plus some more enhancements. This class does not rely on the native control, as it is a full owner-drawn tree control. Apart of the base functionalities of :class:`CustomTreeCtrl` (described below), in addition to the standard :class:`TreeCtrl` behaviour this class supports: * CheckBox-type items: checkboxes are easy to handle, just selected or unselected state with no particular issues in handling the item's children; * Added support for 3-state value checkbox items; * RadioButton-type items: since I elected to put radiobuttons in :class:`CustomTreeCtrl`, I needed some way to handle them, that made sense. So, I used the following approach: - All peer-nodes that are radiobuttons will be mutually exclusive. In other words, only one of a set of radiobuttons that share a common parent can be checked at once. If a radiobutton node becomes checked, then all of its peer radiobuttons must be unchecked. - If a radiobutton node becomes unchecked, then all of its child nodes will become inactive. * Hyperlink-type items: they look like an hyperlink, with the proper mouse cursor on hovering; * Multiline text items (**note**: to add a newline character in a multiline item, press ``Shift`` + ``Enter`` as the ``Enter`` key alone is consumed by :class:`CustomTreeCtrl` to finish the editing and ``Ctrl`` + ``Enter`` is consumed by the platform for tab navigation); * Enabling/disabling items (together with their plain or grayed out icons); * Whatever non-toplevel widget can be attached next to an item; * Possibility to horizontally align the widgets attached to tree items on the same tree level. * Possibility to align the widgets attached to tree items to the rightmost edge of :class:`CustomTreeCtrl`; * Default selection style, gradient (horizontal/vertical) selection style and Windows Vista selection style; * Customized drag and drop images built on the fly; * Setting the :class:`CustomTreeCtrl` item buttons to a personalized imagelist; * Setting the :class:`CustomTreeCtrl` check/radio item icons to a personalized imagelist; * Changing the style of the lines that connect the items (in terms of :class:`Pen` styles); * Using an image as a :class:`CustomTreeCtrl` background (currently only in "tile" mode); * Adding images to any item in the leftmost area of the :class:`CustomTreeCtrl` client window. * Separator-type items which are simply visual indicators that are meant to set apart or divide tree items, with the following caveats: - Separator items should not have children, labels, data or an associated window; - You can change the color of individual separators by using meth:~CustomTreeCtrl.SetItemTextColour`, or you can use meth:~CustomTreeCtrl.SetSeparatorColour` to change the color of all separators. The default separator colour is that returned by `SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)`; - Separators can be selected just like any other tree item; - Separators cannot have text; - Separators cannot have children; - Separators cannot be edited via the ``EVT_TREE_BEGIN_LABEL_EDIT`` event. * Ellipsization of long items when the horizontal space is low, via the ``TR_ELLIPSIZE_LONG_ITEMS`` style (`New in version 0.9.3`); * Tooltips on long items when the horizontal space is low, via the ``TR_TOOLTIP_ON_LONG_ITEMS`` style (`New in version 0.9.3`). And a lot more. Check the demo for an almost complete review of the functionalities. Base Functionalities ==================== :class:`CustomTreeCtrl` supports all the :class:`TreeCtrl` styles, except: - ``TR_EXTENDED``: supports for this style is on the todo list (am I sure of this?). Plus it has 3 more styles to handle checkbox-type items: - ``TR_AUTO_CHECK_CHILD``: automatically checks/unchecks the item children; - ``TR_AUTO_CHECK_PARENT``: automatically checks/unchecks the item parent; - ``TR_AUTO_TOGGLE_CHILD``: automatically toggles the item children. And two styles you can use to force the horizontal alignment of all the widgets attached to the tree items: - ``TR_ALIGN_WINDOWS``: aligns horizontally the windows belonging to the item on the same tree level. - ``TR_ALIGN_WINDOWS_RIGHT``: aligns to the rightmost position the windows belonging to the item on the same tree level. And two styles related to long items (with a lot of text in them), which can be ellipsized and/or highlighted with a tooltip: - ``TR_ELLIPSIZE_LONG_ITEMS``: ellipsizes long items when the horizontal space for :class:`CustomTreeCtrl` is low (`New in version 0.9.3`); - ``TR_TOOLTIP_ON_LONG_ITEMS``: shows tooltips on long items when the horizontal space for :class:`CustomTreeCtrl` is low (`New in version 0.9.3`);. All the methods available in :class:`TreeCtrl` are also available in :class:`CustomTreeCtrl`. Usage ===== Usage example:: import wx import wx.lib.agw.customtreectrl as CT class MyFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init(self, parent, -1, "CustomTreeCtrl Demo") # Create a CustomTreeCtrl instance custom_tree = CT.CustomTreeCtrl(self, agwStyle=wx.TR_DEFAULT_STYLE) # Add a root node to it root = custom_tree.AddRoot("The Root Item") # Create an image list to add icons next to an item il = wx.ImageList(16, 16) fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, 16)) fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, 16)) fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, 16)) custom_tree.SetImageList(il) custom_tree.SetItemImage(root, fldridx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(root, fldropenidx, wx.TreeItemIcon_Expanded) for x in range(15): child = custom_tree.AppendItem(root, "Item %d" % x) custom_tree.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Expanded) for y in range(5): last = custom_tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y))) custom_tree.SetItemImage(last, fldridx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(last, fldropenidx, wx.TreeItemIcon_Expanded) for z in range(5): item = custom_tree.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z)) custom_tree.SetItemImage(item, fileidx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(item, smileidx, wx.TreeItemIcon_Selected) custom_tree.Expand(self.root) # our normal wxApp-derived class, as usual app = wx.App(0) frame = MyFrame(None) app.SetTopWindow(frame) frame.Show() app.MainLoop() Events ====== All the events supported by :class:`TreeCtrl` are also available in :class:`CustomTreeCtrl`, with a few exceptions: - ``EVT_TREE_GET_INFO`` (don't know what this means); - ``EVT_TREE_SET_INFO`` (don't know what this means); - ``EVT_TREE_ITEM_MIDDLE_CLICK`` (not implemented, but easy to add); - ``EVT_TREE_STATE_IMAGE_CLICK`` (no need for that, look at the checking events below). Plus, :class:`CustomTreeCtrl` supports the events related to the checkbutton-type items: - ``EVT_TREE_ITEM_CHECKING``: an item is being checked; - ``EVT_TREE_ITEM_CHECKED``: an item has been checked. And to hyperlink-type items: - ``EVT_TREE_ITEM_HYPERLINK``: an hyperlink item has been clicked (this event is sent after the ``EVT_TREE_SEL_CHANGED`` event). Supported Platforms =================== :class:`CustomTreeCtrl` has been tested on the following platforms: * Windows (Windows XP); * GTK (Thanks to Michele Petrazzo); * Mac OS (Thanks to John Jackson). Window Styles ============= This class supports the following window styles: ============================== =========== ================================================== Window Styles Hex Value Description ============================== =========== ================================================== ``TR_NO_BUTTONS`` 0x0 For convenience to document that no buttons are to be drawn. ``TR_SINGLE`` 0x0 For convenience to document that only one item may be selected at a time. Selecting another item causes the current selection, if any, to be deselected. This is the default. ``TR_HAS_BUTTONS`` 0x1 Use this style to show + and - buttons to the left of parent items. ``TR_NO_LINES`` 0x4 Use this style to hide vertical level connectors. ``TR_LINES_AT_ROOT`` 0x8 Use this style to show lines between root nodes. Only applicable if ``TR_HIDE_ROOT`` is set and ``TR_NO_LINES`` is not set. ``TR_DEFAULT_STYLE`` 0x9 The set of flags that are closest to the defaults for the native control for a particular toolkit. ``TR_TWIST_BUTTONS`` 0x10 Use old Mac-twist style buttons. ``TR_MULTIPLE`` 0x20 Use this style to allow a range of items to be selected. If a second range is selected, the current range, if any, is deselected. ``TR_EXTENDED`` 0x40 Use this style to allow disjoint items to be selected. (Only partially implemented; may not work in all cases). ``TR_HAS_VARIABLE_ROW_HEIGHT`` 0x80 Use this style to cause row heights to be just big enough to fit the content. If not set, all rows use the largest row height. The default is that this flag is unset. ``TR_EDIT_LABELS`` 0x200 Use this style if you wish the user to be able to edit labels in the tree control. ``TR_ROW_LINES`` 0x400 Use this style to draw a contrasting border between displayed rows. ``TR_HIDE_ROOT`` 0x800 Use this style to suppress the display of the root node, effectively causing the first-level nodes to appear as a series of root nodes. ``TR_FULL_ROW_HIGHLIGHT`` 0x2000 Use this style to have the background colour and the selection highlight extend over the entire horizontal row of the tree control window. ``TR_AUTO_CHECK_CHILD`` 0x4000 Only meaningful foe checkbox-type items: when a parent item is checked/unchecked its children are checked/unchecked as well. ``TR_AUTO_TOGGLE_CHILD`` 0x8000 Only meaningful foe checkbox-type items: when a parent item is checked/unchecked its children are toggled accordingly. ``TR_AUTO_CHECK_PARENT`` 0x10000 Only meaningful foe checkbox-type items: when a child item is checked/unchecked its parent item is checked/unchecked as well. ``TR_ALIGN_WINDOWS`` 0x20000 Flag used to align windows (in items with windows) at the same horizontal position. ``TR_ALIGN_WINDOWS_RIGHT`` 0x40000 Flag used to align windows (in items with windows) to the rightmost edge of :class:`CustomTreeCtrl`. ``TR_ELLIPSIZE_LONG_ITEMS`` 0x80000 Flag used to ellipsize long items when the horizontal space for :class:`CustomTreeCtrl` is low. ``TR_TOOLTIP_ON_LONG_ITEMS`` 0x100000 Flag used to show tooltips on long items when the horizontal space for :class:`CustomTreeCtrl` is low. ============================== =========== ================================================== Events Processing ================= This class processes the following events: ============================== ================================================== Event Name Description ============================== ================================================== ``EVT_TREE_BEGIN_DRAG`` Begin dragging with the left mouse button. ``EVT_TREE_BEGIN_LABEL_EDIT`` Begin editing a label. This can be prevented by calling meth:~TreeEvent.Veto`. ``EVT_TREE_BEGIN_RDRAG`` Begin dragging with the right mouse button. ``EVT_TREE_DELETE_ITEM`` Delete an item. ``EVT_TREE_END_DRAG`` End dragging with the left or right mouse button. ``EVT_TREE_END_LABEL_EDIT`` End editing a label. This can be prevented by calling meth:~TreeEvent.Veto`. ``EVT_TREE_GET_INFO`` Request information from the application (not implemented in :class:`CustomTreeCtrl`). ``EVT_TREE_ITEM_ACTIVATED`` The item has been activated, i.e. chosen by double clicking it with mouse or from keyboard. ``EVT_TREE_ITEM_CHECKED`` A checkbox or radiobox type item has been checked. ``EVT_TREE_ITEM_CHECKING`` A checkbox or radiobox type item is being checked. ``EVT_TREE_ITEM_COLLAPSED`` The item has been collapsed. ``EVT_TREE_ITEM_COLLAPSING`` The item is being collapsed. This can be prevented by calling meth:~TreeEvent.Veto`. ``EVT_TREE_ITEM_EXPANDED`` The item has been expanded. ``EVT_TREE_ITEM_EXPANDING`` The item is being expanded. This can be prevented by calling meth:~TreeEvent.Veto`. ``EVT_TREE_ITEM_GETTOOLTIP`` The opportunity to set the item tooltip is being given to the application (call `TreeEvent.SetToolTip`). ``EVT_TREE_ITEM_HYPERLINK`` An hyperlink type item has been clicked. ``EVT_TREE_ITEM_MENU`` The context menu for the selected item has been requested, either by a right click or by using the menu key. ``EVT_TREE_ITEM_MIDDLE_CLICK`` The user has clicked the item with the middle mouse button (not implemented in :class:`CustomTreeCtrl`). ``EVT_TREE_ITEM_RIGHT_CLICK`` The user has clicked the item with the right mouse button. ``EVT_TREE_KEY_DOWN`` A key has been pressed. ``EVT_TREE_SEL_CHANGED`` Selection has changed. ``EVT_TREE_SEL_CHANGING`` Selection is changing. This can be prevented by calling meth:~TreeEvent.Veto`. ``EVT_TREE_SET_INFO`` Information is being supplied to the application (not implemented in :class:`CustomTreeCtrl`). ``EVT_TREE_STATE_IMAGE_CLICK`` The state image has been clicked (not implemented in :class:`CustomTreeCtrl`). ============================== ================================================== License And Version =================== :class:`CustomTreeCtrl` is distributed under the wxPython license. Latest Revision: Andrea Gavana @ 27 Aug 2012, 21.00 GMT Version 2.6 """ # Version Info __version__ = "2.6" import wx from wx.lib.expando import ExpandoTextCtrl # ---------------------------------------------------------------------------- # Constants # ---------------------------------------------------------------------------- _NO_IMAGE = -1 _PIXELS_PER_UNIT = 10 # Start editing the current item after half a second (if the mouse hasn't # been clicked/moved) _DELAY = 500 # wxPython version string _VERSION_STRING = wx.VERSION_STRING # ---------------------------------------------------------------------------- # Constants # ---------------------------------------------------------------------------- # Enum for different images associated with a treectrl item TreeItemIcon_Normal = 0 # not selected, not expanded """ The tree item is not selected and not expanded. """ TreeItemIcon_Selected = 1 # selected, not expanded """ The tree item is selected and not expanded. """ TreeItemIcon_Expanded = 2 # not selected, expanded """ The tree item is not selected but expanded. """ TreeItemIcon_SelectedExpanded = 3 # selected, expanded """ The tree item is selected and expanded. """ TreeItemIcon_Checked = 0 # check button, checked """ The item's check button is checked. """ TreeItemIcon_NotChecked = 1 # check button, not checked """ The item's check button is not checked. """ TreeItemIcon_Undetermined = 2 # check button, undetermined """ The item's check button is in undetermined state (used only for a 3-state check button). """ TreeItemIcon_Flagged = 3 # radio button, selected """ The item's radio button is checked. """ TreeItemIcon_NotFlagged = 4 # radio button, not selected """ The item's radio button is not checked. """ # ---------------------------------------------------------------------------- # CustomTreeCtrl flags # ---------------------------------------------------------------------------- TR_NO_BUTTONS = wx.TR_NO_BUTTONS # for convenience """ For convenience to document that no buttons are to be drawn. """ TR_HAS_BUTTONS = wx.TR_HAS_BUTTONS # draw collapsed/expanded btns """ Use this style to show + and - buttons to the left of parent items. """ TR_NO_LINES = wx.TR_NO_LINES # don't draw lines at all """ Use this style to hide vertical level connectors. """ TR_LINES_AT_ROOT = wx.TR_LINES_AT_ROOT # connect top-level nodes """ Use this style to show lines between root nodes. Only applicable if ``TR_HIDE_ROOT`` is set and ``TR_NO_LINES`` is not set. """ TR_TWIST_BUTTONS = wx.TR_TWIST_BUTTONS # still used by wxTreeListCtrl """ Use old Mac-twist style buttons. """ TR_SINGLE = wx.TR_SINGLE # for convenience """ For convenience to document that only one item may be selected at a time. Selecting another item causes the current selection, if any, to be deselected. This is the default. """ TR_MULTIPLE = wx.TR_MULTIPLE # can select multiple items """ Use this style to allow a range of items to be selected. If a second range is selected, the current range, if any, is deselected. """ TR_EXTENDED = wx.TR_EXTENDED # TODO: allow extended selection """ Use this style to allow disjoint items to be selected. (Only partially implemented; may not work in all cases). """ TR_HAS_VARIABLE_ROW_HEIGHT = wx.TR_HAS_VARIABLE_ROW_HEIGHT # what it says """ Use this style to cause row heights to be just big enough to fit the content. If not set, all rows use the largest row height. The default is that this flag is unset. """ TR_EDIT_LABELS = wx.TR_EDIT_LABELS # can edit item labels """ Use this style if you wish the user to be able to edit labels in the tree control. """ TR_ROW_LINES = wx.TR_ROW_LINES # put border around items """ Use this style to draw a contrasting border between displayed rows. """ TR_HIDE_ROOT = wx.TR_HIDE_ROOT # don't display root node """ Use this style to suppress the display of the root node, effectively causing the first-level nodes to appear as a series of root nodes. """ TR_FULL_ROW_HIGHLIGHT = wx.TR_FULL_ROW_HIGHLIGHT # highlight full horz space """ Use this style to have the background colour and the selection highlight extend over the entire horizontal row of the tree control window. """ TR_AUTO_CHECK_CHILD = 0x04000 # only meaningful for checkboxes """ Only meaningful foe checkbox-type items: when a parent item is checked/unchecked its children are checked/unchecked as well. """ TR_AUTO_TOGGLE_CHILD = 0x08000 # only meaningful for checkboxes """ Only meaningful foe checkbox-type items: when a parent item is checked/unchecked its children are toggled accordingly. """ TR_AUTO_CHECK_PARENT = 0x10000 # only meaningful for checkboxes """ Only meaningful foe checkbox-type items: when a child item is checked/unchecked its parent item is checked/unchecked as well. """ TR_ALIGN_WINDOWS = 0x20000 # to align windows horizontally for items at the same level """ Flag used to align windows (in items with windows) at the same horizontal position. """ TR_ALIGN_WINDOWS_RIGHT = 0x40000 # to align windows to the rightmost edge of CustomTreeCtrl """ Flag used to align windows (in items with windows) to the rightmost edge of :class:`CustomTreeCtrl`.""" TR_ELLIPSIZE_LONG_ITEMS = 0x80000 # to ellipsize long items when horizontal space is low """ Flag used to ellipsize long items when the horizontal space for :class:`CustomTreeCtrl` is low.""" TR_TOOLTIP_ON_LONG_ITEMS = 0x100000 # to display tooltips on long items when horizontal space is low """ Flag used to show tooltips on long items when the horizontal space for :class:`CustomTreeCtrl` is low.""" TR_DEFAULT_STYLE = wx.TR_DEFAULT_STYLE # default style for the tree control """ The set of flags that are closest to the defaults for the native control for a particular toolkit. """ # Values for the `flags` parameter of CustomTreeCtrl.HitTest() which determine # where exactly the specified point is situated: TREE_HITTEST_ABOVE = wx.TREE_HITTEST_ABOVE """ Above the client area. """ TREE_HITTEST_BELOW = wx.TREE_HITTEST_BELOW """ Below the client area. """ TREE_HITTEST_NOWHERE = wx.TREE_HITTEST_NOWHERE """ No item has been hit. """ TREE_HITTEST_ONITEMBUTTON = wx.TREE_HITTEST_ONITEMBUTTON """ On the button associated with an item. """ TREE_HITTEST_ONITEMICON = wx.TREE_HITTEST_ONITEMICON """ On the bitmap associated with an item. """ TREE_HITTEST_ONITEMINDENT = wx.TREE_HITTEST_ONITEMINDENT """ On the indent associated with an item. """ TREE_HITTEST_ONITEMLABEL = wx.TREE_HITTEST_ONITEMLABEL """ On the label (string) associated with an item. """ TREE_HITTEST_ONITEMRIGHT = wx.TREE_HITTEST_ONITEMRIGHT """ On the right of the label associated with an item. """ TREE_HITTEST_ONITEMSTATEICON = wx.TREE_HITTEST_ONITEMSTATEICON """ On the right of the label associated with an item. """ TREE_HITTEST_TOLEFT = wx.TREE_HITTEST_TOLEFT """ On the left of an item. """ TREE_HITTEST_TORIGHT = wx.TREE_HITTEST_TORIGHT """ On the right of an item. """ TREE_HITTEST_ONITEMUPPERPART = wx.TREE_HITTEST_ONITEMUPPERPART """ On the upper part (first half) of the item. """ TREE_HITTEST_ONITEMLOWERPART = wx.TREE_HITTEST_ONITEMLOWERPART """ On the lower part (second half) of the item. """ TREE_HITTEST_ONITEMCHECKICON = 0x4000 """ On the check icon, if present. """ TREE_HITTEST_ONITEM = TREE_HITTEST_ONITEMICON | TREE_HITTEST_ONITEMLABEL | TREE_HITTEST_ONITEMCHECKICON """ Anywhere on the item. """ TREE_ITEMTYPE_NORMAL = 0 """ A normal item. """ TREE_ITEMTYPE_CHECK = 1 """ A checkbox-like item. """ TREE_ITEMTYPE_RADIO = 2 """ A radiobutton-like item. """ # Background Image Style _StyleTile = 0 _StyleStretch = 1 # Windows Vista Colours _rgbSelectOuter = wx.Colour(170, 200, 245) _rgbSelectInner = wx.Colour(230, 250, 250) _rgbSelectTop = wx.Colour(210, 240, 250) _rgbSelectBottom = wx.Colour(185, 215, 250) _rgbNoFocusTop = wx.Colour(250, 250, 250) _rgbNoFocusBottom = wx.Colour(235, 235, 235) _rgbNoFocusOuter = wx.Colour(220, 220, 220) _rgbNoFocusInner = wx.Colour(245, 245, 245) # Flags for wx.RendererNative _CONTROL_EXPANDED = 8 _CONTROL_CURRENT = 16 # ---------------------------------------------------------------------------- # CustomTreeCtrl events and binding for handling them # ---------------------------------------------------------------------------- wxEVT_TREE_BEGIN_DRAG = wx.wxEVT_COMMAND_TREE_BEGIN_DRAG wxEVT_TREE_BEGIN_RDRAG = wx.wxEVT_COMMAND_TREE_BEGIN_RDRAG wxEVT_TREE_BEGIN_LABEL_EDIT = wx.wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT wxEVT_TREE_END_LABEL_EDIT = wx.wxEVT_COMMAND_TREE_END_LABEL_EDIT wxEVT_TREE_DELETE_ITEM = wx.wxEVT_COMMAND_TREE_DELETE_ITEM wxEVT_TREE_GET_INFO = wx.wxEVT_COMMAND_TREE_GET_INFO wxEVT_TREE_SET_INFO = wx.wxEVT_COMMAND_TREE_SET_INFO wxEVT_TREE_ITEM_EXPANDED = wx.wxEVT_COMMAND_TREE_ITEM_EXPANDED wxEVT_TREE_ITEM_EXPANDING = wx.wxEVT_COMMAND_TREE_ITEM_EXPANDING wxEVT_TREE_ITEM_COLLAPSED = wx.wxEVT_COMMAND_TREE_ITEM_COLLAPSED wxEVT_TREE_ITEM_COLLAPSING = wx.wxEVT_COMMAND_TREE_ITEM_COLLAPSING wxEVT_TREE_SEL_CHANGED = wx.wxEVT_COMMAND_TREE_SEL_CHANGED wxEVT_TREE_SEL_CHANGING = wx.wxEVT_COMMAND_TREE_SEL_CHANGING wxEVT_TREE_KEY_DOWN = wx.wxEVT_COMMAND_TREE_KEY_DOWN wxEVT_TREE_ITEM_ACTIVATED = wx.wxEVT_COMMAND_TREE_ITEM_ACTIVATED wxEVT_TREE_ITEM_RIGHT_CLICK = wx.wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK wxEVT_TREE_ITEM_MIDDLE_CLICK = wx.wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK wxEVT_TREE_END_DRAG = wx.wxEVT_COMMAND_TREE_END_DRAG wxEVT_TREE_STATE_IMAGE_CLICK = wx.wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK wxEVT_TREE_ITEM_GETTOOLTIP = wx.wxEVT_COMMAND_TREE_ITEM_GETTOOLTIP wxEVT_TREE_ITEM_MENU = wx.wxEVT_COMMAND_TREE_ITEM_MENU wxEVT_TREE_ITEM_CHECKING = wx.NewEventType() wxEVT_TREE_ITEM_CHECKED = wx.NewEventType() wxEVT_TREE_ITEM_HYPERLINK = wx.NewEventType() EVT_TREE_BEGIN_DRAG = wx.EVT_TREE_BEGIN_DRAG """ Begin dragging with the left mouse button. """ EVT_TREE_BEGIN_RDRAG = wx.EVT_TREE_BEGIN_RDRAG """ Begin dragging with the right mouse button. """ EVT_TREE_BEGIN_LABEL_EDIT = wx.EVT_TREE_BEGIN_LABEL_EDIT """ Begin editing a label. This can be prevented by calling meth:~TreeEvent.Veto`. """ EVT_TREE_END_LABEL_EDIT = wx.EVT_TREE_END_LABEL_EDIT """ End editing a label. This can be prevented by calling meth:~TreeEvent.Veto`. """ EVT_TREE_DELETE_ITEM = wx.EVT_TREE_DELETE_ITEM """ Delete an item. """ EVT_TREE_GET_INFO = wx.EVT_TREE_GET_INFO """ Request information from the application (not implemented in :class:`CustomTreeCtrl`). """ EVT_TREE_SET_INFO = wx.EVT_TREE_SET_INFO """ Information is being supplied to the application (not implemented in :class:`CustomTreeCtrl`). """ EVT_TREE_ITEM_EXPANDED = wx.EVT_TREE_ITEM_EXPANDED """ The item has been expanded. """ EVT_TREE_ITEM_EXPANDING = wx.EVT_TREE_ITEM_EXPANDING """ The item is being expanded. This can be prevented by calling meth:~TreeEvent.Veto`. """ EVT_TREE_ITEM_COLLAPSED = wx.EVT_TREE_ITEM_COLLAPSED """ The item has been collapsed. """ EVT_TREE_ITEM_COLLAPSING = wx.EVT_TREE_ITEM_COLLAPSING """ The item is being collapsed. This can be prevented by calling meth:~TreeEvent.Veto`. """ EVT_TREE_SEL_CHANGED = wx.EVT_TREE_SEL_CHANGED """ Selection has changed. """ EVT_TREE_SEL_CHANGING = wx.EVT_TREE_SEL_CHANGING """ Selection is changing. This can be prevented by calling meth:~TreeEvent.Veto`. """ EVT_TREE_KEY_DOWN = wx.EVT_TREE_KEY_DOWN """ A key has been pressed. """ EVT_TREE_ITEM_ACTIVATED = wx.EVT_TREE_ITEM_ACTIVATED """ The item has been activated, i.e. chosen by double clicking it with mouse or from keyboard. """ EVT_TREE_ITEM_RIGHT_CLICK = wx.EVT_TREE_ITEM_RIGHT_CLICK """ The user has clicked the item with the right mouse button. """ EVT_TREE_ITEM_MIDDLE_CLICK = wx.EVT_TREE_ITEM_MIDDLE_CLICK """ The user has clicked the item with the middle mouse button (not implemented in :class:`CustomTreeCtrl`). """ EVT_TREE_END_DRAG = wx.EVT_TREE_END_DRAG """ End dragging with the left or right mouse button. """ EVT_TREE_STATE_IMAGE_CLICK = wx.EVT_TREE_STATE_IMAGE_CLICK """ The state image has been clicked (not implemented in :class:`CustomTreeCtrl`). """ EVT_TREE_ITEM_GETTOOLTIP = wx.EVT_TREE_ITEM_GETTOOLTIP """ The opportunity to set the item tooltip is being given to the application (call `TreeEvent.SetToolTip`). """ EVT_TREE_ITEM_MENU = wx.EVT_TREE_ITEM_MENU """ The context menu for the selected item has been requested, either by a right click or by using the menu key. """ EVT_TREE_ITEM_CHECKING = wx.PyEventBinder(wxEVT_TREE_ITEM_CHECKING, 1) """ A checkbox or radiobox type item is being checked. """ EVT_TREE_ITEM_CHECKED = wx.PyEventBinder(wxEVT_TREE_ITEM_CHECKED, 1) """ A checkbox or radiobox type item has been checked. """ EVT_TREE_ITEM_HYPERLINK = wx.PyEventBinder(wxEVT_TREE_ITEM_HYPERLINK, 1) """ An hyperlink type item has been clicked. """ # ---------------------------------------------------------------------------- def MakeDisabledBitmap(original): """ Creates a disabled-looking bitmap starting from the input one. :param `original`: an instance of :class:`Bitmap` to be greyed-out. :return: An instance of :class:`Bitmap`, containing a disabled-looking representation of the original item image. """ img = original.ConvertToImage() return wx.BitmapFromImage(img.ConvertToGreyscale()) # ---------------------------------------------------------------------------- def DrawTreeItemButton(win, dc, rect, flags): """ Draw the expanded/collapsed icon for a tree control item. :param `win`: an instance of :class:`Window`; :param `dc`: an instance of :class:`DC`; :param Rect `rect`: the client rectangle where to draw the tree item button; :param integer `flags`: contains ``wx.CONTROL_EXPANDED`` bit for expanded tree items. :note: This is a simple replacement of :meth:`RendererNative.DrawTreeItemButton`. :note: This method is never used in wxPython versions newer than 2.6.2.1. """ # white background dc.SetPen(wx.GREY_PEN) dc.SetBrush(wx.WHITE_BRUSH) dc.DrawRectangleRect(rect) # black lines xMiddle = rect.x + rect.width/2 yMiddle = rect.y + rect.height/2 # half of the length of the horz lines in "-" and "+" halfWidth = rect.width/2 - 2 dc.SetPen(wx.BLACK_PEN) dc.DrawLine(xMiddle - halfWidth, yMiddle, xMiddle + halfWidth + 1, yMiddle) if not flags & _CONTROL_EXPANDED: # turn "-" into "+" halfHeight = rect.height/2 - 2 dc.DrawLine(xMiddle, yMiddle - halfHeight, xMiddle, yMiddle + halfHeight + 1) # ---------------------------------------------------------------------------- def EventFlagsToSelType(style, shiftDown=False, ctrlDown=False): """ Translate the key or mouse event flag to the type of selection we are dealing with. :param integer `style`: the main :class:`CustomTreeCtrl` window style flag; :param bool `shiftDown`: ``True`` if the ``Shift`` key is pressed, ``False`` otherwise; :param bool `ctrlDown`: ``True`` if the ``Ctrl`` key is pressed, ``False`` otherwise; :return: A 3-elements tuple, with the following elements: - `is_multiple`: ``True`` if :class:`CustomTreeCtrl` has the ``TR_MULTIPLE`` flag set, ``False`` otherwise; - `extended_select`: ``True`` if the ``Shift`` key is pressend and if :class:`CustomTreeCtrl` has the ``TR_MULTIPLE`` flag set, ``False`` otherwise; - `unselect_others`: ``True`` if the ``Ctrl`` key is pressend and if :class:`CustomTreeCtrl` has the ``TR_MULTIPLE`` flag set, ``False`` otherwise. """ is_multiple = (style & TR_MULTIPLE) != 0 extended_select = shiftDown and is_multiple unselect_others = not (extended_select or (ctrlDown and is_multiple)) return is_multiple, extended_select, unselect_others # ---------------------------------------------------------------------------- def ChopText(dc, text, max_size): """ Chops the input `text` if its size does not fit in `max_size`, by cutting the text and adding ellipsis at the end. :param `dc`: a :class:`DC` device context; :param `text`: the text to chop; :param `max_size`: the maximum size in which the text should fit. :note: This method is used exclusively when :class:`CustomTreeCtrl` has the ``TR_ELLIPSIZE_LONG_ITEMS`` style set. .. versionadded:: 0.9.3 """ # first check if the text fits with no problems x, y, dummy = dc.GetMultiLineTextExtent(text) if x <= max_size: return text textLen = len(text) last_good_length = 0 for i in xrange(textLen, -1, -1): s = text[0:i] s += "..." x, y = dc.GetTextExtent(s) last_good_length = i if x < max_size: break ret = text[0:last_good_length] + "..." return ret #--------------------------------------------------------------------------- # DragImage Implementation # This Class Handles The Creation Of A Custom Image In Case Of Item Drag # And Drop. #--------------------------------------------------------------------------- class DragImage(wx.DragImage): """ This class handles the creation of a custom image in case of item drag and drop. """ def __init__(self, treeCtrl, item): """ Default class constructor. For internal use: do not call it in your code! :param `treeCtrl`: the parent :class:`CustomTreeCtrl`; :param `item`: one of the tree control item (an instance of :class:`GenericTreeItem`). """ text = item.GetText() font = item.Attr().GetFont() colour = item.Attr().GetTextColour() if not colour: colour = wx.BLACK if not font: font = treeCtrl._normalFont backcolour = treeCtrl.GetBackgroundColour() r, g, b = int(backcolour.Red()), int(backcolour.Green()), int(backcolour.Blue()) backcolour = ((r >> 1) + 20, (g >> 1) + 20, (b >> 1) + 20) backcolour = wx.Colour(backcolour[0], backcolour[1], backcolour[2]) self._backgroundColour = backcolour tempdc = wx.ClientDC(treeCtrl) tempdc.SetFont(font) width, height, dummy = tempdc.GetMultiLineTextExtent(text + "M") image = item.GetCurrentImage() image_w, image_h = 0, 0 wcheck, hcheck = 0, 0 itemcheck = None itemimage = None ximagepos = 0 yimagepos = 0 xcheckpos = 0 ycheckpos = 0 if image != _NO_IMAGE: if treeCtrl._imageListNormal: image_w, image_h = treeCtrl._imageListNormal.GetSize(image) image_w += 4 itemimage = treeCtrl._imageListNormal.GetBitmap(image) checkimage = item.GetCurrentCheckedImage() if checkimage is not None: if treeCtrl._imageListCheck: wcheck, hcheck = treeCtrl._imageListCheck.GetSize(checkimage) wcheck += 4 itemcheck = treeCtrl._imageListCheck.GetBitmap(checkimage) total_h = max(hcheck, height) total_h = max(image_h, total_h) if image_w: ximagepos = wcheck yimagepos = ((total_h > image_h) and [(total_h-image_h)/2] or [0])[0] if checkimage is not None: xcheckpos = 2 ycheckpos = ((total_h > image_h) and [(total_h-image_h)/2] or [0])[0] + 2 extraH = ((total_h > height) and [(total_h - height)/2] or [0])[0] xtextpos = wcheck + image_w ytextpos = extraH total_h = max(image_h, hcheck) total_h = max(total_h, height) if total_h < 30: total_h += 2 # at least 2 pixels else: total_h += total_h/10 # otherwise 10% extra spacing total_w = image_w + wcheck + width self._total_w = total_w self._total_h = total_h self._itemimage = itemimage self._itemcheck = itemcheck self._text = text self._colour = colour self._font = font self._xtextpos = xtextpos self._ytextpos = ytextpos self._ximagepos = ximagepos self._yimagepos = yimagepos self._xcheckpos = xcheckpos self._ycheckpos = ycheckpos self._textwidth = width self._textheight = height self._extraH = extraH self._bitmap = self.CreateBitmap() wx.DragImage.__init__(self, self._bitmap) def CreateBitmap(self): """ Actually creates the drag and drop bitmap for :class:`DragImage`. :return: An instance of :class:`DragImage`, a close representation of the item's appearance (i.e., a screenshot of the item). """ memory = wx.MemoryDC() bitmap = wx.EmptyBitmap(self._total_w, self._total_h) memory.SelectObject(bitmap) if wx.Platform == '__WXMAC__': memory.SetBackground(wx.TRANSPARENT_BRUSH) else: memory.SetBackground(wx.Brush(self._backgroundColour)) memory.SetBackgroundMode(wx.TRANSPARENT) memory.SetFont(self._font) memory.SetTextForeground(self._colour) memory.Clear() if self._itemimage: memory.DrawBitmap(self._itemimage, self._ximagepos, self._yimagepos, True) if self._itemcheck: memory.DrawBitmap(self._itemcheck, self._xcheckpos, self._ycheckpos, True) textrect = wx.Rect(self._xtextpos, self._ytextpos+self._extraH, self._textwidth, self._textheight) memory.DrawLabel(self._text, textrect) memory.SelectObject(wx.NullBitmap) # Gtk and Windows unfortunatly don't do so well with transparent # drawing so this hack corrects the image to have a transparent # background. if wx.Platform != '__WXMAC__': timg = bitmap.ConvertToImage() if not timg.HasAlpha(): timg.InitAlpha() for y in xrange(timg.GetHeight()): for x in xrange(timg.GetWidth()): pix = wx.Colour(timg.GetRed(x, y), timg.GetGreen(x, y), timg.GetBlue(x, y)) if pix == self._backgroundColour: timg.SetAlpha(x, y, 0) bitmap = timg.ConvertToBitmap() return bitmap # ---------------------------------------------------------------------------- # TreeItemAttr: a structure containing the visual attributes of an item # ---------------------------------------------------------------------------- class TreeItemAttr(object): """ Creates the item attributes (text colour, background colour and font). :note: This class is inspired by the wxWidgets generic implementation of :class:`TreeItemAttr`. """ def __init__(self, colText=wx.NullColour, colBack=wx.NullColour, colBorder=wx.NullColour,font=wx.NullFont): """ Default class constructor. For internal use: do not call it in your code! :param `colText`: the text colour, an instance of :class:`Colour`; :param `colBack`: the tree item background colour, an instance of :class:`Colour`; :param `colBorder`: the tree item border colour, an instance of :class:`Colour`; :param `font`: the tree item font, an instance of :class:`Font`. """ self._colText = colText self._colBack = colBack self._colBorder = colBorder self._font = font # setters def SetTextColour(self, colText): """ Sets the text colour attribute. :param `colText`: an instance of :class:`Colour`. """ self._colText = colText def SetBackgroundColour(self, colBack): """ Sets the item background colour attribute. :param `colBack`: an instance of :class:`Colour`. """ self._colBack = colBack def SetBorderColour(self,colBorder): """ Sets the item border colour attribute. :param `colBack`: an instance of :class:`Colour`. .. versionadded:: 0.9.6 """ self._colBorder = colBorder def SetFont(self, font): """ Sets the item font attribute. :param `font`: an instance of :class:`Font`. """ self._font = font # accessors def HasTextColour(self): """ Returns whether the attribute has text colour. :return: ``True`` if the text colour attribute has been set, ``False`` otherwise. """ return self._colText != wx.NullColour def HasBackgroundColour(self): """ Returns whether the attribute has background colour. :return: ``True`` if the background colour attribute has been set, ``False`` otherwise. """ return self._colBack != wx.NullColour def HasBorderColour(self): """ Returns whether the attribute has border colour. :return: ``True`` if the border colour attribute has been set, ``False`` otherwise. .. versionadded:: 0.9.6 """ return self._colBorder != wx.NullColour def HasFont(self): """ Returns whether the attribute has font. :return: ``True`` if the font attribute has been set, ``False`` otherwise. """ return self._font != wx.NullFont # getters def GetTextColour(self): """ Returns the attribute text colour. :return: An instance of :class:`Colour`. """ return self._colText def GetBackgroundColour(self): """ Returns the attribute background colour. :return: An instance of :class:`Colour`. """ return self._colBack def GetBorderColour(self): """ Returns the attribute border colour. :return: An instance of :class:`Colour`. .. versionadded:: 0.9.6 """ return self._colBorder def GetFont(self): """ Returns the attribute font. :return: An instance of :class:`Font`. """ return self._font # ---------------------------------------------------------------------------- # CommandTreeEvent Is A Special Subclassing Of wx.PyCommandEvent # # NB: Note That Not All The Accessors Make Sense For All The Events, See The # Event Description Below. # ---------------------------------------------------------------------------- class CommandTreeEvent(wx.PyCommandEvent): """ :class:`CommandTreeEvent` is a special subclassing of :class:`PyCommandEvent`. :note: Not all the accessors make sense for all the events, see the event description for every method in this class. """ def __init__(self, evtType, evtId, item=None, evtKey=None, point=None, label=None, **kwargs): """ Default class constructor. For internal use: do not call it in your code! :param integer `evtType`: the event type; :param integer `evtId`: the event identifier; :param `item`: an instance of :class:`GenericTreeItem`; :param integer `evtKey`: a character ordinal; :param `point`: an instance of :class:`Point`; :param string `label`: a :class:`GenericTreeItem` text label. """ wx.PyCommandEvent.__init__(self, evtType, evtId, **kwargs) self._item = item self._evtKey = evtKey self._pointDrag = point self._label = label def GetItem(self): """ Gets the item on which the operation was performed or the newly selected item for ``EVT_TREE_SEL_CHANGED`` and ``EVT_TREE_SEL_CHANGING`` events. :return: An instance of :class:`GenericTreeItem`. """ return self._item def SetItem(self, item): """ Sets the item on which the operation was performed or the newly selected item for ``EVT_TREE_SEL_CHANGED`` and ``EVT_TREE_SEL_CHANGING`` events. :param `item`: an instance of :class:`GenericTreeItem`. """ self._item = item def GetOldItem(self): """ Returns the previously selected item for ``EVT_TREE_SEL_CHANGED`` and ``EVT_TREE_SEL_CHANGING`` events. :return: An instance of :class:`GenericTreeItem`. """ return self._itemOld def SetOldItem(self, item): """ Returns the previously selected item for ``EVT_TREE_SEL_CHANGED`` and ``EVT_TREE_SEL_CHANGING`` events. :param `item`: an instance of :class:`GenericTreeItem`. """ self._itemOld = item def GetPoint(self): """ Returns the point where the mouse was when the drag operation started (for ``EVT_TREE_BEGIN_DRAG`` and ``EVT_TREE_BEGIN_RDRAG`` events only) or the click position. :return: An instance of :class:`Point`. """ return self._pointDrag def SetPoint(self, pt): """ Sets the point where the mouse was when the drag operation started (for ``EVT_TREE_BEGIN_DRAG`` and ``EVT_TREE_BEGIN_RDRAG`` events only) or the click position. :param `pt`: an instance of :class:`Point`. """ self._pointDrag = pt def GetKeyEvent(self): """ Returns the keyboard data (for ``EVT_TREE_KEY_DOWN`` event only). :return: An instance of :class:`KeyEvent`. """ return self._evtKey def GetKeyCode(self): """ Returns the virtual key code. ASCII events return normal ASCII values, while non-ASCII events return values such as ``wx.WXK_LEFT`` for the left cursor key. This method is for ``EVT_TREE_KEY_DOWN`` events only. :return: An integer representing the virtual key code. :note: In Unicode build, the returned value is meaningful only if the user entered a character that can be represented in current locale's default charset. You can obtain the corresponding Unicode character using `GetUnicodeKey`. """ return self._evtKey.GetKeyCode() def SetKeyEvent(self, event): """ Sets the keyboard data (for ``EVT_TREE_KEY_DOWN`` event only). :param `event`: a :class:`CommandTreeEvent` event to be processed. """ self._evtKey = event def GetLabel(self): """ Returns the item text (for ``EVT_TREE_BEGIN_LABEL_EDIT`` and ``EVT_TREE_END_LABEL_EDIT`` events only). :return: A string containing the item text. """ return self._label def SetLabel(self, label): """ Sets the item text (for ``EVT_TREE_BEGIN_LABEL_EDIT`` and ``EVT_TREE_END_LABEL_EDIT`` events only). :param string `label`: a string containing the new item text. """ self._label = label def IsEditCancelled(self): """ Returns the edit cancel flag (for ``EVT_TREE_BEGIN_LABEL_EDIT`` and ``EVT_TREE_END_LABEL_EDIT`` events only). :return: ``True`` is the item editing has been cancelled, ``False`` otherwise. """ return self._editCancelled def SetEditCanceled(self, editCancelled): """ Sets the edit cancel flag (for ``EVT_TREE_BEGIN_LABEL_EDIT`` and ``EVT_TREE_END_LABEL_EDIT`` events only). :param bool `editCancelled`: ``True`` to cancel the editing, ``False`` otherwise. """ self._editCancelled = editCancelled def SetToolTip(self, toolTip): """ Sets the tooltip for the item (for ``EVT_TREE_ITEM_GETTOOLTIP`` events). :param string `tooltip`: a string representing the item tooltip. """ self._label = toolTip def GetToolTip(self): """ Returns the tooltip for the item (for ``EVT_TREE_ITEM_GETTOOLTIP`` events). :return: A string containing the item tooltip. """ return self._label # ---------------------------------------------------------------------------- # TreeEvent is a special class for all events associated with tree controls # # NB: note that not all accessors make sense for all events, see the event # descriptions below # ---------------------------------------------------------------------------- class TreeEvent(CommandTreeEvent): """ :class:`CommandTreeEvent` is a special class for all events associated with tree controls. :note: Not all accessors make sense for all events, see the event descriptions below. """ def __init__(self, evtType, evtId, item=None, evtKey=None, point=None, label=None, **kwargs): """ Default class constructor. For internal use: do not call it in your code! :param integer `evtType`: the event type; :param integer `evtId`: the event identifier; :param `item`: an instance of :class:`GenericTreeItem`; :param integer `evtKey`: a character ordinal; :param `point`: an instance of :class:`Point`; :param string `label`: a :class:`GenericTreeItem` text label. """ CommandTreeEvent.__init__(self, evtType, evtId, item, evtKey, point, label, **kwargs) self.notify = wx.NotifyEvent(evtType, evtId) def GetNotifyEvent(self): """ Returns the actual :class:`NotifyEvent`. :return: An instance of :class:`NotifyEvent`. """ return self.notify def IsAllowed(self): """ Returns ``True`` if the change is allowed (:meth:`~TreeEvent.Veto` hasn't been called) or ``False`` otherwise (if it was). """ return self.notify.IsAllowed() def Veto(self): """ Prevents the change announced by this event from happening. :note: It is in general a good idea to notify the user about the reasons for vetoing the change because otherwise the applications behaviour (which just refuses to do what the user wants) might be quite surprising. """ self.notify.Veto() def Allow(self): """ This is the opposite of :meth:`~TreeEvent.Veto`: it explicitly allows the event to be processed. For most events it is not necessary to call this method as the events are allowed anyhow but some are forbidden by default (this will be mentioned in the corresponding event description). """ self.notify.Allow() # ----------------------------------------------------------------------------- # Auxiliary Classes: TreeEditTimer # ----------------------------------------------------------------------------- class TreeEditTimer(wx.Timer): """ Timer used for enabling in-place edit.""" def __init__(self, owner): """ Default class constructor. For internal use: do not call it in your code! :param `owner`: the :class:`Timer` owner (an instance of :class:`CustomTreeCtrl`). """ wx.Timer.__init__(self) self._owner = owner def Notify(self): """ The timer has expired, starts the item editing. """ self._owner.OnEditTimer() # ----------------------------------------------------------------------------- # Auxiliary Classes: TreeTextCtrl # This Is The Temporary ExpandoTextCtrl Created When You Edit The Text Of An Item # ----------------------------------------------------------------------------- class TreeTextCtrl(ExpandoTextCtrl): """ Control used for in-place edit. This is a subclass of :class:`lib.expando.ExpandoTextCtrl` as :class:`CustomTreeCtrl` supports multiline text items. :note: To add a newline character in a multiline item, press ``Shift`` + ``Enter`` as the ``Enter`` key alone is consumed by :class:`CustomTreeCtrl` to finish the editing and ``Ctrl`` + ``Enter`` is consumed by the platform for tab navigation. """ def __init__(self, owner, item=None): """ Default class constructor. For internal use: do not call it in your code! :param `owner`: the control parent (an instance of :class:`CustomTreeCtrl`); :param `item`: an instance of :class:`GenericTreeItem`. :raise: `Exception` when the item has an associated image but the parent :class:`CustomTreeCtrl` does not have a :class:`ImageList` assigned. """ self._owner = owner self._itemEdited = item self._startValue = item.GetText() self._finished = False self._aboutToFinish = False self._currentValue = self._startValue w = self._itemEdited.GetWidth() h = self._itemEdited.GetHeight() wnd = self._itemEdited.GetWindow() if wnd: w = w - self._itemEdited.GetWindowSize()[0] h = 0 x, y = self._owner.CalcScrolledPosition(item.GetX(), item.GetY()) image_h = 0 image_w = 0 image = item.GetCurrentImage() if image != _NO_IMAGE: if self._owner._imageListNormal: image_w, image_h = self._owner._imageListNormal.GetSize(image) image_w += 4 else: raise Exception("\n ERROR: You Must Create An Image List To Use Images!") checkimage = item.GetCurrentCheckedImage() if checkimage is not None: wcheck, hcheck = self._owner._imageListCheck.GetSize(checkimage) wcheck += 4 else: wcheck = hcheck = 0 if wnd: h = max(hcheck, image_h) dc = wx.ClientDC(self._owner) h = max(h, dc.GetTextExtent("Aq")[1]) h = h + 2 # FIXME: what are all these hardcoded 4, 8 and 11s really? x += image_w + wcheck w -= image_w + 4 + wcheck expandoStyle = wx.WANTS_CHARS if wx.Platform in ["__WXGTK__", "__WXMAC__"]: expandoStyle |= wx.SIMPLE_BORDER xSize, ySize = w + 25, h else: expandoStyle |= wx.SUNKEN_BORDER xSize, ySize = w + 25, h+2 ExpandoTextCtrl.__init__(self, self._owner, wx.ID_ANY, self._startValue, wx.Point(x - 4, y), wx.Size(xSize, ySize), expandoStyle) if wx.Platform == "__WXMAC__": self.SetFont(owner.GetFont()) bs = self.GetBestSize() self.SetSize((-1, bs.height)) self.Bind(wx.EVT_CHAR, self.OnChar) self.Bind(wx.EVT_KEY_UP, self.OnKeyUp) self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) def AcceptChanges(self): """ Accepts/rejects the changes made by the user. :return: ``True`` if the changes to the item text have been accepted, ``False`` if they have been rejected (i.e., vetoed by the user). """ value = self.GetValue() if value == self._startValue: # nothing changed, always accept # when an item remains unchanged, the owner # needs to be notified that the user decided # not to change the tree item label, and that # the edit has been cancelled self._owner.OnCancelEdit(self._itemEdited) return True if not self._owner.OnAcceptEdit(self._itemEdited, value): # vetoed by the user return False # accepted, do rename the item self._owner.SetItemText(self._itemEdited, value) return True def Finish(self): """ Finish editing. """ if not self._finished: self._finished = True self._owner.SetFocusIgnoringChildren() self._owner.ResetEditControl() def OnChar(self, event): """ Handles the ``wx.EVT_CHAR`` event for :class:`TreeTextCtrl`. :param `event`: a :class:`KeyEvent` event to be processed. """ keycode = event.GetKeyCode() shiftDown = event.ShiftDown() if keycode in [wx.WXK_RETURN, wx.WXK_NUMPAD_ENTER]: if shiftDown: event.Skip() else: self._aboutToFinish = True self.SetValue(self._currentValue) # Notify the owner about the changes self.AcceptChanges() # Even if vetoed, close the control (consistent with MSW) wx.CallAfter(self.Finish) elif keycode == wx.WXK_ESCAPE: self.StopEditing() else: event.Skip() def OnKeyUp(self, event): """ Handles the ``wx.EVT_KEY_UP`` event for :class:`TreeTextCtrl`. :param `event`: a :class:`KeyEvent` event to be processed. """ if not self._finished: # auto-grow the textctrl: parentSize = self._owner.GetSize() myPos = self.GetPosition() mySize = self.GetSize() dc = wx.ClientDC(self) sx, sy, dummy = dc.GetMultiLineTextExtent(self.GetValue() + "M") if myPos.x + sx > parentSize.x: sx = parentSize.x - myPos.x if mySize.x > sx: sx = mySize.x self.SetSize((sx, -1)) self._currentValue = self.GetValue() event.Skip() def OnKillFocus(self, event): """ Handles the ``wx.EVT_KILL_FOCUS`` event for :class:`TreeTextCtrl`. :param `event`: a :class:`FocusEvent` event to be processed. """ if not self._finished and not self._aboutToFinish: # We must finish regardless of success, otherwise we'll get # focus problems: if not self.AcceptChanges(): self._owner.OnCancelEdit(self._itemEdited) # We must let the native text control handle focus, too, otherwise # it could have problems with the cursor (e.g., in wxGTK). event.Skip() def StopEditing(self): """ Suddenly stops the editing. """ self._owner.OnCancelEdit(self._itemEdited) self.Finish() def item(self): """ Returns the item currently edited. :return: An instance of :class:`GenericTreeItem`. """ return self._itemEdited # ----------------------------------------------------------------------------- # Auxiliary Classes: TreeFindTimer # Timer Used To Clear CustomTreeCtrl._findPrefix If No Key Was Pressed For A # Sufficiently Long Time. # ----------------------------------------------------------------------------- class TreeFindTimer(wx.Timer): """ Timer used to clear the :class:`CustomTreeCtrl` `_findPrefix` attribute if no key was pressed for a sufficiently long time. """ def __init__(self, owner): """ Default class constructor. For internal use: do not call it in your code! :param `owner`: the :class:`Timer` owner (an instance of :class:`CustomTreeCtrl`). """ wx.Timer.__init__(self) self._owner = owner def Notify(self): """ The timer has expired, clear the `_findPrefix` attribute in :class:`CustomTreeCtrl`. """ self._owner._findPrefix = "" # ----------------------------------------------------------------------------- # GenericTreeItem Implementation. # This Class Holds All The Information And Methods For Every Single Item In # CustomTreeCtrl. # ----------------------------------------------------------------------------- class GenericTreeItem(object): """ This class holds all the information and methods for every single item in :class:`CustomTreeCtrl`. This is a generic implementation of :class:`TreeItem`. """ def __init__(self, parent, text="", ct_type=0, wnd=None, image=-1, selImage=-1, data=None, separator=False): """ Default class constructor. For internal use: do not call it in your code! :param `parent`: the tree item parent, an instance of :class:`GenericTreeItem` (may be ``None`` for root items); :param string `text`: the tree item text; :param integer `ct_type`: the tree item kind. May be one of the following integers: =============== ========================================= `ct_type` Value Description =============== ========================================= 0 A normal item 1 A checkbox-like item 2 A radiobutton-type item =============== ========================================= :param `wnd`: if not ``None``, a non-toplevel window to be displayed next to the item, an instance of :class:`Window`; :param integer `image`: an index within the normal image list specifying the image to use for the item in unselected state; :param integer `selImage`: an index within the normal image list specifying the image to use for the item in selected state; if `image` > -1 and `selImage` is -1, the same image is used for both selected and unselected items; :param object `data`: associate the given Python object `data` with the item; :param bool `separator`: ``True`` if the item is a separator, ``False`` otherwise. :note: Regarding radiobutton-type items (with `ct_type` = 2), the following approach is used: - All peer-nodes that are radiobuttons will be mutually exclusive. In other words, only one of a set of radiobuttons that share a common parent can be checked at once. If a radiobutton node becomes checked, then all of its peer radiobuttons must be unchecked. - If a radiobutton node becomes unchecked, then all of its child nodes will become inactive. :note: Separator items should not have children, labels, data or an associated window. Other issues/features associated to separator items: - You can change the color of individual separators by using :meth:`CustomTreeCtrl.SetItemTextColour() <customtreectrl.CustomTreeCtrl.SetItemTextColour>`, or you can use :meth:`CustomTreeCtrl.SetSeparatorColour() <customtreectrl.CustomTreeCtrl.SetSeparatorColour>` to change the color of all separators. The default separator colour is that returned by `SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)`; - Separators can be selected just like any other tree item; - Separators cannot have text; - Separators cannot have children; - Separators cannot be edited via the ``EVT_TREE_BEGIN_LABEL_EDIT`` event. """ # since there can be very many of these, we save size by chosing # the smallest representation for the elements and by ordering # the members to avoid padding. self._text = text # label to be rendered for item self._data = data # user-provided data self._children = [] # list of children self._parent = parent # parent of this item self._attr = None # attributes??? self._separator = separator # tree ctrl images for the normal, selected, expanded and # expanded+selected states self._images = [-1, -1, -1, -1] self._images[TreeItemIcon_Normal] = image self._images[TreeItemIcon_Selected] = selImage self._images[TreeItemIcon_Expanded] = _NO_IMAGE self._images[TreeItemIcon_SelectedExpanded] = _NO_IMAGE self._checkedimages = [None, None, None, None, None] self._leftimage = _NO_IMAGE self._x = 0 # (virtual) offset from top self._y = 0 # (virtual) offset from left self._width = 0 # width of this item self._height = 0 # height of this item self._isCollapsed = True self._hasHilight = False # same as focused self._hasPlus = False # used for item which doesn't have # children but has a [+] button self._isBold = False # render the label in bold font self._isItalic = False # render the label in italic font self._ownsAttr = False # delete attribute when done self._type = ct_type # item type: 0=normal, 1=check, 2=radio self._is3State = False # true for 3-state checkbox items self._checked = 0 # only meaningful for check and radio items self._enabled = True # flag to enable/disable an item self._hypertext = False # indicates if the item is hypertext self._visited = False # visited state for an hypertext item if self._type > 0: # do not construct the array for normal items self._checkedimages[TreeItemIcon_Checked] = 0 self._checkedimages[TreeItemIcon_NotChecked] = 1 self._checkedimages[TreeItemIcon_Undetermined] = 2 self._checkedimages[TreeItemIcon_Flagged] = 3 self._checkedimages[TreeItemIcon_NotFlagged] = 4 if parent: if parent.GetType() == 2 and not parent.IsChecked(): # if the node parent is a radio not enabled, we are disabled self._enabled = False self._wnd = wnd # are we holding a window? if wnd: self.SetWindow(wnd) def IsOk(self): """ Returns whether the item is ok or not. :note: This method always returns ``True``, it has been added for backward compatibility with the wxWidgets C++ implementation. """ return True def IsSeparator(self): """ Returns whether the item is meant to be an horizontal line separator or not. :return: ``True`` if this item is a separator, ``False`` otherwise. """ return self._separator def GetChildren(self): """ Returns the item's children. :return: A Python list containing instances of :class:`GenericTreeItem`, representing this item's children. """ return self._children def GetText(self): """ Returns the item text. :return: A string containing the item text. """ return self._text def GetImage(self, which=TreeItemIcon_Normal): """ Returns the item image for a particular item state. :param integer `which`: can be one of the following bits: ================================= ======================== Item State Description ================================= ======================== ``TreeItemIcon_Normal`` To get the normal item image ``TreeItemIcon_Selected`` To get the selected item image (i.e. the image which is shown when the item is currently selected) ``TreeItemIcon_Expanded`` To get the expanded image (this only makes sense for items which have children - then this image is shown when the item is expanded and the normal image is shown when it is collapsed) ``TreeItemIcon_SelectedExpanded`` To get the selected expanded image (which is shown when an expanded item is currently selected) ================================= ======================== :return: An integer index that can be used to retrieve the item image inside a :class:`ImageList`. """ return self._images[which] def GetCheckedImage(self, which=TreeItemIcon_Checked): """ Returns the item check image. :param integer `which`: can be one of the following bits: ================================= ======================== Item State Description ================================= ======================== ``TreeItemIcon_Checked`` To get the checkbox checked item image ``TreeItemIcon_NotChecked`` To get the checkbox unchecked item image ``TreeItemIcon_Undetermined`` To get the checkbox undetermined state item image ``TreeItemIcon_Flagged`` To get the radiobutton checked image ``TreeItemIcon_NotFlagged`` To get the radiobutton unchecked image ================================= ======================== :return: An integer index that can be used to retrieve the item check image inside a :class:`ImageList`. :note: This method is meaningful only for radio & check items. """ return self._checkedimages[which] def GetLeftImage(self): """ Returns the leftmost image associated to this item, i.e. the image on the leftmost part of the client area of :class:`CustomTreeCtrl`. :return: An integer index that can be used to retrieve the item leftmost image inside a :class:`ImageList`. """ return self._leftimage def GetData(self): """ Returns the data associated to this item. :return: A Python object representing the item data, or ``None`` if no data has been assigned to this item. """ return self._data def SetImage(self, image, which): """ Sets the item image. :param integer `image`: an index within the normal image list specifying the image to use; :param integer `which`: the image kind. :see: :meth:`~GenericTreeItem.GetImage` for a description of the `which` parameter. """ self._images[which] = image def SetLeftImage(self, image): """ Sets the item leftmost image, i.e. the image associated to the item on the leftmost part of the :class:`CustomTreeCtrl` client area. :param integer `image`: an index within the left image list specifying the image to use for the item in the leftmost part of the client area. """ self._leftimage = image def SetData(self, data): """ Sets the data associated to this item. :param object `data`: can be any Python object. """ self._data = data def SetHasPlus(self, has=True): """ Sets whether an item has the 'plus' button. :param bool `has`: ``True`` to set the 'plus' button on the item, ``False`` otherwise. """ self._hasPlus = has def SetBold(self, bold): """ Sets the item font bold. :parameter bool `bold`: ``True`` to have a bold font item, ``False`` otherwise. """ self._isBold = bold def SetItalic(self, italic): """ Sets the item font italic. :parameter bool `italic`: ``True`` to have an italic font item, ``False`` otherwise. """ self._isItalic = italic def GetX(self): """ Returns the `x` position on an item, in logical coordinates. """ return self._x def GetY(self): """ Returns the `y` position on an item, in logical coordinates. """ return self._y def SetX(self, x): """ Sets the `x` position on an item, in logical coordinates. :param integer `x`: an integer specifying the x position of the item. """ self._x = x def SetY(self, y): """ Sets the `y` position on an item, in logical coordinates. :param integer `y`: an integer specifying the y position of the item. """ self._y = y def GetHeight(self): """ Returns the height of the item, in pixels. """ return self._height def GetWidth(self): """ Returns the width of the item, in pixels. """ return self._width def SetHeight(self, h): """ Sets the item's height. :param integer `h`: an integer specifying the item's height, in pixels. """ self._height = h def SetWidth(self, w): """ Sets the item's width. :param integer `w`: an integer specifying the item's width, in pixels. """ self._width = w def SetWindow(self, wnd): """ Sets the window associated to the item. :param `wnd`: a non-toplevel window to be displayed next to the item, any subclass of :class:`Window`. :raise: `Exception` if the input `item` is a separator and `wnd` is not ``None``. """ if self.IsSeparator() and wnd is not None: raise Exception("Separator items can not have an associated window") self._wnd = wnd if wnd.GetSizer(): # the window is a complex one hold by a sizer size = wnd.GetBestSize() else: # simple window, without sizers size = wnd.GetSize() # We have to bind the wx.EVT_SET_FOCUS for the associated window # No other solution to handle the focus changing from an item in # CustomTreeCtrl and the window associated to an item # Do better strategies exist? self._wnd.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self._height = size.GetHeight() + 2 self._width = size.GetWidth() self._windowsize = size # We don't show the window if the item is collapsed if self._isCollapsed: self._wnd.Show(False) # The window is enabled only if the item is enabled self._wnd.Enable(self._enabled) self._windowenabled = self._enabled def GetWindow(self): """ Returns the window associated to the item (if any). :return: An instance of any :class:`Window` derived class, excluding top-level windows. """ return self._wnd def DeleteWindow(self): """ Deletes the window associated to the item (if any). """ if self._wnd: self._wnd.Destroy() self._wnd = None def GetWindowEnabled(self): """ Returns whether the associated window is enabled or not. :return: ``True`` if the associated window is enabled, ``False`` if it is disabled. :raise: `Exception` when the item has no associated window. """ if not self._wnd: raise Exception("\nERROR: This Item Has No Window Associated") return self._windowenabled def SetWindowEnabled(self, enable=True): """ Sets whether the associated window is enabled or not. :param bool `enable`: ``True`` to enable the associated window, ``False`` to disable it. :raise: `Exception` when the item has no associated window. """ if not self._wnd: raise Exception("\nERROR: This Item Has No Window Associated") self._windowenabled = enable self._wnd.Enable(enable) def GetWindowSize(self): """ Returns the associated window size. """ return self._windowsize def OnSetFocus(self, event): """ Handles the ``wx.EVT_SET_FOCUS`` event for the window associated with the item. :param `event`: a :class:`FocusEvent` event to be processed. """ treectrl = self._wnd.GetParent() select = treectrl.GetSelection() # If the window is associated to an item that currently is selected # (has focus) we don't kill the focus. Otherwise we do it. if select != self: treectrl._hasFocus = False else: treectrl._hasFocus = True event.Skip() def GetType(self): """ Returns the item type. :see: :meth:`~GenericTreeItem.SetType` and :meth:`~GenericTreeItem.__init__` for a description of valid item types. """ return self._type def SetType(self, ct_type): """ Sets the item type. :param integer `ct_type`: may be one of the following integers: =============== ========================================= `ct_type` Value Description =============== ========================================= 0 A normal item 1 A checkbox-like item 2 A radiobutton-type item =============== ========================================= :note: Regarding radiobutton-type items (with `ct_type` = 2), the following approach is used: - All peer-nodes that are radiobuttons will be mutually exclusive. In other words, only one of a set of radiobuttons that share a common parent can be checked at once. If a radiobutton node becomes checked, then all of its peer radiobuttons must be unchecked. - If a radiobutton node becomes unchecked, then all of its child nodes will become inactive. """ self._type = ct_type def SetHyperText(self, hyper=True): """ Sets whether the item is hypertext or not. :param bool `hyper`: ``True`` to set hypertext behaviour, ``False`` otherwise. """ self._hypertext = hyper def SetVisited(self, visited=True): """ Sets whether an hypertext item was visited or not. :param bool `visited`: ``True`` to set a hypertext item as visited, ``False`` otherwise. """ self._visited = visited def GetVisited(self): """ Returns whether an hypertext item was visited or not. """ return self._visited def IsHyperText(self): """ Returns whether the item is hypetext or not. """ return self._hypertext def GetParent(self): """ Gets the item parent (another instance of :class:`GenericTreeItem` or ``None`` for root items. :return: An instance of :class:`GenericTreeItem` or ``None`` for root items. """ return self._parent def Insert(self, child, index): """ Inserts an item in the item children list for this item. :param `child`: an instance of :class:`GenericTreeItem`; :param integer `index`: the index at which we should insert the new child. """ self._children.insert(index, child) def Expand(self): """ Expands the item. """ self._isCollapsed = False def Collapse(self): """ Collapses the item. """ self._isCollapsed = True def SetHilight(self, set=True): """ Sets the item focus/unfocus. :param bool `set`: ``True`` to set the focus to the item, ``False`` otherwise. """ self._hasHilight = set def HasChildren(self): """ Returns whether the item has children or not. :return: ``True`` if the item has children, ``False`` otherwise. """ return len(self._children) > 0 def IsSelected(self): """ Returns whether the item is selected or not. :return: ``True`` if the item is selected, ``False`` otherwise. """ return self._hasHilight != 0 def IsExpanded(self): """ Returns whether the item is expanded or not. :return: ``True`` if the item is expanded, ``False`` if it is collapsed. """ return not self._isCollapsed def GetValue(self): """ Returns whether the item is checked or not. :note: This is meaningful only for checkbox-like and radiobutton-like items. """ if self.Is3State(): return self.Get3StateValue() return self._checked def Get3StateValue(self): """ Gets the state of a 3-state checkbox item. :return: ``wx.CHK_UNCHECKED`` when the checkbox is unchecked, ``wx.CHK_CHECKED`` when it is checked and ``wx.CHK_UNDETERMINED`` when it's in the undetermined state. :raise: `Exception` when the item is not a 3-state checkbox item. :note: This method raises an exception when the function is used with a 2-state checkbox item. :note: This method is meaningful only for checkbox-like items. """ if not self.Is3State(): raise Exception("Get3StateValue can only be used with 3-state checkbox items.") return self._checked def Is3State(self): """ Returns whether or not the checkbox item is a 3-state checkbox. :return: ``True`` if this checkbox is a 3-state checkbox, ``False`` if it's a 2-state checkbox item. :note: This method is meaningful only for checkbox-like items. """ return self._is3State def Set3StateValue(self, state): """ Sets the checkbox item to the given `state`. :param integer `state`: can be one of: ``wx.CHK_UNCHECKED`` (check is off), ``wx.CHK_CHECKED`` (check is on) or ``wx.CHK_UNDETERMINED`` (check is mixed). :raise: `Exception` when the item is not a 3-state checkbox item. :note: This method raises an exception when the checkbox item is a 2-state checkbox and setting the state to ``wx.CHK_UNDETERMINED``. :note: This method is meaningful only for checkbox-like items. """ if not self._is3State and state == wx.CHK_UNDETERMINED: raise Exception("Set3StateValue can only be used with 3-state checkbox items.") self._checked = state def Set3State(self, allow): """ Sets whether the item has a 3-state value checkbox assigned to it or not. :param bool `allow`: ``True`` to set an item as a 3-state checkbox, ``False`` to set it to a 2-state checkbox. :return: ``True`` if the change was successful, ``False`` otherwise. :note: This method is meaningful only for checkbox-like items. """ if self._type != 1: return False self._is3State = allow return True def IsChecked(self): """ This is just a maybe more readable synonym for :meth:`~GenericTreeItem.GetValue`. Returns whether the item is checked or not. :note: This is meaningful only for checkbox-like and radiobutton-like items. """ return self.GetValue() def Check(self, checked=True): """ Checks/unchecks an item. :param bool `checked`: ``True`` to check an item, ``False`` to uncheck it. :note: This is meaningful only for checkbox-like and radiobutton-like items. """ self._checked = checked def HasPlus(self): """ Returns whether the item has the plus button or not. :return: ``True`` if the item has a 'plus' mark, ``False`` otherwise. """ return self._hasPlus or self.HasChildren() def IsBold(self): """ Returns whether the item font is bold or not. :return: ``True`` if the item has bold text, ``False`` otherwise. """ return self._isBold != 0 def IsItalic(self): """ Returns whether the item font is italic or not. :return: ``True`` if the item has italic text, ``False`` otherwise. """ return self._isItalic != 0 def Enable(self, enable=True): """ Enables/disables the item. :param bool `enable`: ``True`` to enable the item, ``False`` to disable it. """ self._enabled = enable def IsEnabled(self): """ Returns whether the item is enabled or not. :return: ``True`` if the item is enabled, ``False`` if it is disabled. """ return self._enabled def GetAttributes(self): """ Returns the item attributes (font, colours, etc...). :return: An instance of :class:`TreeItemAttr`. """ return self._attr def Attr(self): """ Creates a new attribute (font, colours, etc...) for this item. :return: An instance of :class:`TreeItemAttr`. """ if not self._attr: self._attr = TreeItemAttr() self._ownsAttr = True return self._attr def SetAttributes(self, attr): """ Sets the item attributes (font, colours, etc...). :param `attr`: an instance of :class:`TreeItemAttr`. """ if self._ownsAttr: del self._attr self._attr = attr self._ownsAttr = False def AssignAttributes(self, attr): """ Assigns the item attributes (font, colours, etc...) for this item. :param `attr`: an instance of :class:`TreeItemAttr`. """ self.SetAttributes(attr) self._ownsAttr = True def DeleteChildren(self, tree): """ Deletes the item children. :param `tree`: the main :class:`CustomTreeCtrl` instance. """ for child in self._children: if tree: tree.SendDeleteEvent(child) child.DeleteChildren(tree) if child == tree._select_me: tree._select_me = None # We have to destroy the associated window wnd = child.GetWindow() if wnd: wnd.Destroy() child._wnd = None if child in tree._itemWithWindow: tree._itemWithWindow.remove(child) del child self._children = [] def SetText(self, text): """ Sets the item text. :param string `text`: the new item label. :raise: `Exception` if the item is a separator. """ if self.IsSeparator(): raise Exception("Separator items can not have text") self._text = text def GetChildrenCount(self, recursively=True): """ Gets the number of children of this item. :param bool `recursively`: if ``True``, returns the total number of descendants, otherwise only one level of children is counted. """ count = len(self._children) if not recursively: return count total = count for n in xrange(count): total += self._children[n].GetChildrenCount() return total def GetSize(self, x, y, theButton): """ Returns the item size. :param integer `x`: the current item's x position; :param integer `y`: the current item's y position; :param `theButton`: an instance of the main :class:`CustomTreeCtrl`. :return: A tuple of (`x`, `y`) dimensions, in pixels, representing the item's width and height. """ bottomY = self._y + theButton.GetLineHeight(self) if y < bottomY: y = bottomY width = self._x + self._width if x < width: x = width if self.IsExpanded(): for child in self._children: x, y = child.GetSize(x, y, theButton) return x, y def HitTest(self, point, theCtrl, flags=0, level=0): """ :meth:`~GenericTreeItem.HitTest` method for an item. Called from the main window :meth:`CustomTreeCtrl.HitTest() <customtreectrl.CustomTreeCtrl.HitTest>`. :param `point`: the point to test for the hit (an instance of :class:`Point`); :param `theCtrl`: the main :class:`CustomTreeCtrl` tree; :param integer `flags`: a bitlist of hit locations; :param integer `level`: the item's level inside the tree hierarchy. :see: :meth:`CustomTreeCtrl.HitTest() <customtreectrl.CustomTreeCtrl.HitTest>` method for the flags explanation. """ # for a hidden root node, don't evaluate it, but do evaluate children if not (level == 0 and theCtrl.HasAGWFlag(TR_HIDE_ROOT)): # evaluate the item h = theCtrl.GetLineHeight(self) if point.y > self._y and point.y < self._y + h: y_mid = self._y + h/2 if point.y < y_mid: flags |= TREE_HITTEST_ONITEMUPPERPART else: flags |= TREE_HITTEST_ONITEMLOWERPART xCross = self._x - theCtrl.GetSpacing() if wx.Platform == "__WXMAC__": # according to the drawing code the triangels are drawn # at -4 , -4 from the position up to +10/+10 max if point.x > xCross-4 and point.x < xCross+10 and point.y > y_mid-4 and \ point.y < y_mid+10 and self.HasPlus() and theCtrl.HasButtons(): flags |= TREE_HITTEST_ONITEMBUTTON return self, flags else: # 5 is the size of the plus sign if point.x > xCross-6 and point.x < xCross+6 and point.y > y_mid-6 and \ point.y < y_mid+6 and self.HasPlus() and theCtrl.HasButtons(): flags |= TREE_HITTEST_ONITEMBUTTON return self, flags if point.x >= self._x and point.x <= self._x + self._width: image_w = -1 wcheck = 0 # assuming every image (normal and selected) has the same size! if self.GetImage() != _NO_IMAGE and theCtrl._imageListNormal: image_w, image_h = theCtrl._imageListNormal.GetSize(self.GetImage()) if self.GetCheckedImage() is not None: wcheck, hcheck = theCtrl._imageListCheck.GetSize(self.GetCheckedImage()) if wcheck and point.x <= self._x + wcheck + 1: flags |= TREE_HITTEST_ONITEMCHECKICON return self, flags if image_w != -1 and point.x <= self._x + wcheck + image_w + 1: flags |= TREE_HITTEST_ONITEMICON else: flags |= TREE_HITTEST_ONITEMLABEL return self, flags if point.x < self._x: if theCtrl.HasAGWFlag(TR_FULL_ROW_HIGHLIGHT): flags |= TREE_HITTEST_ONITEM else: flags |= TREE_HITTEST_ONITEMINDENT if point.x > self._x + self._width: if theCtrl.HasAGWFlag(TR_FULL_ROW_HIGHLIGHT): flags |= TREE_HITTEST_ONITEM else: flags |= TREE_HITTEST_ONITEMRIGHT return self, flags # if children are expanded, fall through to evaluate them if self._isCollapsed: return None, 0 # evaluate children for child in self._children: res, flags = child.HitTest(point, theCtrl, flags, level + 1) if res != None: return res, flags return None, 0 def GetCurrentImage(self): """ Returns the current item image. :return: An integer index that can be used to retrieve the item image inside a :class:`ImageList`. """ image = _NO_IMAGE if self.IsExpanded(): if self.IsSelected(): image = self._images[TreeItemIcon_SelectedExpanded] if image == _NO_IMAGE: # we usually fall back to the normal item, but try just the # expanded one (and not selected) first in this case image = self._images[TreeItemIcon_Expanded] else: # not expanded if self.IsSelected(): image = self._images[TreeItemIcon_Selected] # maybe it doesn't have the specific image we want, # try the default one instead if image == _NO_IMAGE: image = self._images[TreeItemIcon_Normal] return image def GetCurrentCheckedImage(self): """ Returns the current item check image. :return: An integer index that can be used to retrieve the item check image inside a :class:`ImageList`. """ if self._type == 0: return None checked = self.IsChecked() if checked > 0: if self._type == 1: # Checkbox if checked == wx.CHK_CHECKED: return self._checkedimages[TreeItemIcon_Checked] else: return self._checkedimages[TreeItemIcon_Undetermined] else: # Radiobutton return self._checkedimages[TreeItemIcon_Flagged] else: if self._type == 1: # Checkbox return self._checkedimages[TreeItemIcon_NotChecked] else: # Radiobutton return self._checkedimages[TreeItemIcon_NotFlagged] # ----------------------------------------------------------------------------- # CustomTreeCtrl Main Implementation. # This Is The Main Class. # ----------------------------------------------------------------------------- class CustomTreeCtrl(wx.PyScrolledWindow): """ :class:`CustomTreeCtrl` is a class that mimics the behaviour of :class:`TreeCtrl`, with almost the same base functionalities plus some more enhancements. This class does not rely on the native control, as it is a full owner-drawn tree control. """ def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, agwStyle=TR_DEFAULT_STYLE, validator=wx.DefaultValidator, name="CustomTreeCtrl"): """ Default class constructor. :param Window `parent`: parent window. Must not be ``None``; :param integer `id`: window identifier. A value of -1 indicates a default value; :param `pos`: the control position. A value of (-1, -1) indicates a default position, chosen by either the windowing system or wxPython, depending on platform; :type `pos`: tuple or :class:`Point` :param `size`: the control size. A value of (-1, -1) indicates a default size, chosen by either the windowing system or wxPython, depending on platform; :type `size`: tuple or :class:`Size` :param integer `style`: the underlying :class:`PyScrolledWindow` style; :param integer `agwStyle`: the AGW-specific window style for :class:`CustomTreeCtrl`. It can be a combination of the following bits: ============================== =========== ================================================== Window Styles Hex Value Description ============================== =========== ================================================== ``TR_NO_BUTTONS`` 0x0 For convenience to document that no buttons are to be drawn. ``TR_SINGLE`` 0x0 For convenience to document that only one item may be selected at a time. Selecting another item causes the current selection, if any, to be deselected. This is the default. ``TR_HAS_BUTTONS`` 0x1 Use this style to show + and - buttons to the left of parent items. ``TR_NO_LINES`` 0x4 Use this style to hide vertical level connectors. ``TR_LINES_AT_ROOT`` 0x8 Use this style to show lines between root nodes. Only applicable if ``TR_HIDE_ROOT`` is set and ``TR_NO_LINES`` is not set. ``TR_DEFAULT_STYLE`` 0x9 The set of flags that are closest to the defaults for the native control for a particular toolkit. ``TR_TWIST_BUTTONS`` 0x10 Use old Mac-twist style buttons. ``TR_MULTIPLE`` 0x20 Use this style to allow a range of items to be selected. If a second range is selected, the current range, if any, is deselected. ``TR_EXTENDED`` 0x40 Use this style to allow disjoint items to be selected. (Only partially implemented; may not work in all cases). ``TR_HAS_VARIABLE_ROW_HEIGHT`` 0x80 Use this style to cause row heights to be just big enough to fit the content. If not set, all rows use the largest row height. The default is that this flag is unset. ``TR_EDIT_LABELS`` 0x200 Use this style if you wish the user to be able to edit labels in the tree control. ``TR_ROW_LINES`` 0x400 Use this style to draw a contrasting border between displayed rows. ``TR_HIDE_ROOT`` 0x800 Use this style to suppress the display of the root node, effectively causing the first-level nodes to appear as a series of root nodes. ``TR_FULL_ROW_HIGHLIGHT`` 0x2000 Use this style to have the background colour and the selection highlight extend over the entire horizontal row of the tree control window. ``TR_AUTO_CHECK_CHILD`` 0x4000 Only meaningful foe checkbox-type items: when a parent item is checked/unchecked its children are checked/unchecked as well. ``TR_AUTO_TOGGLE_CHILD`` 0x8000 Only meaningful foe checkbox-type items: when a parent item is checked/unchecked its children are toggled accordingly. ``TR_AUTO_CHECK_PARENT`` 0x10000 Only meaningful foe checkbox-type items: when a child item is checked/unchecked its parent item is checked/unchecked as well. ``TR_ALIGN_WINDOWS`` 0x20000 Flag used to align windows (in items with windows) at the same horizontal position. ``TR_ALIGN_WINDOWS_RIGHT`` 0x40000 Flag used to align windows (in items with windows) to the rightmost edge of :class:`CustomTreeCtrl`. ``TR_ELLIPSIZE_LONG_ITEMS`` 0x80000 Flag used to ellipsize long items when the horizontal space for :class:`CustomTreeCtrl` is low. ``TR_TOOLTIP_ON_LONG_ITEMS`` 0x100000 Flag used to show tooltips on long items when the horizontal space for :class:`CustomTreeCtrl` is low. ============================== =========== ================================================== :param Validator `validator`: window validator; :param string `name`: window name. """ self._current = self._key_current = self._anchor = self._select_me = None self._hasFocus = False self._dirty = False # Default line height: it will soon be changed self._lineHeight = 10 # Item indent wrt parent self._indent = 15 # item horizontal spacing between the start and the text self._spacing = 18 # Brushes for focused/unfocused items (also gradient type) self._hilightBrush = wx.Brush(wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT)) btnshadow = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW) self._hilightUnfocusedBrush = wx.Brush(btnshadow) r, g, b = btnshadow.Red(), btnshadow.Green(), btnshadow.Blue() backcolour = (max((r >> 1) - 20, 0), max((g >> 1) - 20, 0), max((b >> 1) - 20, 0)) backcolour = wx.Colour(backcolour[0], backcolour[1], backcolour[2]) self._hilightUnfocusedBrush2 = wx.Brush(backcolour) # image list for icons self._imageListNormal = self._imageListButtons = self._imageListState = self._imageListCheck = self._imageListLeft = None self._ownsImageListNormal = self._ownsImageListButtons = self._ownsImageListState = self._ownsImageListLeft = False # Drag and drop initial settings self._dragCount = 0 self._countDrag = 0 self._isDragging = False self._dropTarget = self._oldSelection = None self._dragImage = None self._underMouse = None # EditCtrl initial settings for editable items self._editCtrl = None self._editTimer = None # This one allows us to handle Freeze() and Thaw() calls self._freezeCount = 0 self._findPrefix = "" self._findTimer = None self._dropEffectAboveItem = False self._lastOnSame = False # Default normal and bold fonts for an item self._hasFont = True self._normalFont = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT) family = self._normalFont.GetFamily() if family == wx.FONTFAMILY_UNKNOWN: family = wx.FONTFAMILY_SWISS self._boldFont = wx.Font(self._normalFont.GetPointSize(), family, self._normalFont.GetStyle(), wx.BOLD, self._normalFont.GetUnderlined(), self._normalFont.GetFaceName(), self._normalFont.GetEncoding()) self._italicFont = wx.Font(self._normalFont.GetPointSize(), family, wx.FONTSTYLE_ITALIC, wx.NORMAL, self._normalFont.GetUnderlined(), self._normalFont.GetFaceName(), self._normalFont.GetEncoding()) # Hyperlinks things self._hypertextfont = wx.Font(self._normalFont.GetPointSize(), family, self._normalFont.GetStyle(), wx.NORMAL, True, self._normalFont.GetFaceName(), self._normalFont.GetEncoding()) self._hypertextnewcolour = wx.BLUE self._hypertextvisitedcolour = wx.Colour(200, 47, 200) self._isonhyperlink = False # Default CustomTreeCtrl background colour. self._backgroundColour = wx.WHITE # Background image settings self._backgroundImage = None self._imageStretchStyle = _StyleTile # Disabled items colour self._disabledColour = wx.Colour(180, 180, 180) # Gradient selection colours self._firstcolour = colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT) self._secondcolour = wx.WHITE self._usegradients = False self._gradientstyle = 0 # Horizontal Gradient # Vista Selection Styles self._vistaselection = False # To speed up ExpandAll and SelectAll self._sendEvent = True # Connection lines style grey = (160,160,160) if wx.Platform != "__WXMAC__": self._dottedPen = wx.Pen(grey, 1, wx.USER_DASH) self._dottedPen.SetDashes([1,1]) self._dottedPen.SetCap(wx.CAP_BUTT) else: self._dottedPen = wx.Pen(grey, 1) # Pen Used To Draw The Border Around Selected Items self._borderPen = wx.BLACK_PEN self._cursor = wx.StockCursor(wx.CURSOR_ARROW) # For Appended Windows self._hasWindows = False self._itemWithWindow = [] if wx.Platform == "__WXMAC__": agwStyle &= ~TR_LINES_AT_ROOT agwStyle |= TR_NO_LINES platform, major, minor = wx.GetOsVersion() if major < 10: agwStyle |= TR_ROW_LINES # A constant to use my translation of RendererNative.DrawTreeItemButton # if the wxPython version is less than 2.6.2.1. if _VERSION_STRING < "2.6.2.1": self._drawingfunction = DrawTreeItemButton else: self._drawingfunction = wx.RendererNative.Get().DrawTreeItemButton # Set the separator pen default colour self._separatorPen = wx.Pen(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT)) # Create our container... at last! wx.PyScrolledWindow.__init__(self, parent, id, pos, size, style|wx.HSCROLL|wx.VSCROLL, name) self._agwStyle = agwStyle # Create the default check image list self.SetImageListCheck(16, 16) # If the tree display has no buttons, but does have # connecting lines, we can use a narrower layout. # It may not be a good idea to force this... if not self.HasButtons() and not self.HasAGWFlag(TR_NO_LINES): self._indent= 10 self._spacing = 10 self.SetValidator(validator) attr = self.GetDefaultAttributes() self.SetOwnForegroundColour(attr.colFg) self.SetOwnBackgroundColour(attr.colBg) if not self._hasFont: self.SetOwnFont(attr.font) self.SetSize(size) # Bind the events self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse) self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) self.Bind(EVT_TREE_ITEM_GETTOOLTIP, self.OnGetToolTip) self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy) # Sets the focus to ourselves: this is useful if you have items # with associated widgets. self.SetFocus() def AcceptsFocus(self): """ Can this window be given focus by mouse click? :note: This method always returns ``True`` as we always accept focus from mouse click. :note: Overridden from :class:`PyScrolledWindow`. """ # overridden base class method, allows this ctrl to # participate in the tab-order, etc. It's overridable because # of deriving this class from wx.PyScrolledWindow... return True def OnDestroy(self, event): """ Handles the ``wx.EVT_WINDOW_DESTROY`` event for :class:`CustomTreeCtrl`. :param `event`: a :class:`WindowDestroyEvent` event to be processed. """ # Here there may be something I miss... do I have to destroy # something else? if self._editTimer and self._editTimer.IsRunning(): self._editTimer.Stop() del self._editTimer self._editTimer = None if self._findTimer and self._findTimer.IsRunning(): self._findTimer.Stop() del self._findTimer event.Skip() def GetControlBmp(self, checkbox=True, checked=False, enabled=True, x=16, y=16): """ Returns a native looking checkbox or radio button bitmap. :param bool `checkbox`: ``True`` to get a checkbox image, ``False`` for a radiobutton one; :param bool `checked`: ``True`` if the control is marked, ``False`` if it is not; :param bool `enabled`: ``True`` if the control is enabled, ``False`` if it is not; :param integer `x`: the width of the bitmap; :param integer `y`: the height of the bitmap. :return: An instance of :class:`Bitmap`, representing a native looking checkbox or radiobutton. """ bmp = wx.EmptyBitmap(x, y) mdc = wx.MemoryDC(bmp) mask = wx.Colour(0xfe, 0xfe, 0xfe) mdc.SetBackground(wx.Brush(mask)) mdc.Clear() render = wx.RendererNative.Get() if checked == wx.CHK_CHECKED: flag = wx.CONTROL_CHECKED elif checked == wx.CHK_UNDETERMINED: flag = wx.CONTROL_UNDETERMINED else: flag = 0 if not enabled: flag |= wx.CONTROL_DISABLED if checkbox: render.DrawCheckBox(self, mdc, (0, 0, x, y), flag) else: if _VERSION_STRING < "2.9": render.DrawRadioButton(self, mdc, (0, 0, x, y), flag) else: render.DrawRadioBitmap(self, mdc, (0, 0, x, y), flag) mdc.SelectObject(wx.NullBitmap) bmp.SetMaskColour(mask) return bmp def GetCount(self): """ Returns the global number of items in the tree. """ if not self._anchor: # the tree is empty return 0 count = self._anchor.GetChildrenCount() if not self.HasAGWFlag(TR_HIDE_ROOT): # take the root itself into account count = count + 1 return count def GetIndent(self): """ Returns the item indentation, in pixels. """ return self._indent def GetSpacing(self): """ Returns the spacing between the start and the text, in pixels. """ return self._spacing def GetRootItem(self): """ Returns the root item, an instance of :class:`GenericTreeItem`. """ return self._anchor def GetSelection(self): """ Returns the current selection. :return: An instance of :class:`GenericTreeItem`. :note: This method is valid only with the style ``TR_SINGLE`` set. Use :meth:`~CustomTreeCtrl.GetSelections` for multiple-selections trees. """ return self._current def ToggleItemSelection(self, item): """ Toggles the item selection. :param `item`: an instance of :class:`GenericTreeItem`. """ self.SelectItem(item, not self.IsSelected(item)) def EnableChildren(self, item, enable=True): """ Enables/disables the item children. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `enable`: ``True`` to enable the children, ``False`` to disable them. :note: This method is used internally. """ torefresh = False if item.IsExpanded(): torefresh = True if item.GetType() == 2 and enable and not item.IsChecked(): # We hit a radiobutton item not checked, we don't want to # enable the children return child, cookie = self.GetFirstChild(item) while child: self.EnableItem(child, enable, torefresh=torefresh) # Recurse on tree if child.GetType != 2 or (child.GetType() == 2 and item.IsChecked()): self.EnableChildren(child, enable) (child, cookie) = self.GetNextChild(item, cookie) def EnableItem(self, item, enable=True, torefresh=True): """ Enables/disables an item. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `enable`: ``True`` to enable the item, ``False`` to disable it; :param bool `torefresh`: whether to redraw the item or not. """ if item.IsEnabled() == enable: return if not enable and item.IsSelected(): self.SelectItem(item, False) item.Enable(enable) wnd = item.GetWindow() # Handles the eventual window associated to the item if wnd: wndenable = item.GetWindowEnabled() wnd.Enable(enable) if torefresh: # We have to refresh the item line dc = wx.ClientDC(self) self.CalculateSize(item, dc) self.RefreshLine(item) def IsItemEnabled(self, item): """ Returns whether an item is enabled or disabled. :param `item`: an instance of :class:`GenericTreeItem`. """ return item.IsEnabled() def SetDisabledColour(self, colour): """ Sets the colour for items in a disabled state. :param `colour`: a valid :class:`Colour` instance. """ self._disabledColour = colour self._dirty = True def GetDisabledColour(self): """ Returns the colour for items in a disabled state. :return: An instance of :class:`Colour`. """ return self._disabledColour def IsItemChecked(self, item): """ Returns whether an item is checked or not. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the item is in a 'checked' state, ``False`` otherwise. :note: This method is meaningful only for checkbox-like and radiobutton-like items. """ return item.IsChecked() def GetItem3StateValue(self, item): """ Gets the state of a 3-state checkbox item. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``wx.CHK_UNCHECKED`` when the checkbox is unchecked, ``wx.CHK_CHECKED`` when it is checked and ``wx.CHK_UNDETERMINED`` when it's in the undetermined state. :note: This method raises an exception when the function is used with a 2-state checkbox item. :note: This method is meaningful only for checkbox-like items. """ return item.Get3StateValue() def IsItem3State(self, item): """ Returns whether or not the checkbox item is a 3-state checkbox. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if this checkbox is a 3-state checkbox, ``False`` if it's a 2-state checkbox item. :note: This method is meaningful only for checkbox-like items. """ return item.Is3State() def SetItem3StateValue(self, item, state): """ Sets the checkbox item to the given `state`. :param `item`: an instance of :class:`GenericTreeItem`; :param integer `state`: can be one of: ``wx.CHK_UNCHECKED`` (check is off), ``wx.CHK_CHECKED`` (check is on) or ``wx.CHK_UNDETERMINED`` (check is mixed). :note: This method raises an exception when the checkbox item is a 2-state checkbox and setting the state to ``wx.CHK_UNDETERMINED``. :note: This method is meaningful only for checkbox-like items. """ item.Set3StateValue(state) def SetItem3State(self, item, allow): """ Sets whether the item has a 3-state value checkbox assigned to it or not. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `allow`: ``True`` to set an item as a 3-state checkbox, ``False`` to set it to a 2-state checkbox. :return: ``True`` if the change was successful, ``False`` otherwise. :note: This method is meaningful only for checkbox-like items. """ return item.Set3State(allow) def CheckItem2(self, item, checked=True, torefresh=False): """ Used internally to avoid ``EVT_TREE_ITEM_CHECKED`` events. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `checked`: ``True`` to check an item, ``False`` to uncheck it; :param bool `torefresh`: whether to redraw the item or not. """ if item.GetType() == 0: return item.Check(checked) if torefresh: dc = wx.ClientDC(self) self.CalculateSize(item, dc) self.RefreshLine(item) def UnCheckRadioParent(self, item, checked=False): """ Used internally to handle radio node parent correctly. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `checked`: ``True`` to check an item, ``False`` to uncheck it. """ e = TreeEvent(wxEVT_TREE_ITEM_CHECKING, self.GetId()) e.SetItem(item) e.SetEventObject(self) if self.GetEventHandler().ProcessEvent(e): return False item.Check(checked) self.RefreshLine(item) self.EnableChildren(item, checked) e = TreeEvent(wxEVT_TREE_ITEM_CHECKED, self.GetId()) e.SetItem(item) e.SetEventObject(self) self.GetEventHandler().ProcessEvent(e) return True def CheckItem(self, item, checked=True): """ Actually checks/uncheks an item, sending (eventually) the two events ``EVT_TREE_ITEM_CHECKING`` and ``EVT_TREE_ITEM_CHECKED``. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `checked`: for a radiobutton-type item, ``True`` to check it, ``False`` to uncheck it. For a checkbox-type item, it can be one of ``wx.CHK_UNCHECKED`` when the checkbox is unchecked, ``wx.CHK_CHECKED`` when it is checked and ``wx.CHK_UNDETERMINED`` when it's in the undetermined state. """ # Should we raise an error here?!? if item.GetType() == 0: return if item.GetType() == 2: # it's a radio button if not checked and item.IsChecked(): # Try To Unckeck? return else: if not self.UnCheckRadioParent(item, checked): return self.CheckSameLevel(item, False) return # Radiobuttons are done, let's handle checkbuttons... e = TreeEvent(wxEVT_TREE_ITEM_CHECKING, self.GetId()) e.SetItem(item) e.SetEventObject(self) if self.GetEventHandler().ProcessEvent(e): # Blocked by user return if item.Is3State(): item.Set3StateValue(checked) else: item.Check(checked) dc = wx.ClientDC(self) self.RefreshLine(item) if self.HasAGWFlag(TR_AUTO_CHECK_CHILD): ischeck = self.IsItemChecked(item) self.AutoCheckChild(item, ischeck) if self.HasAGWFlag(TR_AUTO_CHECK_PARENT): ischeck = self.IsItemChecked(item) self.AutoCheckParent(item, ischeck) elif self.HasAGWFlag(TR_AUTO_TOGGLE_CHILD): self.AutoToggleChild(item) e = TreeEvent(wxEVT_TREE_ITEM_CHECKED, self.GetId()) e.SetItem(item) e.SetEventObject(self) self.GetEventHandler().ProcessEvent(e) def AutoToggleChild(self, item): """ Transverses the tree and toggles the items. :param `item`: an instance of :class:`GenericTreeItem`. :note: This method is meaningful only for checkbox-like and radiobutton-like items. """ child, cookie = self.GetFirstChild(item) torefresh = False if item.IsExpanded(): torefresh = True # Recurse on tree while child: if child.GetType() == 1 and child.IsEnabled(): self.CheckItem2(child, not child.IsChecked(), torefresh=torefresh) self.AutoToggleChild(child) (child, cookie) = self.GetNextChild(item, cookie) def AutoCheckChild(self, item, checked): """ Transverses the tree and checks/unchecks the items. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `checked`: ``True`` to check an item, ``False`` to uncheck it. :note: This method is meaningful only for checkbox-like and radiobutton-like items. """ (child, cookie) = self.GetFirstChild(item) torefresh = False if item.IsExpanded(): torefresh = True while child: if child.GetType() == 1 and child.IsEnabled(): self.CheckItem2(child, checked, torefresh=torefresh) self.AutoCheckChild(child, checked) (child, cookie) = self.GetNextChild(item, cookie) def AutoCheckParent(self, item, checked): """ Traverses up the tree and checks/unchecks parent items. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `checked`: ``True`` to check an item, ``False`` to uncheck it. :note: This method is meaningful only for checkbox-like and radiobutton-like items. """ parent = item.GetParent() if not parent or parent.GetType() != 1: return (child, cookie) = self.GetFirstChild(parent) while child: if child.GetType() == 1 and child.IsEnabled(): if checked != child.IsChecked(): return (child, cookie) = self.GetNextChild(parent, cookie) self.CheckItem2(parent, checked, torefresh=True) self.AutoCheckParent(parent, checked) def CheckChilds(self, item, checked=True): """ Programatically check/uncheck item children. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `checked`: ``True`` to check an item, ``False`` to uncheck it. :note: This method is meaningful only for checkbox-like and radiobutton-like items. :note: This method does not generate ``EVT_TREE_ITEM_CHECKING`` and ``EVT_TREE_ITEM_CHECKED`` events. """ if checked == None: self.AutoToggleChild(item) else: self.AutoCheckChild(item, checked) def CheckSameLevel(self, item, checked=False): """ Uncheck radio items which are on the same level of the checked one. Used internally. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `checked`: ``True`` to check an item, ``False`` to uncheck it. :note: This method is meaningful only for radiobutton-like items. """ parent = item.GetParent() if not parent: return torefresh = False if parent.IsExpanded(): torefresh = True (child, cookie) = self.GetFirstChild(parent) while child: if child.GetType() == 2 and child != item: self.CheckItem2(child, checked, torefresh=torefresh) if child.GetType != 2 or (child.GetType() == 2 and child.IsChecked()): self.EnableChildren(child, checked) (child, cookie) = self.GetNextChild(parent, cookie) def EditLabel(self, item): """ Starts editing an item label. :param `item`: an instance of :class:`GenericTreeItem`. """ self.Edit(item) def ShouldInheritColours(self): """ Return ``True`` from here to allow the colours of this window to be changed by `InheritAttributes`, returning ``False`` forbids inheriting them from the parent window. The base class version returns ``False``, but this method is overridden in :class:`Control` where it returns ``True``. :class:`CustomTreeCtrl` does not inherit colours from anyone. """ return False def SetIndent(self, indent): """ Sets the indentation for :class:`CustomTreeCtrl`. :param integer `indent`: an integer representing the indentation for the items in the tree. """ self._indent = indent self._dirty = True def SetSpacing(self, spacing): """ Sets the spacing between items in :class:`CustomTreeCtrl`. :param integer `spacing`: an integer representing the spacing between items in the tree. """ self._spacing = spacing self._dirty = True def HasChildren(self, item): """ Returns whether an item has children or not. :param `item`: an instance of :class:`GenericTreeItem`. """ return len(item.GetChildren()) > 0 def GetChildrenCount(self, item, recursively=True): """ Returns the item children count. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `recursively`: if ``True``, returns the total number of descendants, otherwise only one level of children is counted. """ return item.GetChildrenCount(recursively) def HasAGWFlag(self, flag): """ Returns ``True`` if :class:`CustomTreeCtrl` has the `flag` bit set. :param integer `flag`: any possible window style for :class:`CustomTreeCtrl`. :see: The :meth:`~CustomTreeCtrl.__init__` method for the `flag` parameter description. """ return self._agwStyle & flag def SetAGWWindowStyleFlag(self, agwStyle): """ Sets the :class:`CustomTreeCtrl` window style. :param integer `agwStyle`: the new :class:`CustomTreeCtrl` window style. :see: The :meth:`~CustomTreeCtrl.__init__` method for the `agwStyle` parameter description. """ # Do not try to expand the root node if it hasn't been created yet if self._anchor and not self.HasAGWFlag(TR_HIDE_ROOT) and agwStyle & TR_HIDE_ROOT: # if we will hide the root, make sure children are visible self._anchor.SetHasPlus() self._anchor.Expand() self.CalculatePositions() # right now, just sets the styles. Eventually, we may # want to update the inherited styles, but right now # none of the parents has updatable styles if self.HasAGWFlag(TR_MULTIPLE) and not (agwStyle & TR_MULTIPLE): selections = self.GetSelections() for select in selections[0:-1]: self.SelectItem(select, False) self._agwStyle = agwStyle self._dirty = True def GetAGWWindowStyleFlag(self): """ Returns the :class:`CustomTreeCtrl` style. :see: The :meth:`~CustomTreeCtrl.__init__` method for a list of possible style flags. """ return self._agwStyle def HasButtons(self): """ Returns whether :class:`CustomTreeCtrl` has the ``TR_HAS_BUTTONS`` flag set. :return: ``True`` if :class:`CustomTreeCtrl` has the ``TR_HAS_BUTTONS`` flag set, ``False`` otherwise. """ return self.HasAGWFlag(TR_HAS_BUTTONS) # ----------------------------------------------------------------------------- # functions to work with tree items # ----------------------------------------------------------------------------- def GetItemText(self, item): """ Returns the item text. :param `item`: an instance of :class:`GenericTreeItem`. """ return item.GetText() def GetItemSize(self, item): """ Returns the horizontal space available in :class:`CustomTreeCtrl`, in pixels, to draw this item. :param `item`: an instance of :class:`GenericTreeItem`. .. versionadded:: 0.9.3 """ w, h = self.GetClientSize() xa, ya = self.CalcScrolledPosition((0, item.GetY())) wcheck = image_w = 0 if item.GetType() != 0: wcheck, dummy = self._imageListCheck.GetSize(item.GetType()) wcheck += 4 image = item.GetCurrentImage() if image != _NO_IMAGE: if self._imageListNormal: image_w, dummy = self._imageListNormal.GetSize(image) image_w += 4 maxsize = w - (wcheck + image_w + item.GetX()) + xa return maxsize def GetItemImage(self, item, which=TreeItemIcon_Normal): """ Returns the item image. :param `item`: an instance of :class:`GenericTreeItem`; :param integer `which`: can be one of the following bits: ================================= ======================== Item State Description ================================= ======================== ``TreeItemIcon_Normal`` To get the normal item image ``TreeItemIcon_Selected`` To get the selected item image (i.e. the image which is shown when the item is currently selected) ``TreeItemIcon_Expanded`` To get the expanded image (this only makes sense for items which have children - then this image is shown when the item is expanded and the normal image is shown when it is collapsed) ``TreeItemIcon_SelectedExpanded`` To get the selected expanded image (which is shown when an expanded item is currently selected) ================================= ======================== :return: An integer index that can be used to retrieve the item image inside a :class:`ImageList`. """ return item.GetImage(which) def GetItemLeftImage(self, item): """ Returns the item leftmost image, i.e. the image associated to the item on the leftmost part of the :class:`CustomTreeCtrl` client area. :param `item`: an instance of :class:`GenericTreeItem`. :return: An integer index that can be used to retrieve the item leftmost image inside a :class:`ImageList`. """ return item.GetLeftImage() def GetPyData(self, item): """ Returns the data associated to an item. :param `item`: an instance of :class:`GenericTreeItem`. :return: A Python object representing the item data, or ``None`` if no data has been assigned to this item. """ return item.GetData() GetItemPyData = GetPyData def GetItemTextColour(self, item): """ Returns the item text colour or separator horizontal line colour. :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`Colour`. """ return item.Attr().GetTextColour() def GetItemBackgroundColour(self, item): """ Returns the item background colour. :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`Colour`. """ return item.Attr().GetBackgroundColour() def GetItemFont(self, item): """ Returns the item font. :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`Font`. """ font = item.Attr().GetFont() if font.IsOk(): return font return wx.NullFont def IsItemHyperText(self, item): """ Returns whether an item is hypertext or not. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the item is hypertext-like, ``False`` otherwise. """ return item.IsHyperText() def SetItemText(self, item, text): """ Sets the item text. :param `item`: an instance of :class:`GenericTreeItem`; :param string `text`: the new item label. :raise: `Exception` if the input `item` is a separator. """ if item.IsSeparator(): raise Exception("Separator items can not have text") dc = wx.ClientDC(self) item.SetText(text) self.CalculateSize(item, dc) self.RefreshLine(item) def SetItemImage(self, item, image, which=TreeItemIcon_Normal): """ Sets the item image, depending on the item state. :param `item`: an instance of :class:`GenericTreeItem`; :param integer `image`: an index within the normal image list specifying the image to use for the item in the state specified by the `which` parameter; :param integer `which`: the item state. :see: :meth:`~CustomTreeCtrl.GetItemImage` for an explanation of the `which` parameter. """ item.SetImage(image, which) dc = wx.ClientDC(self) self.CalculateSize(item, dc) self.RefreshLine(item) def SetItemLeftImage(self, item, image): """ Sets the item leftmost image, i.e. the image associated to the item on the leftmost part of the :class:`CustomTreeCtrl` client area. :param `item`: an instance of :class:`GenericTreeItem`; :param integer `image`: an index within the left image list specifying the image to use for the item in the leftmost part of the client area. """ item.SetLeftImage(image) dc = wx.ClientDC(self) self.CalculateSize(item, dc) self.RefreshLine(item) def SetPyData(self, item, data): """ Sets the data associated to an item. :param `item`: an instance of :class:`GenericTreeItem`; :param object `data`: can be any Python object. """ item.SetData(data) SetItemPyData = SetPyData def SetItemHasChildren(self, item, has=True): """ Forces the appearance/disappearance of the button next to the item. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `has`: ``True`` to have a button next to an item, ``False`` otherwise. """ item.SetHasPlus(has) self.RefreshLine(item) def SetItemBold(self, item, bold=True): """ Sets the item font as bold/unbold. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `bold`: ``True`` to set the item font as bold, ``False`` otherwise. """ # avoid redrawing the tree if no real change if item.IsBold() != bold: item.SetBold(bold) self._dirty = True def SetItemItalic(self, item, italic=True): """ Sets the item font as italic/non-italic. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `italic`: ``True`` to set the item font as italic, ``False`` otherwise. """ if item.IsItalic() != italic: item.SetItalic(italic) self._dirty = True def SetItemDropHighlight(self, item, highlight=True): """ Gives the item the visual feedback for drag and drop operations. This is useful when something is dragged from outside the :class:`CustomTreeCtrl`. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `highlight`: ``True`` to highlight the dragged items, ``False`` otherwise. """ if highlight: bg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT) fg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT) item.Attr().SetTextColour(fg) item.Attr.SetBackgroundColour(bg) self.RefreshLine(item) def SetItemTextColour(self, item, colour): """ Sets the item text colour or separator horizontal line colour. :param `item`: an instance of :class:`GenericTreeItem`; :param `colour`: a valid :class:`Colour` instance. """ item.Attr().SetTextColour(colour) self.RefreshLine(item) def SetItemBackgroundColour(self, item, colour): """ Sets the item background colour. :param `item`: an instance of :class:`GenericTreeItem`; :param `colour`: a valid :class:`Colour` instance. """ item.Attr().SetBackgroundColour(colour) self.RefreshLine(item) def SetItemHyperText(self, item, hyper=True): """ Sets whether the item is hypertext or not. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `hyper`: ``True`` to have an item with hypertext behaviour, ``False`` otherwise. """ item.SetHyperText(hyper) self.RefreshLine(item) def SetItemFont(self, item, font): """ Sets the item font. :param `item`: an instance of :class:`GenericTreeItem`; :param `font`: a valid :class:`Font` instance. """ item.Attr().SetFont(font) self._dirty = True def SetFont(self, font): """ Sets the :class:`CustomTreeCtrl` font. :param `font`: a valid :class:`Font` instance. :note: Overridden from :class:`PyScrolledWindow`. """ wx.PyScrolledWindow.SetFont(self, font) self._normalFont = font family = self._normalFont.GetFamily() if family == wx.FONTFAMILY_UNKNOWN: family = wx.FONTFAMILY_SWISS self._boldFont = wx.Font(self._normalFont.GetPointSize(), family, self._normalFont.GetStyle(), wx.BOLD, self._normalFont.GetUnderlined(), self._normalFont.GetFaceName(), self._normalFont.GetEncoding()) self._italicFont = wx.Font(self._normalFont.GetPointSize(), family, wx.FONTSTYLE_ITALIC, wx.NORMAL, self._normalFont.GetUnderlined(), self._normalFont.GetFaceName(), self._normalFont.GetEncoding()) self.CalculatePositions() self.Refresh() self.AdjustMyScrollbars() return True def GetHyperTextFont(self): """ Returns the font used to render hypertext items. :return: An instance of :class:`Font`. :note: This method is meaningful only for hypertext-like items. """ return self._hypertextfont def SetHyperTextFont(self, font): """ Sets the font used to render hypertext items. :param `font`: a valid :class:`Font` instance. :note: This method is meaningful only for hypertext-like items. """ self._hypertextfont = font self._dirty = True def SetHyperTextNewColour(self, colour): """ Sets the colour used to render a non-visited hypertext item. :param `colour`: a valid :class:`Colour` instance. :note: This method is meaningful only for hypertext-like items. """ self._hypertextnewcolour = colour self._dirty = True def GetHyperTextNewColour(self): """ Returns the colour used to render a non-visited hypertext item. :return: An instance of :class:`Colour`. :note: This method is meaningful only for hypertext-like items. """ return self._hypertextnewcolour def SetHyperTextVisitedColour(self, colour): """ Sets the colour used to render a visited hypertext item. :param `colour`: a valid :class:`Colour` instance. :note: This method is meaningful only for hypertext-like items. """ self._hypertextvisitedcolour = colour self._dirty = True def GetHyperTextVisitedColour(self): """ Returns the colour used to render a visited hypertext item. :return: An instance of :class:`Colour`. :note: This method is meaningful only for hypertext-like items. """ return self._hypertextvisitedcolour def SetItemVisited(self, item, visited=True): """ Sets whether an hypertext item was visited. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `visited`: ``True`` to mark an hypertext item as visited, ``False`` otherwise. :note: This method is meaningful only for hypertext-like items. """ item.SetVisited(visited) self.RefreshLine(item) def GetItemVisited(self, item): """ Returns whether an hypertext item was visited. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the hypertext item has been visited, ``False`` otherwise. :note: This method is meaningful only for hypertext-like items. """ return item.GetVisited() def SetHilightFocusColour(self, colour): """ Sets the colour used to highlight focused selected items. :param `colour`: a valid :class:`Colour` instance. :note: This is applied only if gradient and Windows Vista selection styles are disabled. """ self._hilightBrush = wx.Brush(colour) self.RefreshSelected() def SetHilightNonFocusColour(self, colour): """ Sets the colour used to highlight unfocused selected items. :param `colour`: a valid :class:`Colour` instance. :note: This is applied only if gradient and Windows Vista selection styles are disabled. """ self._hilightUnfocusedBrush = wx.Brush(colour) self.RefreshSelected() def GetHilightFocusColour(self): """ Returns the colour used to highlight focused selected items. :return: An instance of :class:`Colour`. :note: This is used only if gradient and Windows Vista selection styles are disabled. """ return self._hilightBrush.GetColour() def GetHilightNonFocusColour(self): """ Returns the colour used to highlight unfocused selected items. :return: An instance of :class:`Colour`. :note: This is used only if gradient and Windows Vista selection styles are disabled. """ return self._hilightUnfocusedBrush.GetColour() def SetFirstGradientColour(self, colour=None): """ Sets the first gradient colour for gradient-style selections. :param `colour`: if not ``None``, a valid :class:`Colour` instance. Otherwise, the colour is taken from the system value ``wx.SYS_COLOUR_HIGHLIGHT``. """ if colour is None: colour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT) self._firstcolour = colour if self._usegradients: self.RefreshSelected() def SetSecondGradientColour(self, colour=None): """ Sets the second gradient colour for gradient-style selections. :param `colour`: if not ``None``, a valid :class:`Colour` instance. Otherwise, the colour generated is a slightly darker version of the :class:`CustomTreeCtrl` background colour. """ if colour is None: # No colour given, generate a slightly darker from the # CustomTreeCtrl background colour colour = self.GetBackgroundColour() r, g, b = int(colour.Red()), int(colour.Green()), int(colour.Blue()) colour = ((r >> 1) + 20, (g >> 1) + 20, (b >> 1) + 20) colour = wx.Colour(colour[0], colour[1], colour[2]) self._secondcolour = colour if self._usegradients: self.RefreshSelected() def GetFirstGradientColour(self): """ Returns the first gradient colour for gradient-style selections. :return: An instance of :class:`Colour`. """ return self._firstcolour def GetSecondGradientColour(self): """ Returns the second gradient colour for gradient-style selections. :return: An instance of :class:`Colour`. """ return self._secondcolour def EnableSelectionGradient(self, enable=True): """ Globally enables/disables drawing of gradient selections. :param bool `enable`: ``True`` to enable gradient-style selections, ``False`` to disable it. :note: Calling this method disables any Vista-style selection previously enabled. """ self._usegradients = enable self._vistaselection = False self.RefreshSelected() def SetGradientStyle(self, vertical=0): """ Sets the gradient style for gradient-style selections. :param integer `vertical`: ``0`` for horizontal gradient-style selections, ``1`` for vertical gradient-style selections. """ # 0 = Horizontal, 1 = Vertical self._gradientstyle = vertical if self._usegradients: self.RefreshSelected() def GetGradientStyle(self): """ Returns the gradient style for gradient-style selections. :return: ``0`` for horizontal gradient-style selections, ``1`` for vertical gradient-style selections. """ return self._gradientstyle def EnableSelectionVista(self, enable=True): """ Globally enables/disables drawing of Windows Vista selections. :param bool `enable`: ``True`` to enable Vista-style selections, ``False`` to disable it. :note: Calling this method disables any gradient-style selection previously enabled. """ self._usegradients = False self._vistaselection = enable self.RefreshSelected() def SetBorderPen(self, pen): """ Sets the pen used to draw the selected item border. :param `pen`: an instance of :class:`Pen`. :note: The border pen is not used if the Windows Vista selection style is applied. """ self._borderPen = pen self.RefreshSelected() def GetBorderPen(self): """ Returns the pen used to draw the selected item border. :return: An instance of :class:`Pen`. :note: The border pen is not used if the Windows Vista selection style is applied. """ return self._borderPen def SetConnectionPen(self, pen): """ Sets the pen used to draw the connecting lines between items. :param `pen`: an instance of :class:`Pen`. """ self._dottedPen = pen self._dirty = True def GetConnectionPen(self): """ Returns the pen used to draw the connecting lines between items. :return: An instance of :class:`Pen`. """ return self._dottedPen def SetBackgroundImage(self, image): """ Sets the :class:`CustomTreeCtrl` background image. :param `image`: if not ``None``, an instance of :class:`Bitmap`. :note: At present, the background image can only be used in "tile" mode. .. todo:: Support background images also in stretch and centered modes. """ self._backgroundImage = image self.Refresh() def GetBackgroundImage(self): """ Returns the :class:`CustomTreeCtrl` background image (if any). :return: An instance of :class:`Bitmap` if a background image is present, ``None`` otherwise. :note: At present, the background image can only be used in "tile" mode. .. todo:: Support background images also in stretch and centered modes. """ return self._backgroundImage def SetSeparatorColour(self, colour): """ Sets the pen colour for separator-type items. :param `colour`: a valid instance of :class:`Colour`. """ self._separatorPen = wx.Pen(colour, 1) self.Refresh() def GetSeparatorColour(self, colour): """ Returns the pen colour for separator-type items. :return: An instance of :class:`Colour` representing the separator pen colour. """ return self._separatorPen.GetColour() def IsItemSeparator(self, item): """ Returns whether an item is of separator type or not. :param `item`: an instance of :class:`GenericTreeItem`. """ return item.IsSeparator() def GetItemWindow(self, item): """ Returns the window associated to the item (if any). :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`Window` if the item has an associated window, ``None`` otherwise. """ return item.GetWindow() def SetItemWindow(self, item, wnd): """ Sets the window for the given item. :param `item`: an instance of :class:`GenericTreeItem`; :param `wnd`: if not ``None``, a non-toplevel window to be displayed next to the item. :raise: `Exception` if the input `item` is a separator and `wnd` is not ``None``. """ if item.IsSeparator() and wnd is not None: raise Exception("Separator items can not have an associated window") if wnd is not None: self._hasWindows = True if item not in self._itemWithWindow: self._itemWithWindow.append(item) else: self.DeleteItemWindow(item) else: self.DeleteItemWindow(item) item.SetWindow(wnd) self.CalculatePositions() self.Refresh() self.AdjustMyScrollbars() def DeleteItemWindow(self, item): """ Deletes the window associated to an item (if any). :param `item`: an instance of :class:`GenericTreeItem`. """ if item.GetWindow() is None: return item.DeleteWindow() if item in self._itemWithWindow: self._itemWithWindow.remove(item) def GetItemWindowEnabled(self, item): """ Returns whether the window associated to the item is enabled. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the item has an associated window and this window is enabled, ``False`` in all other cases. """ return item.GetWindowEnabled() def SetItemWindowEnabled(self, item, enable=True): """ Enables/disables the window associated to the item. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `enable`: ``True`` to enable the associated window, ``False`` to disable it. """ item.SetWindowEnabled(enable) def GetItemType(self, item): """ Returns the item type. :param `item`: an instance of :class:`GenericTreeItem`. :return: An integer representing the item type. :see: :meth:`~CustomTreeCtrl.SetItemType` for a description of valid item types. """ return item.GetType() def SetItemType(self, item, ct_type): """ Sets the item type. :param `item`: an instance of :class:`GenericTreeItem`; :param integer `ct_type`: may be one of the following integers: =============== ========================================= `ct_type` Value Description =============== ========================================= 0 A normal item 1 A checkbox-like item 2 A radiobutton-type item =============== ========================================= :note: Regarding radiobutton-type items (with `ct_type` = 2), the following approach is used: - All peer-nodes that are radiobuttons will be mutually exclusive. In other words, only one of a set of radiobuttons that share a common parent can be checked at once. If a radiobutton node becomes checked, then all of its peer radiobuttons must be unchecked. - If a radiobutton node becomes unchecked, then all of its child nodes will become inactive. """ item.SetType(ct_type) self.CalculatePositions() self.Refresh() # ----------------------------------------------------------------------------- # item status inquiries # ----------------------------------------------------------------------------- def IsVisible(self, item): """ Returns whether the item is visible or not (i.e., its hierarchy is expanded enough to show the item). :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the item is visible, ``False`` if it is hidden. """ # An item is only visible if it's not a descendant of a collapsed item parent = item.GetParent() while parent: if not parent.IsExpanded(): return False parent = parent.GetParent() startX, startY = self.GetViewStart() clientSize = self.GetClientSize() rect = self.GetBoundingRect(item) if not rect: return False if rect.GetWidth() == 0 or rect.GetHeight() == 0: return False if rect.GetBottom() < 0 or rect.GetTop() > clientSize.y: return False if rect.GetRight() < 0 or rect.GetLeft() > clientSize.x: return False return True def ItemHasChildren(self, item): """ Returns whether the item has children or not. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the item has children, ``False`` otherwise. """ # consider that the item does have children if it has the "+" button: it # might not have them (if it had never been expanded yet) but then it # could have them as well and it's better to err on this side rather than # disabling some operations which are restricted to the items with # children for an item which does have them return item.HasPlus() def IsExpanded(self, item): """ Returns whether the item is expanded or not. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the item is expanded, ``False`` if it is collapsed. """ return item.IsExpanded() def IsSelected(self, item): """ Returns whether the item is selected or not. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the item is selected, ``False`` otherwise. """ return item.IsSelected() def IsBold(self, item): """ Returns whether the item font is bold or not. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the item has bold text, ``False`` otherwise. """ return item.IsBold() def IsItalic(self, item): """ Returns whether the item font is italic or not. :param `item`: an instance of :class:`GenericTreeItem`. :return: ``True`` if the item has italic text, ``False`` otherwise. """ return item.IsItalic() # ----------------------------------------------------------------------------- # navigation # ----------------------------------------------------------------------------- def GetItemParent(self, item): """ Returns the item parent (can be ``None`` for root items). :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`GenericTreeItem` or ``None`` for root items. """ return item.GetParent() def GetFirstChild(self, item): """ Returns the item's first child and an integer value 'cookie'. Call :meth:`~CustomTreeCtrl.GetNextChild` for the next child using this very 'cookie' return value as an input. :param `item`: an instance of :class:`GenericTreeItem`. :return: A tuple with the first value being an instance of :class:`GenericTreeItem` or ``None`` if there are no further children, and as second value an integer parameter 'cookie'. :note: This method returns ``None`` if there are no further children. """ cookie = 0 return self.GetNextChild(item, cookie) def GetNextChild(self, item, cookie): """ Returns the item's next child. :param `item`: an instance of :class:`GenericTreeItem`; :param `cookie`: a parameter which is opaque for the application but is necessary for the library to make these functions reentrant (i.e. allow more than one enumeration on one and the same object simultaneously). :return: A tuple with the first value being an instance of :class:`GenericTreeItem` or ``None`` if there are no further children, and as second value an integer parameter 'cookie'. :note: This method returns ``None`` if there are no further children. """ children = item.GetChildren() # it's ok to cast cookie to size_t, we never have indices big enough to # overflow "void *" if cookie < len(children): return children[cookie], cookie+1 else: # there are no more of them return None, cookie def GetLastChild(self, item): """ Returns the item last child. :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`GenericTreeItem` or ``None`` if there are no further children. """ children = item.GetChildren() return (len(children) == 0 and [None] or [children[-1]])[0] def GetNextSibling(self, item): """ Returns the next sibling of an item. :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`GenericTreeItem` or ``None`` if there are no further siblings. :note: This method returns ``None`` if there are no further siblings. """ i = item parent = i.GetParent() if parent == None: # root item doesn't have any siblings return None siblings = parent.GetChildren() index = siblings.index(i) n = index + 1 return (n == len(siblings) and [None] or [siblings[n]])[0] def GetPrevSibling(self, item): """ Returns the previous sibling of an item. :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`GenericTreeItem` or ``None`` if there are no further siblings. :note: This method returns ``None`` if there are no further siblings. """ i = item parent = i.GetParent() if parent == None: # root item doesn't have any siblings return None siblings = parent.GetChildren() index = siblings.index(i) return (index == 0 and [None] or [siblings[index-1]])[0] def GetNext(self, item): """ Returns the next item. Only for internal use right now. :return: An instance of :class:`GenericTreeItem` or ``None`` if there are no further items. :param `item`: an instance of :class:`GenericTreeItem`. """ i = item # First see if there are any children. children = i.GetChildren() if len(children) > 0: return children[0] else: # Try a sibling of this or ancestor instead p = item toFind = None while p and not toFind: toFind = self.GetNextSibling(p) p = self.GetItemParent(p) return toFind def GetPrev(self, item): """ Returns the previous item. Only for internal use right now. :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`GenericTreeItem` """ # Look for a previous sibling of this item prevSibling = self.GetPrevSibling(item) if prevSibling: # return it's last child or itself if has not got any children if len(prevSibling.GetChildren()) > 0: return self.GetLastChild(prevSibling) return prevSibling # item has not got a previous sibling, return it's parent return self.GetItemParent(item) def GetNextExpanded(self, item): """ Returns the next expanded item after the input one. :param `item`: an instance of :class:`TreeListItem`. """ nextSibling = self.GetNextSibling(item) if nextSibling: if nextSibling.IsExpanded(): return nextSibling return self.GetNextExpanded(prevSibling) return None def GetPrevExpanded(self, item): """ Returns the previous expanded item before the input one. :param `item`: an instance of :class:`TreeListItem`. """ prevSibling = self.GetPrevSibling(item) if prevSibling: if prevSibling.IsExpanded(): return prevSibling return self.GetPrevExpanded(prevSibling) return None def GetFirstVisibleItem(self): """ Returns the first visible item. :return: An instance of :class:`GenericTreeItem` or ``None`` if there are no visible items. """ id = self.GetRootItem() if not id: return id while id: if self.IsVisible(id): return id id = self.GetNext(id) return None def GetNextVisible(self, item): """ Returns the next visible item. :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`GenericTreeItem` or ``None`` if there are no next visible items. """ id = item while id: id = self.GetNext(id) if id and self.IsVisible(id): return id return None def GetPrevVisible(self, item): """ Returns the previous visible item. :param `item`: an instance of :class:`GenericTreeItem`. :return: An instance of :class:`GenericTreeItem` or ``None`` if there are no previous visible items. """ # find a previous sibling or parent which is visible lastGoodItem = self.GetPrevSibling(item) if not lastGoodItem or not self.IsVisible(lastGoodItem): parent = self.GetItemParent(item) rootHidden = self.HasAGWFlag(TR_HIDE_ROOT) rootItem = self.GetRootItem() while parent and not (rootHidden and parent == rootItem): if self.IsVisible(parent): lastGoodItem = parent break parent = self.GetItemParent(parent) if not lastGoodItem: return None # test if found item has visible children, if so and if the found item is not the # parent of the current item traverse the found item to the last visible child if not self.HasChildren(lastGoodItem) or not self.IsExpanded(lastGoodItem) or \ (self.GetItemParent(item) == lastGoodItem): return lastGoodItem lastChild = self.GetLastChild(lastGoodItem) while lastChild and self.IsVisible(lastChild): lastGoodItem = lastChild lastChild = self.GetLastChild(lastGoodItem) return lastGoodItem def ResetEditControl(self): """ Called by :class:`TreeTextCtrl` when it marks itself for deletion. """ if self._editCtrl is not None: self._editCtrl.Destroy() self._editCtrl = None self.CalculatePositions() self.Refresh() self.AdjustMyScrollbars() def FindItem(self, idParent, prefixOrig): """ Finds the first item starting with the given prefix after the given parent. :param integer `idParent`: an instance of :class:`GenericTreeItem`; :param string `prefixOrig`: a string containing the item text prefix. :return: An instance of :class:`GenericTreeItem` or ``None`` if no item has been found. """ # match is case insensitive as this is more convenient to the user: having # to press Shift-letter to go to the item starting with a capital letter # would be too bothersome prefix = prefixOrig.lower() # determine the starting point: we shouldn't take the current item (this # allows to switch between two items starting with the same letter just by # pressing it) but we shouldn't jump to the next one if the user is # continuing to type as otherwise he might easily skip the item he wanted id = idParent if len(prefix) == 1: id = self.GetNext(id) # look for the item starting with the given prefix after it while id and not self.GetItemText(id).lower().startswith(prefix): id = self.GetNext(id) # if we haven't found anything... if not id: # ... wrap to the beginning id = self.GetRootItem() if self.HasAGWFlag(TR_HIDE_ROOT): # can't select virtual root id = self.GetNext(id) if idParent == self.GetRootItem(): # no tree item selected and idParent is not reachable return id # and try all the items (stop when we get to the one we started from) while id != idParent and not self.GetItemText(id).lower().startswith(prefix): id = self.GetNext(id) return id # ----------------------------------------------------------------------------- # operations # ----------------------------------------------------------------------------- def DoInsertItem(self, parentId, previous, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None, separator=False): """ Actually inserts an item in the tree. :param `parentId`: an instance of :class:`GenericTreeItem` representing the item's parent; :param integer `previous`: the index at which we should insert the item; :param string `text`: the item text label; :param integer `ct_type`: the item type (see :meth:`~CustomTreeCtrl.SetItemType` for a list of valid item types); :param `wnd`: if not ``None``, a non-toplevel window to show next to the item, any subclass of :class:`Window` except top-level windows; :param integer `image`: an index within the normal image list specifying the image to use for the item in unselected state; :param integer `selImage`: an index within the normal image list specifying the image to use for the item in selected state; if `image` > -1 and `selImage` is -1, the same image is used for both selected and unselected items; :param object `data`: associate the given Python object `data` with the item; :param bool `separator`: ``True`` if the item is a separator, ``False`` otherwise. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :raise: `Exception` in the following cases: - The item window is not ``None`` but the ``TR_HAS_VARIABLE_ROW_HEIGHT`` flag has not been set for :class:`CustomTreeCtrl`; - The item has multiline text (with line-breaks in it) but the ``TR_HAS_VARIABLE_ROW_HEIGHT`` flag has not been set for :class:`CustomTreeCtrl`; - The `ct_type` attribute is less than ``0`` or greater than ``2``; - The parent item is a separator; - The item is a separator but it has text or an associated window. :note: Separator items should not have children, text labels or an associated window. """ if wnd is not None and not self.HasAGWFlag(TR_HAS_VARIABLE_ROW_HEIGHT): raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT") if text.find("\n") >= 0 and not self.HasAGWFlag(TR_HAS_VARIABLE_ROW_HEIGHT): raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT") if ct_type < 0 or ct_type > 2: raise Exception("\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). ") if separator: if wnd: raise Exception("Separator items can not have associated windows") if text.strip(): raise Exception("Separator items can not text labels") parent = parentId if not parent: # should we give a warning here? return self.AddRoot(text, ct_type, wnd, image, selImage, data) self._dirty = True # do this first so stuff below doesn't cause flicker item = GenericTreeItem(parent, text, ct_type, wnd, image, selImage, data, separator) if wnd is not None: self._hasWindows = True self._itemWithWindow.append(item) parent.Insert(item, previous) return item def AddRoot(self, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None): """ Adds a root item to the :class:`CustomTreeCtrl`. :param string `text`: the item text label; :param integer `ct_type`: the item type (see :meth:`~CustomTreeCtrl.SetItemType` for a list of valid item types); :param `wnd`: if not ``None``, a non-toplevel window to show next to the item, any subclass of :class:`Window` except top-level windows; :param integer `image`: an index within the normal image list specifying the image to use for the item in unselected state; :param integer `selImage`: an index within the normal image list specifying the image to use for the item in selected state; if `image` > -1 and `selImage` is -1, the same image is used for both selected and unselected items; :param object `data`: associate the given Python object `data` with the item. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :raise: `Exception` in the following cases: - There already is a root item in the tree; - The item window is not ``None`` but the ``TR_HAS_VARIABLE_ROW_HEIGHT`` flag has not been set for :class:`CustomTreeCtrl`; - The item has multiline text (with line-breaks in it) but the ``TR_HAS_VARIABLE_ROW_HEIGHT`` flag has not been set for :class:`CustomTreeCtrl`; - The `ct_type` attribute is less than ``0`` or greater than ``2``. .. warning:: Only one root is allowed to exist in any given instance of :class:`CustomTreeCtrl`. """ if self._anchor: raise Exception("\nERROR: Tree Can Have Only One Root") if wnd is not None and not self.HasAGWFlag(TR_HAS_VARIABLE_ROW_HEIGHT): raise Exception("\nERROR: In Order To Append/Insert Controls You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT") if text.find("\n") >= 0 and not self.HasAGWFlag(TR_HAS_VARIABLE_ROW_HEIGHT): raise Exception("\nERROR: In Order To Append/Insert A MultiLine Text You Have To Use The Style TR_HAS_VARIABLE_ROW_HEIGHT") if ct_type < 0 or ct_type > 2: raise Exception("\nERROR: Item Type Should Be 0 (Normal), 1 (CheckBox) or 2 (RadioButton). ") self._dirty = True # do this first so stuff below doesn't cause flicker self._anchor = GenericTreeItem(None, text, ct_type, wnd, image, selImage, data) if wnd is not None: self._hasWindows = True self._itemWithWindow.append(self._anchor) if self.HasAGWFlag(TR_HIDE_ROOT): # if root is hidden, make sure we can navigate # into children self._anchor.SetHasPlus() self._anchor.Expand() self.CalculatePositions() if not self.HasAGWFlag(TR_MULTIPLE): self._current = self._key_current = self._anchor self._current.SetHilight(True) return self._anchor def PrependItem(self, parent, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None, separator=False): """ Prepends an item as a first child of parent. :param `parent`: an instance of :class:`GenericTreeItem` representing the item's parent; :param string `text`: the item text label; :param integer `ct_type`: the item type (see :meth:`~CustomTreeCtrl.SetItemType` for a list of valid item types); :param `wnd`: if not ``None``, a non-toplevel window to show next to the item, any subclass of :class:`Window` except top-level windows; :param integer `image`: an index within the normal image list specifying the image to use for the item in unselected state; :param integer `selImage`: an index within the normal image list specifying the image to use for the item in selected state; if `image` > -1 and `selImage` is -1, the same image is used for both selected and unselected items; :param object `data`: associate the given Python object `data` with the item; :param bool `separator`: ``True`` if the item is a separator, ``False`` otherwise. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :see: :meth:`~CustomTreeCtrl.DoInsertItem` for possible exceptions generated by this method. """ return self.DoInsertItem(parent, 0, text, ct_type, wnd, image, selImage, data, separator) def InsertItemByItem(self, parentId, idPrevious, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None, separator=False): """ Inserts an item after the given previous. :param `parentId`: an instance of :class:`GenericTreeItem` representing the item's parent; :param `idPrevious`: an instance of :class:`GenericTreeItem` representing the previous item; :param string `text`: the item text label; :param integer `ct_type`: the item type (see :meth:`~CustomTreeCtrl.SetItemType` for a list of valid item types); :param `wnd`: if not ``None``, a non-toplevel window to show next to the item, any subclass of :class:`Window`; :param integer `image`: an index within the normal image list specifying the image to use for the item in unselected state; :param integer `selImage`: an index within the normal image list specifying the image to use for the item in selected state; if `image` > -1 and `selImage` is -1, the same image is used for both selected and unselected items; :param object `data`: associate the given Python object `data` with the item; :param bool `separator`: ``True`` if the item is a separator, ``False`` otherwise. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :raise: `Exception` if the previous item is not a sibling. :see: :meth:`~CustomTreeCtrl.DoInsertItem` for other possible exceptions generated by this method. """ parent = parentId if not parent: # should we give a warning here? return self.AddRoot(text, ct_type, wnd, image, selImage, data) index = -1 if idPrevious: try: index = parent.GetChildren().index(idPrevious) except: raise Exception("ERROR: Previous Item In CustomTreeCtrl.InsertItem() Is Not A Sibling") return self.DoInsertItem(parentId, index+1, text, ct_type, wnd, image, selImage, data, separator) def InsertItemByIndex(self, parentId, idPrevious, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None, separator=False): """ Inserts an item after the given previous. :param `parentId`: an instance of :class:`GenericTreeItem` representing the item's parent; :param `idPrevious`: the index at which we should insert the new item; :param string `text`: the item text label; :param integer `ct_type`: the item type (see :meth:`~CustomTreeCtrl.SetItemType` for a list of valid item types); :param `wnd`: if not ``None``, a non-toplevel window to show next to the item, any subclass of :class:`Window`; :param integer `image`: an index within the normal image list specifying the image to use for the item in unselected state; :param integer `selImage`: an index within the normal image list specifying the image to use for the item in selected state; if `image` > -1 and `selImage` is -1, the same image is used for both selected and unselected items; :param object `data`: associate the given Python object `data` with the item; :param bool `separator`: ``True`` if the item is a separator, ``False`` otherwise. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :see: :meth:`~CustomTreeCtrl.DoInsertItem` for possible exceptions generated by this method. """ parent = parentId if not parent: # should we give a warning here? return self.AddRoot(text, ct_type, wnd, image, selImage, data) return self.DoInsertItem(parentId, idPrevious, text, ct_type, wnd, image, selImage, data, separator) def InsertItem(self, parentId, input, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None, separator=False): """ Inserts an item after the given previous. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :see: :meth:`~CustomTreeCtrl.InsertItemByIndex` and :meth:`~CustomTreeCtrl.InsertItemByItem` for an explanation of the input parameters. :see: :meth:`~CustomTreeCtrl.DoInsertItem` for possible exceptions generated by this method. """ if type(input) == type(1): return self.InsertItemByIndex(parentId, input, text, ct_type, wnd, image, selImage, data, separator) else: return self.InsertItemByItem(parentId, input, text, ct_type, wnd, image, selImage, data, separator) def AppendItem(self, parentId, text, ct_type=0, wnd=None, image=-1, selImage=-1, data=None): """ Appends an item as a last child of its parent. :param `parentId`: an instance of :class:`GenericTreeItem` representing the item's parent; :param string `text`: the item text label; :param integer `ct_type`: the item type (see :meth:`~CustomTreeCtrl.SetItemType` for a list of valid item types); :param `wnd`: if not ``None``, a non-toplevel window to show next to the item, any subclass of :class:`Window`; :param integer `image`: an index within the normal image list specifying the image to use for the item in unselected state; :param integer `selImage`: an index within the normal image list specifying the image to use for the item in selected state; if `image` > -1 and `selImage` is -1, the same image is used for both selected and unselected items; :param object `data`: associate the given Python object `data` with the item. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :see: :meth:`~CustomTreeCtrl.DoInsertItem` for possible exceptions generated by this method. """ parent = parentId if not parent: # should we give a warning here? return self.AddRoot(text, ct_type, wnd, image, selImage, data) return self.DoInsertItem(parent, len(parent.GetChildren()), text, ct_type, wnd, image, selImage, data) def AppendSeparator(self, parentId): """ Appends an horizontal line separator as a last child of its parent. :param `parentId`: an instance of :class:`GenericTreeItem` representing the separator's parent. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :see: :meth:`~CustomTreeCtrl.DoInsertItem` for possible exceptions generated by this method. """ parent = parentId return self.DoInsertItem(parent, len(parent.GetChildren()), "", separator=True) def InsertSeparator(self, parentId, input): """ Inserts a separator item after the given previous. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :see: :meth:`~CustomTreeCtrl.InsertItemByIndex` and :meth:`~CustomTreeCtrl.InsertItemByItem` for an explanation of the input parameters. :see: :meth:`~CustomTreeCtrl.DoInsertItem` for possible exceptions generated by this method. """ return self.InsertItem(parentId, input, "", separator=True) def PrependSeparator(self, parent): """ Prepends a separator item as a first child of parent. :param `parent`: an instance of :class:`GenericTreeItem` representing the item's parent. :return: An instance of :class:`GenericTreeItem` upon successful insertion. :see: :meth:`~CustomTreeCtrl.DoInsertItem` for possible exceptions generated by this method. """ return self.PrependItem(parent, 0, separator=True) def SendDeleteEvent(self, item): """ Actually sends the ``EVT_TREE_DELETE_ITEM`` event. :param `item`: an instance of :class:`GenericTreeItem`. """ event = TreeEvent(wxEVT_TREE_DELETE_ITEM, self.GetId()) event._item = item event.SetEventObject(self) self.GetEventHandler().ProcessEvent(event) def IsDescendantOf(self, parent, item): """ Checks if the given item is under another one in the tree hierarchy. :param `parent`: an instance of :class:`GenericTreeItem`, representing the possible parent of `item`; :param `item`: another instance of :class:`GenericTreeItem`. :return: ``True`` if `item` is a descendant of `parent`, ``False`` otherwise. """ while item: if item == parent: # item is a descendant of parent return True item = item.GetParent() return False # Don't leave edit or selection on a child which is about to disappear def ChildrenClosing(self, item): """ We are about to destroy the item children. :param `item`: an instance of :class:`GenericTreeItem`. """ if self._editCtrl != None and item != self._editCtrl.item() and self.IsDescendantOf(item, self._editCtrl.item()): self._editCtrl.StopEditing() if item != self._key_current and self.IsDescendantOf(item, self._key_current): self._key_current = None if self.IsDescendantOf(item, self._select_me): self._select_me = item if item != self._current and self.IsDescendantOf(item, self._current): self._current.SetHilight(False) self._current = None self._select_me = item def DeleteChildren(self, item): """ Delete all the item's children. :param `item`: an instance of :class:`GenericTreeItem`. """ self._dirty = True # do this first so stuff below doesn't cause flicker self.ChildrenClosing(item) item.DeleteChildren(self) def Delete(self, item): """ Deletes an item. :param `item`: an instance of :class:`GenericTreeItem`. :note: This method sends the ``EVT_TREE_DELETE_ITEM`` event. """ self._dirty = True # do this first so stuff below doesn't cause flicker if self._editCtrl != None and self.IsDescendantOf(item, self._editCtrl.item()): # can't delete the item being edited, cancel editing it first self._editCtrl.StopEditing() parent = item.GetParent() # don't keep stale pointers around! if self.IsDescendantOf(item, self._key_current): # Don't silently change the selection: # do it properly in idle time, so event # handlers get called. # self._key_current = parent self._key_current = None # self._select_me records whether we need to select # a different item, in idle time. if self._select_me and self.IsDescendantOf(item, self._select_me): self._select_me = parent if self.IsDescendantOf(item, self._current): # Don't silently change the selection: # do it properly in idle time, so event # handlers get called. # self._current = parent self._current = None self._select_me = parent # remove the item from the tree if parent: parent.GetChildren().remove(item) # remove by value else: # deleting the root # nothing will be left in the tree self._anchor = None # and delete all of its children and the item itself now item.DeleteChildren(self) self.SendDeleteEvent(item) if item == self._select_me: self._select_me = None # Remove the item with window if item in self._itemWithWindow: wnd = item.GetWindow() wnd.Hide() wnd.Destroy() item._wnd = None self._itemWithWindow.remove(item) del item def DeleteAllItems(self): """ Deletes all items in the :class:`CustomTreeCtrl`. """ if self._anchor: self.Delete(self._anchor) def Expand(self, item): """ Expands an item, sending a ``EVT_TREE_ITEM_EXPANDING`` and ``EVT_TREE_ITEM_EXPANDED`` events. :param `item`: an instance of :class:`GenericTreeItem`. :raise: `Exception` if you try to expand a hidden root (i.e., when the ``TR_HIDE_ROOT`` style is set for :class:`CustomTreeCtrl`). """ if self.HasAGWFlag(TR_HIDE_ROOT) and item == self.GetRootItem(): raise Exception("\nERROR: Can't Expand An Hidden Root. ") if not item.HasPlus(): return if item.IsExpanded(): return if self._sendEvent: event = TreeEvent(wxEVT_TREE_ITEM_EXPANDING, self.GetId()) event._item = item event.SetEventObject(self) if self.GetEventHandler().ProcessEvent(event) and not event.IsAllowed(): # cancelled by program return item.Expand() if not self._sendEvent: # We are in ExpandAll/ExpandAllChildren return self.CalculatePositions() self.RefreshSubtree(item) if self._hasWindows: # We hide the associated window here, we may show it after self.HideWindows() event.SetEventType(wxEVT_TREE_ITEM_EXPANDED) self.GetEventHandler().ProcessEvent(event) def ExpandAllChildren(self, item): """ Expands all the items children of the input item. :param `item`: an instance of :class:`GenericTreeItem`. :note: This method suppresses the ``EVT_TREE_ITEM_EXPANDING`` and ``EVT_TREE_ITEM_EXPANDED`` events because expanding many items int the control would be too slow then. """ self._sendEvent = False if not self.HasAGWFlag(TR_HIDE_ROOT) or item != self.GetRootItem(): self.Expand(item) if not self.IsExpanded(item): self._sendEvent = True return child, cookie = self.GetFirstChild(item) while child: self.ExpandAllChildren(child) child, cookie = self.GetNextChild(item, cookie) self._sendEvent = True def ExpandAll(self): """ Expands all :class:`CustomTreeCtrl` items. :note: This method suppresses the ``EVT_TREE_ITEM_EXPANDING`` and ``EVT_TREE_ITEM_EXPANDED`` events because expanding many items int the control would be too slow then. """ if self._anchor: self.ExpandAllChildren(self._anchor) self._sendEvent = True self._dirty = True def Collapse(self, item): """ Collapse an item, sending a ``EVT_TREE_ITEM_COLLAPSING`` and ``EVT_TREE_ITEM_COLLAPSED`` events. :param `item`: an instance of :class:`GenericTreeItem`. :raise: `Exception` if you try to collapse a hidden root (i.e., when the ``TR_HIDE_ROOT`` style is set for :class:`CustomTreeCtrl`). """ if self.HasAGWFlag(TR_HIDE_ROOT) and item == self.GetRootItem(): raise Exception("\nERROR: Can't Collapse An Hidden Root. ") if not item.IsExpanded(): return event = TreeEvent(wxEVT_TREE_ITEM_COLLAPSING, self.GetId()) event._item = item event.SetEventObject(self) if self.GetEventHandler().ProcessEvent(event) and not event.IsAllowed(): # cancelled by program return self.ChildrenClosing(item) item.Collapse() self.CalculatePositions() self.Refresh() if self._hasWindows: self.HideWindows() self.AdjustMyScrollbars() event.SetEventType(wxEVT_TREE_ITEM_COLLAPSED) self.GetEventHandler().ProcessEvent(event) def CollapseAndReset(self, item): """ Collapse the given item and deletes its children. :param `item`: an instance of :class:`GenericTreeItem`. """ self.Collapse(item) self.DeleteChildren(item) def Toggle(self, item): """ Toggles the item state (collapsed/expanded). :param `item`: an instance of :class:`GenericTreeItem`. """ if item.IsExpanded(): self.Collapse(item) else: self.Expand(item) def HideWindows(self): """ Hides the windows associated to the items. Used internally. """ for child in self._itemWithWindow: if not self.IsVisible(child): wnd = child.GetWindow() if wnd: wnd.Hide() def Unselect(self): """ Unselects the current selection. """ if self._current: self._current.SetHilight(False) self.RefreshLine(self._current) self._current = None self._select_me = None def UnselectAllChildren(self, item): """ Unselects all the children of the given item. :param `item`: an instance of :class:`GenericTreeItem`. """ if item.IsSelected(): item.SetHilight(False) self.RefreshLine(item) if item.HasChildren(): for child in item.GetChildren(): self.UnselectAllChildren(child) def SelectAllChildren(self, item): """ Selects all the children of the given item. :param `item`: an instance of :class:`GenericTreeItem`. :raise: `Exception` if used without the ``TR_EXTENDED`` or ``TR_MULTIPLE`` style set. :note: This method can be used only if :class:`CustomTreeCtrl` has the ``TR_MULTIPLE`` or ``TR_EXTENDED`` style set. """ if not self.HasAGWFlag(TR_MULTIPLE) and not self.HasAGWFlag(TR_EXTENDED): raise Exception("SelectAllChildren can be used only with multiple selection enabled.") if not item.IsSelected(): item.SetHilight(True) self.RefreshLine(item) if item.HasChildren(): for child in item.GetChildren(): self.SelectAllChildren(child) def UnselectAll(self): """ Unselect all the items. """ rootItem = self.GetRootItem() # the tree might not have the root item at all if rootItem: self.UnselectAllChildren(rootItem) self.Unselect() def SelectAll(self): """ Selects all the item in the tree. :raise: `Exception` if used without the ``TR_EXTENDED`` or ``TR_MULTIPLE`` style set. :note: This method can be used only if :class:`CustomTreeCtrl` has the ``TR_MULTIPLE`` or ``TR_EXTENDED`` style set. """ if not self.HasAGWFlag(TR_MULTIPLE) and not self.HasAGWFlag(TR_EXTENDED): raise Exception("SelectAll can be used only with multiple selection enabled.") rootItem = self.GetRootItem() # the tree might not have the root item at all if rootItem: self.SelectAllChildren(rootItem) # Recursive function ! # To stop we must have crt_item<last_item # Algorithm : # Tag all next children, when no more children, # Move to parent (not to tag) # Keep going... if we found last_item, we stop. def TagNextChildren(self, crt_item, last_item, select): """ Used internally. """ parent = crt_item.GetParent() if parent == None: # This is root item return self.TagAllChildrenUntilLast(crt_item, last_item, select) children = parent.GetChildren() index = children.index(crt_item) count = len(children) for n in xrange(index+1, count): if self.TagAllChildrenUntilLast(children[n], last_item, select): return True return self.TagNextChildren(parent, last_item, select) def TagAllChildrenUntilLast(self, crt_item, last_item, select): """ Used internally. """ crt_item.SetHilight(select) self.RefreshLine(crt_item) if crt_item == last_item: return True if crt_item.HasChildren(): for child in crt_item.GetChildren(): if self.TagAllChildrenUntilLast(child, last_item, select): return True return False def SelectItemRange(self, item1, item2): """ Selects all the items between `item1` and `item2`. :param `item1`: an instance of :class:`GenericTreeItem`, representing the first item in the range to select; :param `item2`: an instance of :class:`GenericTreeItem`, representing the last item in the range to select. :raise: `Exception` if used without the ``TR_EXTENDED`` or ``TR_MULTIPLE`` style set. :note: This method can be used only if :class:`CustomTreeCtrl` has the ``TR_MULTIPLE`` or ``TR_EXTENDED`` style set. """ if not self.HasAGWFlag(TR_MULTIPLE) and not self.HasAGWFlag(TR_EXTENDED): raise Exception("SelectItemRange can be used only with multiple selection enabled.") self._select_me = None # item2 is not necessary after item1 # choice first' and 'last' between item1 and item2 first = (item1.GetY() < item2.GetY() and [item1] or [item2])[0] last = (item1.GetY() < item2.GetY() and [item2] or [item1])[0] select = self._current.IsSelected() if self.TagAllChildrenUntilLast(first, last, select): return self.TagNextChildren(first, last, select) def DoSelectItem(self, item, unselect_others=True, extended_select=False, from_key=False): """ Actually selects/unselects an item, sending ``EVT_TREE_SEL_CHANGING`` and ``EVT_TREE_SEL_CHANGED`` events. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `unselect_others`: if ``True``, all the other selected items are unselected. :param bool `extended_select`: ``True`` if the :class:`CustomTreeCtrl` is using the ``TR_EXTENDED`` style; :param bool `from_key`: ``True`` to indicate that the selection was made via a keyboard key, ``False`` if it was a mouse selection. """ self._select_me = None is_single = not (self.GetAGWWindowStyleFlag() & TR_MULTIPLE) # to keep going anyhow !!! if is_single: if item.IsSelected() and not from_key: # Handles hypertext items self.HandleHyperLink(item) return # nothing else to do unselect_others = True extended_select = False elif unselect_others and item.IsSelected(): # selection change if there is more than one item currently selected if len(self.GetSelections()) == 1 and not from_key: # Handles hypertext items self.HandleHyperLink(item) return event = TreeEvent(wxEVT_TREE_SEL_CHANGING, self.GetId()) event._item = item event._itemOld = self._current event.SetEventObject(self) # TODO : Here we don't send any selection mode yet ! if self.GetEventHandler().ProcessEvent(event) and not event.IsAllowed(): return parent = self.GetItemParent(item) while parent: if not self.IsExpanded(parent): self.Expand(parent) parent = self.GetItemParent(parent) # ctrl press if unselect_others: if is_single: self.Unselect() # to speed up thing else: self.UnselectAll() # shift press if extended_select: if not self._current: self._current = self._key_current = self.GetRootItem() # don't change the mark (self._current) self.SelectItemRange(self._current, item) else: select = True # the default # Check if we need to toggle hilight (ctrl mode) if not unselect_others: select = not item.IsSelected() self._current = self._key_current = item self._current.SetHilight(select) self.RefreshLine(self._current) # This can cause idle processing to select the root # if no item is selected, so it must be after the # selection is set self.EnsureVisible(item) event.SetEventType(wxEVT_TREE_SEL_CHANGED) self.GetEventHandler().ProcessEvent(event) if not from_key: # Handles hypertext items self.HandleHyperLink(item) def SelectItem(self, item, select=True): """ Selects/deselects an item. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `select`: ``True`` to select an item, ``False`` to deselect it. """ if select: self.DoSelectItem(item, not self.HasAGWFlag(TR_MULTIPLE)) else: # deselect item.SetHilight(False) self.RefreshLine(item) def FillArray(self, item, array=[]): """ Internal function. Used to populate an array of selected items when the style ``TR_MULTIPLE`` is used. :param `item`: an instance of :class:`GenericTreeItem`; :param list `array`: a Python list containing the selected items. :return: A Python list containing the selected items. """ if not array: array = [] if item.IsSelected(): array.append(item) if item.HasChildren() and item.IsExpanded(): for child in item.GetChildren(): array = self.FillArray(child, array) return array def GetSelections(self): """ Returns a list of selected items. :note: This method can be used only if :class:`CustomTreeCtrl` has the ``TR_MULTIPLE`` or ``TR_EXTENDED`` style set. :return: A Python list containing the selected items, all instances of :class:`GenericTreeItem`. """ array = [] idRoot = self.GetRootItem() if idRoot: array = self.FillArray(idRoot, array) #else: the tree is empty, so no selections return array def HandleHyperLink(self, item): """ Handles the hyperlink items, sending the ``EVT_TREE_ITEM_HYPERLINK`` event. :param `item`: an instance of :class:`GenericTreeItem`. """ if self.IsItemHyperText(item): event = TreeEvent(wxEVT_TREE_ITEM_HYPERLINK, self.GetId()) event._item = item self.GetEventHandler().ProcessEvent(event) def EnsureVisible(self, item): """ Scrolls and/or expands items to ensure that the given item is visible. :param `item`: an instance of :class:`GenericTreeItem`. """ # first expand all parent branches parent = item.GetParent() if self.HasAGWFlag(TR_HIDE_ROOT): while parent and parent != self._anchor: self.Expand(parent) parent = parent.GetParent() else: while parent: self.Expand(parent) parent = parent.GetParent() self.ScrollTo(item) def ScrollTo(self, item): """ Scrolls the specified item into view. :param `item`: an instance of :class:`GenericTreeItem`. """ if not item: return # We have to call this here because the label in # question might just have been added and no screen # update taken place. if self._dirty: if wx.Platform in ["__WXMSW__", "__WXMAC__"]: self.Update() else: wx.YieldIfNeeded() # now scroll to the item item_y = item.GetY() start_x, start_y = self.GetViewStart() start_y *= _PIXELS_PER_UNIT client_w, client_h = self.GetClientSize() x, y = 0, 0 if item_y < start_y+3: # going down x, y = self._anchor.GetSize(x, y, self) y += _PIXELS_PER_UNIT + 2 # one more scrollbar unit + 2 pixels x += _PIXELS_PER_UNIT + 2 # one more scrollbar unit + 2 pixels x_pos = self.GetScrollPos(wx.HORIZONTAL) # Item should appear at top self.SetScrollbars(_PIXELS_PER_UNIT, _PIXELS_PER_UNIT, x/_PIXELS_PER_UNIT, y/_PIXELS_PER_UNIT, x_pos, item_y/_PIXELS_PER_UNIT) elif item_y+self.GetLineHeight(item) > start_y+client_h: # going up x, y = self._anchor.GetSize(x, y, self) y += _PIXELS_PER_UNIT + 2 # one more scrollbar unit + 2 pixels x += _PIXELS_PER_UNIT + 2 # one more scrollbar unit + 2 pixels item_y += _PIXELS_PER_UNIT+2 x_pos = self.GetScrollPos(wx.HORIZONTAL) # Item should appear at bottom self.SetScrollbars(_PIXELS_PER_UNIT, _PIXELS_PER_UNIT, x/_PIXELS_PER_UNIT, y/_PIXELS_PER_UNIT, x_pos, (item_y+self.GetLineHeight(item)-client_h)/_PIXELS_PER_UNIT ) def OnCompareItems(self, item1, item2): """ Returns whether 2 items have the same text. Override this function in the derived class to change the sort order of the items in the :class:`CustomTreeCtrl`. The function should return a negative, zero or positive value if the first item is less than, equal to or greater than the second one. :param `item1`: an instance of :class:`GenericTreeItem`; :param `item2`: another instance of :class:`GenericTreeItem`. :return: The return value is negative if `item1` < `item2`, zero if `item1` == `item2` and strictly positive if `item1` < `item2`. :note: The base class version compares items alphabetically. """ return cmp(self.GetItemText(item1), self.GetItemText(item2)) def SortChildren(self, item): """ Sorts the children of the given item using the :meth:`~CustomTreeCtrl.OnCompareItems` method of :class:`CustomTreeCtrl`. :param `item`: an instance of :class:`GenericTreeItem`. :note: You should override the :meth:`~CustomTreeCtrl.OnCompareItems` method in your derived class to change the sort order (the default is ascending case-sensitive alphabetical order). """ children = item.GetChildren() if len(children) > 1: self._dirty = True children.sort(self.OnCompareItems) def GetImageList(self): """ Returns the normal image list associated with :class:`CustomTreeCtrl`. :return: An instance of :class:`ImageList`. """ return self._imageListNormal def GetButtonsImageList(self): """ Returns the buttons image list associated with :class:`CustomTreeCtrl` (from which application-defined button images are taken). :return: An instance of :class:`ImageList`. """ return self._imageListButtons def GetStateImageList(self): """ Returns the state image list associated with :class:`CustomTreeCtrl` (from which application-defined state images are taken). :return: An instance of :class:`ImageList`. """ return self._imageListState def GetImageListCheck(self): """ Returns the image list used to build the check/radio buttons in :class:`CustomTreeCtrl`. :return: An instance of :class:`ImageList`. """ return self._imageListCheck def GetLeftImageList(self): """ Returns the image list for :class:`CustomTreeCtrl` filled with images to be used on the leftmost part of the client area. Any item can have a leftmost image associated with it. :return: An instance of :class:`ImageList`. """ return self._imageListLeft def CalculateLineHeight(self): """ Calculates the height of a line. """ dc = wx.ClientDC(self) self._lineHeight = dc.GetCharHeight() if self._imageListNormal: # Calculate a self._lineHeight value from the normal Image sizes. # May be toggle off. Then CustomTreeCtrl will spread when # necessary (which might look ugly). n = self._imageListNormal.GetImageCount() for i in xrange(n): width, height = self._imageListNormal.GetSize(i) if height > self._lineHeight: self._lineHeight = height if self._imageListButtons: # Calculate a self._lineHeight value from the Button image sizes. # May be toggle off. Then CustomTreeCtrl will spread when # necessary (which might look ugly). n = self._imageListButtons.GetImageCount() for i in xrange(n): width, height = self._imageListButtons.GetSize(i) if height > self._lineHeight: self._lineHeight = height if self._imageListCheck: # Calculate a self._lineHeight value from the check/radio image sizes. # May be toggle off. Then CustomTreeCtrl will spread when # necessary (which might look ugly). n = self._imageListCheck.GetImageCount() for i in xrange(n): width, height = self._imageListCheck.GetSize(i) if height > self._lineHeight: self._lineHeight = height if self._imageListLeft: # Calculate a self._lineHeight value from the leftmost image sizes. # May be toggle off. Then CustomTreeCtrl will spread when # necessary (which might look ugly). n = self._imageListLeft.GetImageCount() for i in xrange(n): width, height = self._imageListLeft.GetSize(i) if height > self._lineHeight: self._lineHeight = height if self._lineHeight < 30: self._lineHeight += 2 # at least 2 pixels else: self._lineHeight += self._lineHeight/10 # otherwise 10% extra spacing def SetImageList(self, imageList): """ Sets the normal image list for :class:`CustomTreeCtrl`. :param `imageList`: an instance of :class:`ImageList`. """ if self._ownsImageListNormal: del self._imageListNormal self._imageListNormal = imageList self._ownsImageListNormal = False self._dirty = True # Don't do any drawing if we're setting the list to NULL, # since we may be in the process of deleting the tree control. if imageList: self.CalculateLineHeight() # We gray out the image list to use the grayed icons with disabled items sz = imageList.GetSize(0) self._grayedImageList = wx.ImageList(sz[0], sz[1], True, 0) for ii in xrange(imageList.GetImageCount()): bmp = imageList.GetBitmap(ii) newbmp = MakeDisabledBitmap(bmp) self._grayedImageList.Add(newbmp) def SetLeftImageList(self, imageList): """ Sets the image list for :class:`CustomTreeCtrl` filled with images to be used on the leftmost part of the client area. Any item can have a leftmost image associated with it. :param `imageList`: an instance of :class:`ImageList`. """ self._imageListLeft = imageList self._ownsImageListLeft = False self._dirty = True # Don't do any drawing if we're setting the list to NULL, # since we may be in the process of deleting the tree control. if imageList: self.CalculateLineHeight() # We gray out the image list to use the grayed icons with disabled items sz = imageList.GetSize(0) self._grayedImageListLeft = wx.ImageList(sz[0], sz[1], True, 0) for ii in xrange(imageList.GetImageCount()): bmp = imageList.GetBitmap(ii) newbmp = MakeDisabledBitmap(bmp) self._grayedImageListLeft.Add(newbmp) def SetStateImageList(self, imageList): """ Sets the state image list for :class:`CustomTreeCtrl` (from which application-defined state images are taken). :param `imageList`: an instance of :class:`ImageList`. """ if self._ownsImageListState: del self._imageListState self._imageListState = imageList self._ownsImageListState = False def SetButtonsImageList(self, imageList): """ Sets the buttons image list for :class:`CustomTreeCtrl` (from which application-defined button images are taken). :param `imageList`: an instance of :class:`ImageList`. """ if self._ownsImageListButtons: del self._imageListButtons self._imageListButtons = imageList self._ownsImageListButtons = False self._dirty = True self.CalculateLineHeight() def SetImageListCheck(self, sizex, sizey, imglist=None): """ Sets the checkbox/radiobutton image list. :param integer `sizex`: the width of the bitmaps in the `imglist`, in pixels; :param integer `sizey`: the height of the bitmaps in the `imglist`, in pixels; :param `imglist`: an instance of :class:`ImageList`. """ # Image list to hold disabled versions of each control self._grayedCheckList = wx.ImageList(sizex, sizey, True, 0) if imglist is None: self._imageListCheck = wx.ImageList(sizex, sizey) # Get the Checkboxes self._imageListCheck.Add(self.GetControlBmp(checkbox=True, checked=True, enabled=True, x=sizex, y=sizey)) self._grayedCheckList.Add(self.GetControlBmp(checkbox=True, checked=True, enabled=False, x=sizex, y=sizey)) self._imageListCheck.Add(self.GetControlBmp(checkbox=True, checked=False, enabled=True, x=sizex, y=sizey)) self._grayedCheckList.Add(self.GetControlBmp(checkbox=True, checked=False, enabled=False, x=sizex, y=sizey)) self._imageListCheck.Add(self.GetControlBmp(checkbox=True, checked=2, enabled=True, x=sizex, y=sizey)) self._grayedCheckList.Add(self.GetControlBmp(checkbox=True, checked=2, enabled=False, x=sizex, y=sizey)) # Get the Radio Buttons self._imageListCheck.Add(self.GetControlBmp(checkbox=False, checked=True, enabled=True, x=sizex, y=sizey)) self._grayedCheckList.Add(self.GetControlBmp(checkbox=False, checked=True, enabled=False, x=sizex, y=sizey)) self._imageListCheck.Add(self.GetControlBmp(checkbox=False, checked=False, enabled=True, x=sizex, y=sizey)) self._grayedCheckList.Add(self.GetControlBmp(checkbox=False, checked=False, enabled=False, x=sizex, y=sizey)) else: sizex, sizey = imglist.GetSize(0) self._imageListCheck = imglist for ii in xrange(self._imageListCheck.GetImageCount()): bmp = self._imageListCheck.GetBitmap(ii) newbmp = MakeDisabledBitmap(bmp) self._grayedCheckList.Add(newbmp) self._dirty = True if imglist: self.CalculateLineHeight() def AssignImageList(self, imageList): """ Assigns the normal image list. :param `imageList`: an instance of :class:`ImageList`. """ self.SetImageList(imageList) self._ownsImageListNormal = True def AssignStateImageList(self, imageList): """ Assigns the state image list. :param `imageList`: an instance of :class:`ImageList`. """ self.SetStateImageList(imageList) self._ownsImageListState = True def AssignButtonsImageList(self, imageList): """ Assigns the button image list. :param `imageList`: an instance of :class:`ImageList`. """ self.SetButtonsImageList(imageList) self._ownsImageListButtons = True def AssignLeftImageList(self, imageList): """ Assigns the image list for :class:`CustomTreeCtrl` filled with images to be used on the leftmost part of the client area. Any item can have a leftmost image associated with it. :param `imageList`: an instance of :class:`ImageList`. """ self.SetLeftImageList(imageList) self._ownsImageListLeft = True # ----------------------------------------------------------------------------- # helpers # ----------------------------------------------------------------------------- def AdjustMyScrollbars(self): """ Internal method used to adjust the :class:`PyScrolledWindow` scrollbars. """ if self._anchor: x, y = self._anchor.GetSize(0, 0, self) y += _PIXELS_PER_UNIT + 2 # one more scrollbar unit + 2 pixels x += _PIXELS_PER_UNIT + 2 # one more scrollbar unit + 2 pixels x_pos = self.GetScrollPos(wx.HORIZONTAL) y_pos = self.GetScrollPos(wx.VERTICAL) self.SetScrollbars(_PIXELS_PER_UNIT, _PIXELS_PER_UNIT, x/_PIXELS_PER_UNIT, y/_PIXELS_PER_UNIT, x_pos, y_pos) else: self.SetScrollbars(0, 0, 0, 0) def GetLineHeight(self, item): """ Returns the line height for the given item. :param `item`: an instance of :class:`GenericTreeItem`. :return: the item height, in pixels. """ if self.GetAGWWindowStyleFlag() & TR_HAS_VARIABLE_ROW_HEIGHT: return int(item.GetHeight()) else: return int(self._lineHeight) def DrawVerticalGradient(self, dc, rect, hasfocus): """ Gradient fill from colour 1 to colour 2 from top to bottom. :param `dc`: an instance of :class:`DC`; :param Rect `rect`: the rectangle to be filled with the gradient shading; :param bool `hasfocus`: ``True`` if the main :class:`CustomTreeCtrl` has focus, ``False`` otherwise. """ oldpen = dc.GetPen() oldbrush = dc.GetBrush() dc.SetPen(wx.TRANSPARENT_PEN) # calculate gradient coefficients if hasfocus: col2 = self._secondcolour col1 = self._firstcolour else: col2 = self._hilightUnfocusedBrush.GetColour() col1 = self._hilightUnfocusedBrush2.GetColour() r1, g1, b1 = int(col1.Red()), int(col1.Green()), int(col1.Blue()) r2, g2, b2 = int(col2.Red()), int(col2.Green()), int(col2.Blue()) flrect = float(rect.height) rstep = float((r2 - r1)) / flrect gstep = float((g2 - g1)) / flrect bstep = float((b2 - b1)) / flrect rf, gf, bf = 0, 0, 0 for y in xrange(rect.y, rect.y + rect.height): currCol = (r1 + rf, g1 + gf, b1 + bf) dc.SetBrush(wx.Brush(currCol, wx.SOLID)) dc.DrawRectangle(rect.x, y, rect.width, 1) rf = rf + rstep gf = gf + gstep bf = bf + bstep dc.SetPen(oldpen) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.DrawRectangleRect(rect) dc.SetBrush(oldbrush) def DrawHorizontalGradient(self, dc, rect, hasfocus): """ Gradient fill from colour 1 to colour 2 from left to right. :param `dc`: an instance of :class:`DC`; :param Rect `rect`: the rectangle to be filled with the gradient shading; :param bool `hasfocus`: ``True`` if the main :class:`CustomTreeCtrl` has focus, ``False`` otherwise. """ oldpen = dc.GetPen() oldbrush = dc.GetBrush() dc.SetPen(wx.TRANSPARENT_PEN) # calculate gradient coefficients if hasfocus: col2 = self._secondcolour col1 = self._firstcolour else: col2 = self._hilightUnfocusedBrush.GetColour() col1 = self._hilightUnfocusedBrush2.GetColour() r1, g1, b1 = int(col1.Red()), int(col1.Green()), int(col1.Blue()) r2, g2, b2 = int(col2.Red()), int(col2.Green()), int(col2.Blue()) flrect = float(rect.width) rstep = float((r2 - r1)) / flrect gstep = float((g2 - g1)) / flrect bstep = float((b2 - b1)) / flrect rf, gf, bf = 0, 0, 0 for x in xrange(rect.x, rect.x + rect.width): currCol = (int(r1 + rf), int(g1 + gf), int(b1 + bf)) dc.SetBrush(wx.Brush(currCol, wx.SOLID)) dc.DrawRectangle(x, rect.y, 1, rect.height) rf = rf + rstep gf = gf + gstep bf = bf + bstep dc.SetPen(oldpen) dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.DrawRectangleRect(rect) dc.SetBrush(oldbrush) def DrawVistaRectangle(self, dc, rect, hasfocus): """ Draws the selected item(s) with the Windows Vista style. :param `dc`: an instance of :class:`DC`; :param Rect `rect`: the rectangle to be filled with the gradient shading; :param bool `hasfocus`: ``True`` if the main :class:`CustomTreeCtrl` has focus, ``False`` otherwise. """ if hasfocus: outer = _rgbSelectOuter inner = _rgbSelectInner top = _rgbSelectTop bottom = _rgbSelectBottom else: outer = _rgbNoFocusOuter inner = _rgbNoFocusInner top = _rgbNoFocusTop bottom = _rgbNoFocusBottom oldpen = dc.GetPen() oldbrush = dc.GetBrush() bdrRect = wx.Rect(*rect.Get()) filRect = wx.Rect(*rect.Get()) filRect.Deflate(1,1) r1, g1, b1 = int(top.Red()), int(top.Green()), int(top.Blue()) r2, g2, b2 = int(bottom.Red()), int(bottom.Green()), int(bottom.Blue()) flrect = float(filRect.height) if flrect < 1: flrect = self._lineHeight rstep = float((r2 - r1)) / flrect gstep = float((g2 - g1)) / flrect bstep = float((b2 - b1)) / flrect rf, gf, bf = 0, 0, 0 dc.SetPen(wx.TRANSPARENT_PEN) for y in xrange(filRect.y, filRect.y + filRect.height): currCol = (r1 + rf, g1 + gf, b1 + bf) dc.SetBrush(wx.Brush(currCol, wx.SOLID)) dc.DrawRectangle(filRect.x, y, filRect.width, 1) rf = rf + rstep gf = gf + gstep bf = bf + bstep dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetPen(wx.Pen(outer)) dc.DrawRoundedRectangleRect(bdrRect, 3) bdrRect.Deflate(1, 1) dc.SetPen(wx.Pen(inner)) dc.DrawRoundedRectangleRect(bdrRect, 2) dc.SetPen(oldpen) dc.SetBrush(oldbrush) def PaintItem(self, item, dc, level, align): """ Actually draws an item. :param `item`: an instance of :class:`GenericTreeItem`; :param `dc`: an instance of :class:`DC`; :param integer `level`: the item level in the tree hierarchy; :param integer `align`: an integer specifying the alignment type: =============== ========================================= `align` Value Description =============== ========================================= 0 No horizontal alignment of windows (in items with windows). 1 Windows (in items with windows) are aligned at the same horizontal position. 2 Windows (in items with windows) are aligned at the rightmost edge of :class:`CustomTreeCtrl`. =============== ========================================= """ attr = item.GetAttributes() if attr and attr.HasFont(): dc.SetFont(attr.GetFont()) else: if item.IsBold(): dc.SetFont(self._boldFont) elif item.IsItalic(): dc.SetFont(self._italicFont) if item.IsHyperText(): dc.SetFont(self.GetHyperTextFont()) if item.GetVisited(): dc.SetTextForeground(self.GetHyperTextVisitedColour()) else: dc.SetTextForeground(self.GetHyperTextNewColour()) text_w, text_h, dummy = dc.GetMultiLineTextExtent(item.GetText()) w, h = self.GetClientSize() image = item.GetCurrentImage() checkimage = item.GetCurrentCheckedImage() leftimage = _NO_IMAGE separator = item.IsSeparator() if self._imageListLeft: leftimage = item.GetLeftImage() image_w, image_h = 0, 0 if image != _NO_IMAGE: if self._imageListNormal: image_w, image_h = self._imageListNormal.GetSize(image) image_w += 4 else: image = _NO_IMAGE if item.GetType() != 0: wcheck, hcheck = self._imageListCheck.GetSize(item.GetType()) wcheck += 4 else: wcheck, hcheck = 0, 0 if leftimage != _NO_IMAGE: l_image_w, l_image_h = self._imageListLeft.GetSize(leftimage) total_h = self.GetLineHeight(item) drawItemBackground = False if item.IsSelected(): # under mac selections are only a rectangle in case they don't have the focus if wx.Platform == "__WXMAC__": if not self._hasFocus: dc.SetBrush(wx.TRANSPARENT_BRUSH) dc.SetPen(wx.Pen(wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHT), 1, wx.SOLID)) else: dc.SetBrush(self._hilightBrush) else: dc.SetBrush((self._hasFocus and [self._hilightBrush] or [self._hilightUnfocusedBrush])[0]) drawItemBackground = True else: if attr and attr.HasBackgroundColour(): drawItemBackground = True colBg = attr.GetBackgroundColour() else: colBg = self._backgroundColour dc.SetBrush(wx.Brush(colBg, wx.SOLID)) if attr and attr.HasBorderColour(): colBorder = attr.GetBorderColour() dc.SetPen(wx.Pen(colBorder, 1, wx.SOLID)) else: dc.SetPen(wx.TRANSPARENT_PEN) offset = (self.HasAGWFlag(TR_ROW_LINES) and [1] or [0])[0] if self.HasAGWFlag(TR_FULL_ROW_HIGHLIGHT): x = 0 itemrect = wx.Rect(x, item.GetY()+offset, w, total_h-offset) if item.IsSelected(): if self._usegradients: if self._gradientstyle == 0: # Horizontal self.DrawHorizontalGradient(dc, itemrect, self._hasFocus) else: # Vertical self.DrawVerticalGradient(dc, itemrect, self._hasFocus) elif self._vistaselection: self.DrawVistaRectangle(dc, itemrect, self._hasFocus) else: if wx.Platform in ["__WXGTK2__", "__WXMAC__"]: flags = wx.CONTROL_SELECTED if self._hasFocus: flags = flags | wx.CONTROL_FOCUSED wx.RendererNative.Get().DrawItemSelectionRect(self, dc, itemrect, flags) else: dc.DrawRectangleRect(itemrect) else: if drawItemBackground: minusicon = wcheck + image_w - 2 itemrect = wx.Rect(item.GetX()+minusicon, item.GetY()+offset, item.GetWidth()-minusicon, total_h-offset) dc.DrawRectangleRect(itemrect) else: if item.IsSelected(): # If it's selected, and there's an image, then we should # take care to leave the area under the image painted in the # background colour. wnd = item.GetWindow() wndx = 0 if wnd: wndx, wndy = item.GetWindowSize() if separator: item_width = w else: item_width = item.GetWidth() - image_w - wcheck + 2 - wndx itemrect = wx.Rect(item.GetX() + wcheck + image_w - 2, item.GetY()+offset, item_width, total_h-offset) if self._usegradients: if self._gradientstyle == 0: # Horizontal self.DrawHorizontalGradient(dc, itemrect, self._hasFocus) else: # Vertical self.DrawVerticalGradient(dc, itemrect, self._hasFocus) elif self._vistaselection: self.DrawVistaRectangle(dc, itemrect, self._hasFocus) else: if wx.Platform in ["__WXGTK2__", "__WXMAC__"]: flags = wx.CONTROL_SELECTED if self._hasFocus: flags = flags | wx.CONTROL_FOCUSED wx.RendererNative.Get().DrawItemSelectionRect(self, dc, itemrect, flags) else: dc.DrawRectangleRect(itemrect) # On GTK+ 2, drawing a 'normal' background is wrong for themes that # don't allow backgrounds to be customized. Not drawing the background, # except for custom item backgrounds, works for both kinds of theme. elif drawItemBackground: minusicon = wcheck + image_w - 2 if separator: item_width = w else: item_width = item.GetWidth()-minusicon itemrect = wx.Rect(item.GetX()+minusicon, item.GetY()+offset, item_width, total_h-offset) if self._usegradients and self._hasFocus: if self._gradientstyle == 0: # Horizontal self.DrawHorizontalGradient(dc, itemrect, self._hasFocus) else: # Vertical self.DrawVerticalGradient(dc, itemrect, self._hasFocus) else: dc.DrawRectangleRect(itemrect) if image != _NO_IMAGE: dc.SetClippingRegion(item.GetX(), item.GetY(), wcheck+image_w-2, total_h) if item.IsEnabled(): imglist = self._imageListNormal else: imglist = self._grayedImageList imglist.Draw(image, dc, item.GetX() + wcheck, item.GetY() + ((total_h > image_h) and [(total_h-image_h)/2] or [0])[0], wx.IMAGELIST_DRAW_TRANSPARENT) dc.DestroyClippingRegion() if wcheck: if item.IsEnabled(): imglist = self._imageListCheck else: imglist = self._grayedCheckList imglist.Draw(checkimage, dc, item.GetX(), item.GetY() + ((total_h > hcheck) and [(total_h-hcheck)/2] or [0])[0], wx.IMAGELIST_DRAW_TRANSPARENT) if leftimage != _NO_IMAGE: if item.IsEnabled(): imglist = self._imageListLeft else: imglist = self._grayedImageListLeft imglist.Draw(leftimage, dc, 4, item.GetY() + ((total_h > l_image_h) and [(total_h-l_image_h)/2] or [0])[0], wx.IMAGELIST_DRAW_TRANSPARENT) dc.SetBackgroundMode(wx.TRANSPARENT) extraH = ((total_h > text_h) and [(total_h - text_h)/2] or [0])[0] textrect = wx.Rect(wcheck + image_w + item.GetX(), item.GetY() + extraH, text_w, text_h) itemText = item.GetText() if self.HasAGWFlag(TR_ELLIPSIZE_LONG_ITEMS) and not separator: xa, ya = self.CalcScrolledPosition((0, item.GetY())) maxsize = w - (wcheck + image_w + item.GetX()) + xa itemText = ChopText(dc, itemText, maxsize) if not item.IsEnabled(): foreground = dc.GetTextForeground() dc.SetTextForeground(self._disabledColour) dc.DrawLabel(itemText, textrect) dc.SetTextForeground(foreground) else: if wx.Platform == "__WXMAC__" and item.IsSelected() and self._hasFocus: dc.SetTextForeground(wx.WHITE) dc.DrawLabel(itemText, textrect) wnd = item.GetWindow() if wnd: wndx = wcheck + image_w + item.GetX() + text_w + 4 xa, ya = self.CalcScrolledPosition((0, item.GetY())) wndx += xa if item.GetHeight() > item.GetWindowSize()[1]: ya += (item.GetHeight() - item.GetWindowSize()[1])/2 if align == 1: # Horizontal alignment of windows if level in self.absoluteWindows: wndx = self.absoluteWindows[level] + item.GetX() + 2 + xa elif align == 2: # Rightmost alignment of windows wndx = w - item.GetWindowSize().x - 2 + xa if not wnd.IsShown(): wnd.Show() if wnd.GetPosition() != (wndx, ya): wnd.SetPosition((wndx, ya)) if separator: oldPen = dc.GetPen() if item.IsEnabled(): if attr and attr.HasTextColour(): separatorPen = wx.Pen(attr.GetTextColour(), 1) else: separatorPen = self._separatorPen else: separatorPen = wx.GREY_PEN dc.SetPen(separatorPen) dc.DrawLine(item.GetX()+2, item.GetY()+total_h/2, w, item.GetY()+total_h/2) dc.SetPen(oldPen) # restore normal font dc.SetFont(self._normalFont) # Now y stands for the top of the item, whereas it used to stand for middle ! def PaintLevel(self, item, dc, level, y, align): """ Paint a level in the hierarchy of :class:`CustomTreeCtrl`. :param `item`: an instance of :class:`GenericTreeItem`; :param `dc`: an instance of :class:`DC`; :param integer `level`: the item level in the tree hierarchy; :param integer `y`: the current vertical position in the :class:`PyScrolledWindow`; :param integer `align`: an integer specifying the alignment type: =============== ========================================= `align` Value Description =============== ========================================= 0 No horizontal alignment of windows (in items with windows). 1 Windows (in items with windows) are aligned at the same horizontal position. 2 Windows (in items with windows) are aligned at the rightmost edge of :class:`CustomTreeCtrl`. =============== ========================================= """ x = level*self._indent left_image_list = 0 if self._imageListLeft: left_image_list += self._imageListLeft.GetBitmap(0).GetWidth() x += left_image_list if not self.HasAGWFlag(TR_HIDE_ROOT): x += self._indent elif level == 0: # always expand hidden root origY = y children = item.GetChildren() count = len(children) if count > 0: n = 0 while n < count: oldY = y y = self.PaintLevel(children[n], dc, 1, y, align) n = n + 1 if not self.HasAGWFlag(TR_NO_LINES) and self.HasAGWFlag(TR_LINES_AT_ROOT) and count > 0: # draw line down to last child origY += self.GetLineHeight(children[0])>>1 oldY += self.GetLineHeight(children[n-1])>>1 oldPen = dc.GetPen() dc.SetPen(self._dottedPen) dc.DrawLine(3, origY, 3, oldY) dc.SetPen(oldPen) return y item.SetX(x+self._spacing) item.SetY(y) h = self.GetLineHeight(item) y_top = y y_mid = y_top + (h>>1) y += h exposed_x = dc.LogicalToDeviceX(0) exposed_y = dc.LogicalToDeviceY(y_top) if self.IsExposed(exposed_x, exposed_y, 10000, h): # 10000 = very much if wx.Platform == "__WXMAC__": # don't draw rect outline if we already have the # background colour under Mac pen = ((item.IsSelected() and self._hasFocus) and [self._borderPen] or [wx.TRANSPARENT_PEN])[0] else: pen = self._borderPen if item.IsSelected(): if (wx.Platform == "__WXMAC__" and self._hasFocus): colText = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT) else: colText = wx.SystemSettings_GetColour(wx.SYS_COLOUR_HIGHLIGHTTEXT) if self._vistaselection: colText = wx.BLACK attr = item.GetAttributes() if attr and attr.HasTextColour(): colText = attr.GetTextColour() else: attr = item.GetAttributes() if attr and attr.HasTextColour(): colText = attr.GetTextColour() else: colText = self.GetForegroundColour() # prepare to draw dc.SetTextForeground(colText) dc.SetPen(pen) oldpen = pen # draw self.PaintItem(item, dc, level, align) if self.HasAGWFlag(TR_ROW_LINES): # if the background colour is white, choose a # contrasting colour for the lines medium_grey = wx.Pen(wx.Colour(200, 200, 200)) dc.SetPen(((self.GetBackgroundColour() == wx.WHITE) and [medium_grey] or [wx.WHITE_PEN])[0]) dc.DrawLine(0, y_top, 10000, y_top) dc.DrawLine(0, y, 10000, y) # restore DC objects dc.SetBrush(wx.WHITE_BRUSH) dc.SetTextForeground(wx.BLACK) if not self.HasAGWFlag(TR_NO_LINES): # draw the horizontal line here dc.SetPen(self._dottedPen) x_start = x if x > self._indent+left_image_list: x_start -= self._indent elif self.HasAGWFlag(TR_LINES_AT_ROOT): x_start = 3 dc.DrawLine(x_start, y_mid, x + self._spacing, y_mid) dc.SetPen(oldpen) # should the item show a button? if item.HasPlus() and self.HasButtons(): if self._imageListButtons: # draw the image button here image_h = 0 image_w = 0 image = (item.IsExpanded() and [TreeItemIcon_Expanded] or [TreeItemIcon_Normal])[0] if item.IsSelected(): image += TreeItemIcon_Selected - TreeItemIcon_Normal image_w, image_h = self._imageListButtons.GetSize(image) xx = x - image_w/2 yy = y_mid - image_h/2 dc.SetClippingRegion(xx, yy, image_w, image_h) self._imageListButtons.Draw(image, dc, xx, yy, wx.IMAGELIST_DRAW_TRANSPARENT) dc.DestroyClippingRegion() else: # no custom buttons if self.HasAGWFlag(TR_TWIST_BUTTONS): # We draw something like the Mac twist buttons dc.SetPen(wx.BLACK_PEN) dc.SetBrush(self._hilightBrush) button = [wx.Point(), wx.Point(), wx.Point()] if item.IsExpanded(): button[0].x = x - 5 button[0].y = y_mid - 3 button[1].x = x + 5 button[1].y = button[0].y button[2].x = x button[2].y = button[0].y + 6 else: button[0].x = x - 3 button[0].y = y_mid - 5 button[1].x = button[0].x button[1].y = y_mid + 5 button[2].x = button[0].x + 5 button[2].y = y_mid dc.DrawPolygon(button) else: # These are the standard wx.TreeCtrl buttons as wx.RendererNative knows wImage = 11 hImage = 11 flag = 0 if item.IsExpanded(): flag |= _CONTROL_EXPANDED if item == self._underMouse: flag |= _CONTROL_CURRENT self._drawingfunction(self, dc, wx.Rect(x - wImage/2, y_mid - hImage/2, wImage, hImage), flag) if item.IsExpanded(): children = item.GetChildren() count = len(children) if count > 0: n = 0 level = level + 1 while n < count: oldY = y y = self.PaintLevel(children[n], dc, level, y, align) n = n + 1 if not self.HasAGWFlag(TR_NO_LINES) and count > 0: # draw line down to last child oldY += self.GetLineHeight(children[n-1])>>1 if self.HasButtons(): y_mid += 5 # Only draw the portion of the line that is visible, in case it is huge xOrigin, yOrigin = dc.GetDeviceOrigin() yOrigin = abs(yOrigin) width, height = self.GetClientSize() # Move end points to the begining/end of the view? if y_mid < yOrigin: y_mid = yOrigin if oldY > yOrigin + height: oldY = yOrigin + height # after the adjustments if y_mid is larger than oldY then the line # isn't visible at all so don't draw anything if y_mid < oldY: dc.SetPen(self._dottedPen) dc.DrawLine(x, y_mid, x, oldY) return y # ----------------------------------------------------------------------------- # wxWidgets callbacks # ----------------------------------------------------------------------------- def OnPaint(self, event): """ Handles the ``wx.EVT_PAINT`` event for :class:`CustomTreeCtrl`. :param `event`: a :class:`PaintEvent` event to be processed. """ dc = wx.PaintDC(self) self.PrepareDC(dc) if not self._anchor: return dc.SetFont(self._normalFont) dc.SetPen(self._dottedPen) align = 0 if self.HasAGWFlag(TR_ALIGN_WINDOWS): align = 1 elif self.HasAGWFlag(TR_ALIGN_WINDOWS_RIGHT): align = 2 y = 2 self.PaintLevel(self._anchor, dc, 0, y, align) def OnSize(self, event): """ Handles the ``wx.EVT_SIZE`` event for :class:`CustomTreeCtrl`. :param `event`: a :class:`SizeEvent` event to be processed. """ if self.HasAGWFlag(TR_ELLIPSIZE_LONG_ITEMS): self.Refresh() event.Skip() return if self.HasAGWFlag(TR_ALIGN_WINDOWS_RIGHT) and self._itemWithWindow: self.RefreshItemWithWindows() else: self.RefreshSelected() event.Skip() def OnEraseBackground(self, event): """ Handles the ``wx.EVT_ERASE_BACKGROUND`` event for :class:`CustomTreeCtrl`. :param `event`: a :class:`EraseEvent` event to be processed. """ # Can we actually do something here (or in OnPaint()) To Handle # background images that are stretchable or always centered? # I tried but I get enormous flickering... if not self._backgroundImage: event.Skip() return if self._imageStretchStyle == _StyleTile: dc = event.GetDC() if not dc: dc = wx.ClientDC(self) rect = self.GetUpdateRegion().GetBox() dc.SetClippingRect(rect) self.TileBackground(dc) def TileBackground(self, dc): """ Tiles the background image to fill all the available area. :param `dc`: an instance of :class:`DC`. .. todo:: Support background images also in stretch and centered modes. """ sz = self.GetClientSize() w = self._backgroundImage.GetWidth() h = self._backgroundImage.GetHeight() x = 0 while x < sz.width: y = 0 while y < sz.height: dc.DrawBitmap(self._backgroundImage, x, y, True) y = y + h x = x + w def OnSetFocus(self, event): """ Handles the ``wx.EVT_SET_FOCUS`` event for :class:`CustomTreeCtrl`. :param `event`: a :class:`FocusEvent` event to be processed. """ self._hasFocus = True self.RefreshSelected() event.Skip() def OnKillFocus(self, event): """ Handles the ``wx.EVT_KILL_FOCUS`` event for :class:`CustomTreeCtrl`. :param `event`: a :class:`FocusEvent` event to be processed. """ self._hasFocus = False self.RefreshSelected() event.Skip() def OnKeyDown(self, event): """ Handles the ``wx.EVT_KEY_DOWN`` event for :class:`CustomTreeCtrl`, sending a ``EVT_TREE_KEY_DOWN`` event. :param `event`: a :class:`KeyEvent` event to be processed. """ te = TreeEvent(wxEVT_TREE_KEY_DOWN, self.GetId()) te._evtKey = event te.SetEventObject(self) if self.GetEventHandler().ProcessEvent(te): # intercepted by the user code return if self._current is None or self._key_current is None: self._current = self._key_current = self.GetFirstVisibleItem() # how should the selection work for this event? is_multiple, extended_select, unselect_others = EventFlagsToSelType(self.GetAGWWindowStyleFlag(), event.ShiftDown(), event.CmdDown()) # + : Expand # - : Collaspe # * : Expand all/Collapse all # ' ' | return : activate # up : go up (not last children!) # down : go down # left : go to parent # right : open if parent and go next # home : go to root # end : go to last item without opening parents # alnum : start or continue searching for the item with this prefix keyCode = event.GetKeyCode() if keyCode in [ord("+"), wx.WXK_ADD]: # "+" if self._current.HasPlus() and not self.IsExpanded(self._current) and self.IsItemEnabled(self._current): self.Expand(self._current) elif keyCode in [ord("*"), wx.WXK_MULTIPLY]: # "*" if not self.IsExpanded(self._current) and self.IsItemEnabled(self._current): # expand all self.ExpandAll(self._current) elif keyCode in [ord("-"), wx.WXK_SUBTRACT]: # "-" if self.IsExpanded(self._current): self.Collapse(self._current) elif keyCode == wx.WXK_MENU: # Use the item's bounding rectangle to determine position for the event itemRect = self.GetBoundingRect(self._current, True) event = TreeEvent(wxEVT_TREE_ITEM_MENU, self.GetId()) event._item = self._current # Use the left edge, vertical middle event._pointDrag = wx.Point(itemRect.GetX(), itemRect.GetY() + itemRect.GetHeight()/2) event.SetEventObject(self) self.GetEventHandler().ProcessEvent(event) elif keyCode in [wx.WXK_RETURN, wx.WXK_SPACE, wx.WXK_NUMPAD_ENTER]: if not self.IsItemEnabled(self._current): event.Skip() return if not event.HasModifiers(): event = TreeEvent(wxEVT_TREE_ITEM_ACTIVATED, self.GetId()) event._item = self._current event.SetEventObject(self) self.GetEventHandler().ProcessEvent(event) if keyCode == wx.WXK_SPACE and self.GetItemType(self._current) > 0: if self.IsItem3State(self._current): checked = self.GetItem3StateValue(self._current) checked = (checked+1)%3 else: checked = not self.IsItemChecked(self._current) self.CheckItem(self._current, checked) if self.IsItemHyperText(self._current): self.HandleHyperLink(self._current) # in any case, also generate the normal key event for this key, # even if we generated the ACTIVATED event above: this is what # wxMSW does and it makes sense because you might not want to # process ACTIVATED event at all and handle Space and Return # directly (and differently) which would be impossible otherwise event.Skip() # up goes to the previous sibling or to the last # of its children if it's expanded elif keyCode == wx.WXK_UP: prev = self.GetPrevSibling(self._key_current) if not prev: prev = self.GetItemParent(self._key_current) if prev == self.GetRootItem() and self.HasAGWFlag(TR_HIDE_ROOT): return if prev: current = self._key_current # TODO: Huh? If we get here, we'd better be the first child of our parent. How else could it be? if current == self.GetFirstChild(prev)[0] and self.IsItemEnabled(prev): # otherwise we return to where we came from self.DoSelectItem(prev, unselect_others, extended_select, from_key=True) self._key_current = prev else: current = self._key_current # We are going to another parent node while self.IsExpanded(prev) and self.HasChildren(prev): child = self.GetLastChild(prev) if child: prev = child current = prev # Try to get the previous siblings and see if they are active while prev and not self.IsItemEnabled(prev): prev = self.GetPrevSibling(prev) if not prev: # No previous siblings active: go to the parent and up prev = self.GetItemParent(current) while prev and not self.IsItemEnabled(prev): prev = self.GetItemParent(prev) if prev: self.DoSelectItem(prev, unselect_others, extended_select, from_key=True) self._key_current = prev # left arrow goes to the parent elif keyCode == wx.WXK_LEFT: prev = self.GetItemParent(self._current) if prev == self.GetRootItem() and self.HasAGWFlag(TR_HIDE_ROOT): # don't go to root if it is hidden prev = self.GetPrevSibling(self._current) if self.IsExpanded(self._current): self.Collapse(self._current) else: if prev and self.IsItemEnabled(prev): self.DoSelectItem(prev, unselect_others, extended_select, from_key=True) elif keyCode == wx.WXK_RIGHT: # this works the same as the down arrow except that we # also expand the item if it wasn't expanded yet if self.IsExpanded(self._current) and self.HasChildren(self._current): child, cookie = self.GetFirstChild(self._key_current) if self.IsItemEnabled(child): self.DoSelectItem(child, unselect_others, extended_select, from_key=True) self._key_current = child else: self.Expand(self._current) # fall through elif keyCode == wx.WXK_DOWN: if self.IsExpanded(self._key_current) and self.HasChildren(self._key_current): child = self.GetNextActiveItem(self._key_current) if child: self.DoSelectItem(child, unselect_others, extended_select, from_key=True) self._key_current = child else: next = self.GetNextSibling(self._key_current) if not next: current = self._key_current while current and not next: current = self.GetItemParent(current) if current: next = self.GetNextSibling(current) if not next or not self.IsItemEnabled(next): next = None else: while next and not self.IsItemEnabled(next): next = self.GetNext(next) if next: self.DoSelectItem(next, unselect_others, extended_select, from_key=True) self._key_current = next # <End> selects the last visible tree item elif keyCode == wx.WXK_END: last = self.GetRootItem() while last and self.IsExpanded(last): lastChild = self.GetLastChild(last) # it may happen if the item was expanded but then all of # its children have been deleted - so IsExpanded() returned # true, but GetLastChild() returned invalid item if not lastChild: break last = lastChild if last and self.IsItemEnabled(last): self.DoSelectItem(last, unselect_others, extended_select, from_key=True) # <Home> selects the root item elif keyCode == wx.WXK_HOME: prev = self.GetRootItem() if not prev: return if self.HasAGWFlag(TR_HIDE_ROOT): prev, cookie = self.GetFirstChild(prev) if not prev: return if self.IsItemEnabled(prev): self.DoSelectItem(prev, unselect_others, extended_select, from_key=True) else: if not event.HasModifiers() and ((keyCode >= ord('0') and keyCode <= ord('9')) or \ (keyCode >= ord('a') and keyCode <= ord('z')) or \ (keyCode >= ord('A') and keyCode <= ord('Z'))): # find the next item starting with the given prefix ch = chr(keyCode) id = self.FindItem(self._current, self._findPrefix + ch) if not id: # no such item return if self.IsItemEnabled(id): self.SelectItem(id) self._findPrefix += ch # also start the timer to reset the current prefix if the user # doesn't press any more alnum keys soon -- we wouldn't want # to use this prefix for a new item search if not self._findTimer: self._findTimer = TreeFindTimer(self) self._findTimer.Start(_DELAY, wx.TIMER_ONE_SHOT) else: event.Skip() def GetNextActiveItem(self, item, down=True): """ Returns the next active item. Used Internally at present. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `down`: ``True`` to search downwards in the hierarchy for an active item, ``False`` to search upwards. :return: An instance of :class:`GenericTreeItem` if an active item has been found or ``None`` if none has been found. """ if down: sibling = self.GetNextSibling else: sibling = self.GetPrevSibling if self.GetItemType(item) == 2 and not self.IsItemChecked(item): # Is an unchecked radiobutton... all its children are inactive # try to get the next/previous sibling found = 0 while 1: child = sibling(item) if (child and self.IsItemEnabled(child)) or not child: break item = child else: # Tha's not a radiobutton... but some of its children can be # inactive child, cookie = self.GetFirstChild(item) while child and not self.IsItemEnabled(child): child, cookie = self.GetNextChild(item, cookie) if child and self.IsItemEnabled(child): return child return None def HitTest(self, point, flags=0): """ Calculates which (if any) item is under the given point, returning the tree item at this point plus extra information flags. :param `point`: an instance of :class:`Point`, a point to test for hits; :param integer `flags`: a bitlist of the following values: ================================== =============== ================================= HitTest Flags Hex Value Description ================================== =============== ================================= ``TREE_HITTEST_ABOVE`` 0x1 Above the client area ``TREE_HITTEST_BELOW`` 0x2 Below the client area ``TREE_HITTEST_NOWHERE`` 0x4 No item has been hit ``TREE_HITTEST_ONITEMBUTTON`` 0x8 On the button associated to an item ``TREE_HITTEST_ONITEMICON`` 0x10 On the icon associated to an item ``TREE_HITTEST_ONITEMINDENT`` 0x20 On the indent associated to an item ``TREE_HITTEST_ONITEMLABEL`` 0x40 On the label (string) associated to an item ``TREE_HITTEST_ONITEM`` 0x50 Anywhere on the item ``TREE_HITTEST_ONITEMRIGHT`` 0x80 On the right of the label associated to an item ``TREE_HITTEST_TOLEFT`` 0x200 On the left of the client area ``TREE_HITTEST_TORIGHT`` 0x400 On the right of the client area ``TREE_HITTEST_ONITEMUPPERPART`` 0x800 On the upper part (first half) of the item ``TREE_HITTEST_ONITEMLOWERPART`` 0x1000 On the lower part (second half) of the item ``TREE_HITTEST_ONITEMCHECKICON`` 0x2000 On the check/radio icon, if present ================================== =============== ================================= :return: A tuple with the first value being an instance of :class:`GenericTreeItem` or ``None`` if no item has been hit-tested, and as second value an integer parameter `flag`. :note: both the item (if any, ``None`` otherwise) and the `flags` are always returned as a tuple. """ w, h = self.GetSize() flags = 0 if point.x < 0: flags |= TREE_HITTEST_TOLEFT if point.x > w: flags |= TREE_HITTEST_TORIGHT if point.y < 0: flags |= TREE_HITTEST_ABOVE if point.y > h: flags |= TREE_HITTEST_BELOW if flags: return None, flags if self._anchor == None: flags = TREE_HITTEST_NOWHERE return None, flags hit, flags = self._anchor.HitTest(self.CalcUnscrolledPosition(point), self, flags, 0) if hit == None: flags = TREE_HITTEST_NOWHERE return None, flags if not self.IsItemEnabled(hit): return None, flags return hit, flags def GetBoundingRect(self, item, textOnly=False): """ Retrieves the rectangle bounding the item. :param `item`: an instance of :class:`GenericTreeItem`; :param bool `textOnly`: if ``True``, only the rectangle around the item's label will be returned, otherwise the item's image is also taken into account. :return: An instance of :class:`Rect`. :note: The rectangle coordinates are logical, not physical ones. So, for example, the `x` coordinate may be negative if the tree has a horizontal scrollbar and its position is not ``0``. """ i = item startX, startY = self.GetViewStart() rect = wx.Rect() rect.x = i.GetX() - startX*_PIXELS_PER_UNIT rect.y = i.GetY() - startY*_PIXELS_PER_UNIT rect.width = i.GetWidth() rect.height = self.GetLineHeight(i) return rect def Edit(self, item): """ Internal function. Starts the editing of an item label, sending a ``EVT_TREE_BEGIN_LABEL_EDIT`` event. :param `item`: an instance of :class:`GenericTreeItem`. .. warning:: Separator-type items can not be edited. """ if item.IsSeparator(): return te = TreeEvent(wxEVT_TREE_BEGIN_LABEL_EDIT, self.GetId()) te._item = item te.SetEventObject(self) if self.GetEventHandler().ProcessEvent(te) and not te.IsAllowed(): # vetoed by user return # We have to call this here because the label in # question might just have been added and no screen # update taken place. if self._dirty: if wx.Platform in ["__WXMSW__", "__WXMAC__"]: self.Update() else: wx.YieldIfNeeded() if self._editCtrl != None and item != self._editCtrl.item(): self._editCtrl.StopEditing() self._editCtrl = TreeTextCtrl(self, item=item) self._editCtrl.SetFocus() def GetEditControl(self): """ Returns a pointer to the edit :class:`TreeTextCtrl` if the item is being edited or ``None`` otherwise (it is assumed that no more than one item may be edited simultaneously). """ return self._editCtrl def OnAcceptEdit(self, item, value): """ Called by :class:`TreeTextCtrl`, to accept the changes and to send the ``EVT_TREE_END_LABEL_EDIT`` event. :param `item`: an instance of :class:`GenericTreeItem`; :param string `value`: the new value of the item label. :return: ``True`` if the editing has not been vetoed, ``False`` otherwise. """ le = TreeEvent(wxEVT_TREE_END_LABEL_EDIT, self.GetId()) le._item = item le.SetEventObject(self) le._label = value le._editCancelled = False return not self.GetEventHandler().ProcessEvent(le) or le.IsAllowed() def OnCancelEdit(self, item): """ Called by :class:`TreeTextCtrl`, to cancel the changes and to send the ``EVT_TREE_END_LABEL_EDIT`` event. :param `item`: an instance of :class:`GenericTreeItem`. """ # let owner know that the edit was cancelled le = TreeEvent(wxEVT_TREE_END_LABEL_EDIT, self.GetId()) le._item = item le.SetEventObject(self) le._label = "" le._editCancelled = True self.GetEventHandler().ProcessEvent(le) def OnEditTimer(self): """ The timer for editing has expired. Start editing. """ self.Edit(self._current) def OnMouse(self, event): """ Handles a bunch of ``wx.EVT_MOUSE_EVENTS`` events for :class:`CustomTreeCtrl`. :param `event`: a :class:`MouseEvent` event to be processed. """ if not self._anchor: return pt = self.CalcUnscrolledPosition(event.GetPosition()) # Is the mouse over a tree item button? flags = 0 thisItem, flags = self._anchor.HitTest(pt, self, flags, 0) underMouse = thisItem underMouseChanged = underMouse != self._underMouse if underMouse and (flags & TREE_HITTEST_ONITEM) and not event.LeftIsDown() and \ not self._isDragging and (not self._editTimer or not self._editTimer.IsRunning()): underMouse = underMouse else: underMouse = None if underMouse != self._underMouse: if self._underMouse: # unhighlight old item self._underMouse = None self._underMouse = underMouse # Determines what item we are hovering over and need a tooltip for hoverItem = thisItem # We do not want a tooltip if we are dragging, or if the edit timer is running if underMouseChanged and not self._isDragging and (not self._editTimer or not self._editTimer.IsRunning()): if hoverItem is not None: # Ask the tree control what tooltip (if any) should be shown hevent = TreeEvent(wxEVT_TREE_ITEM_GETTOOLTIP, self.GetId()) hevent._item = hoverItem hevent.SetEventObject(self) if self.GetEventHandler().ProcessEvent(hevent) and hevent.IsAllowed(): self.SetToolTip(hevent._label) elif self.HasAGWFlag(TR_TOOLTIP_ON_LONG_ITEMS): tip = self.GetToolTipString() if hoverItem.IsSeparator(): if tip: self.SetToolTipString('') else: maxsize = self.GetItemSize(hoverItem) itemText = hoverItem.GetText() dc = wx.ClientDC(self) if dc.GetMultiLineTextExtent(itemText)[0] > maxsize: if tip != itemText: self.SetToolTipString(itemText) else: if tip: self.SetToolTipString('') if hoverItem.IsHyperText() and (flags & TREE_HITTEST_ONITEMLABEL) and hoverItem.IsEnabled(): self.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) self._isonhyperlink = True else: if self._isonhyperlink: self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) self._isonhyperlink = False # we process left mouse up event (enables in-place edit), right down # (pass to the user code), left dbl click (activate item) and # dragging/moving events for items drag-and-drop if not (event.LeftDown() or event.LeftUp() or event.RightDown() or event.LeftDClick() or \ event.Dragging() or ((event.Moving() or event.RightUp()) and self._isDragging)): event.Skip() return flags = 0 item, flags = self._anchor.HitTest(pt, self, flags, 0) if event.Dragging() and not self._isDragging and ((flags & TREE_HITTEST_ONITEMICON) or (flags & TREE_HITTEST_ONITEMLABEL)): if self._dragCount == 0: self._dragStart = pt self._countDrag = 0 self._dragCount = self._dragCount + 1 if self._dragCount != 3: # wait until user drags a bit further... return command = (event.RightIsDown() and [wxEVT_TREE_BEGIN_RDRAG] or [wxEVT_TREE_BEGIN_DRAG])[0] nevent = TreeEvent(command, self.GetId()) nevent._item = self._current nevent.SetEventObject(self) newpt = self.CalcScrolledPosition(pt) nevent.SetPoint(newpt) # by default the dragging is not supported, the user code must # explicitly allow the event for it to take place nevent.Veto() if self.GetEventHandler().ProcessEvent(nevent) and nevent.IsAllowed(): # we're going to drag this item self._isDragging = True # remember the old cursor because we will change it while # dragging self._oldCursor = self._cursor # in a single selection control, hide the selection temporarily if not (self.GetAGWWindowStyleFlag() & TR_MULTIPLE): self._oldSelection = self.GetSelection() if self._oldSelection: self._oldSelection.SetHilight(False) self.RefreshLine(self._oldSelection) else: selections = self.GetSelections() if len(selections) == 1: self._oldSelection = selections[0] self._oldSelection.SetHilight(False) self.RefreshLine(self._oldSelection) if self._dragImage: del self._dragImage # Create the custom draw image from the icons and the text of the item self._dragImage = DragImage(self, self._current) self._dragImage.BeginDrag(wx.Point(0,0), self) self._dragImage.Show() self._dragImage.Move(self.CalcScrolledPosition(pt)) elif event.Dragging() and self._isDragging: self._dragImage.Move(self.CalcScrolledPosition(pt)) if self._countDrag == 0 and item: self._oldItem = item if item != self._dropTarget: # unhighlight the previous drop target if self._dropTarget: self._dropTarget.SetHilight(False) self.RefreshLine(self._dropTarget) if item: item.SetHilight(True) self.RefreshLine(item) self._countDrag = self._countDrag + 1 self._dropTarget = item self.Update() if self._countDrag >= 3: # Here I am trying to avoid ugly repainting problems... hope it works self.RefreshLine(self._oldItem) self._countDrag = 0 elif (event.LeftUp() or event.RightUp()) and self._isDragging: if self._dragImage: self._dragImage.EndDrag() if self._dropTarget: self._dropTarget.SetHilight(False) if self._oldSelection: self._oldSelection.SetHilight(True) self.RefreshLine(self._oldSelection) self._oldSelection = None # generate the drag end event event = TreeEvent(wxEVT_TREE_END_DRAG, self.GetId()) event._item = item event._pointDrag = self.CalcScrolledPosition(pt) event.SetEventObject(self) self.GetEventHandler().ProcessEvent(event) self._isDragging = False self._dropTarget = None self.SetCursor(self._oldCursor) if wx.Platform in ["__WXMSW__", "__WXMAC__"]: self.Refresh() else: # Probably this is not enough on GTK. Try a Refresh() if it does not work. wx.YieldIfNeeded() else: # If we got to this point, we are not dragging or moving the mouse. # Because the code in carbon/toplevel.cpp will only set focus to the tree # if we skip for EVT_LEFT_DOWN, we MUST skip this event here for focus to work. # We skip even if we didn't hit an item because we still should # restore focus to the tree control even if we didn't exactly hit an item. if event.LeftDown(): self._hasFocus = True self.SetFocusIgnoringChildren() event.Skip() # here we process only the messages which happen on tree items self._dragCount = 0 if item == None: if self._editCtrl != None and item != self._editCtrl.item(): self._editCtrl.StopEditing() return # we hit the blank area if event.RightDown(): if self._editCtrl != None and item != self._editCtrl.item(): self._editCtrl.StopEditing() self._hasFocus = True self.SetFocusIgnoringChildren() # If the item is already selected, do not update the selection. # Multi-selections should not be cleared if a selected item is clicked. if not self.IsSelected(item): self.DoSelectItem(item, True, False) nevent = TreeEvent(wxEVT_TREE_ITEM_RIGHT_CLICK, self.GetId()) nevent._item = item nevent._pointDrag = self.CalcScrolledPosition(pt) nevent.SetEventObject(self) event.Skip(not self.GetEventHandler().ProcessEvent(nevent)) # Consistent with MSW (for now), send the ITEM_MENU *after* # the RIGHT_CLICK event. TODO: This behaviour may change. nevent2 = TreeEvent(wxEVT_TREE_ITEM_MENU, self.GetId()) nevent2._item = item nevent2._pointDrag = self.CalcScrolledPosition(pt) nevent2.SetEventObject(self) self.GetEventHandler().ProcessEvent(nevent2) elif event.LeftUp(): # this facilitates multiple-item drag-and-drop if self.HasAGWFlag(TR_MULTIPLE): selections = self.GetSelections() if len(selections) > 1 and not event.CmdDown() and not event.ShiftDown(): self.DoSelectItem(item, True, False) if self._lastOnSame: if item == self._current and (flags & TREE_HITTEST_ONITEMLABEL) and self.HasAGWFlag(TR_EDIT_LABELS): if self._editTimer: if self._editTimer.IsRunning(): self._editTimer.Stop() else: self._editTimer = TreeEditTimer(self) self._editTimer.Start(_DELAY, True) self._lastOnSame = False else: # !RightDown() && !LeftUp() ==> LeftDown() || LeftDClick() if not item or not item.IsEnabled(): if self._editCtrl != None and item != self._editCtrl.item(): self._editCtrl.StopEditing() return if self._editCtrl != None and item != self._editCtrl.item(): self._editCtrl.StopEditing() self._hasFocus = True self.SetFocusIgnoringChildren() if event.LeftDown(): self._lastOnSame = item == self._current if flags & TREE_HITTEST_ONITEMBUTTON: # only toggle the item for a single click, double click on # the button doesn't do anything (it toggles the item twice) if event.LeftDown(): self.Toggle(item) # don't select the item if the button was clicked return if item.GetType() > 0 and (flags & TREE_HITTEST_ONITEMCHECKICON) and (flags & TREE_HITTEST_ONITEMLABEL == 0): if event.LeftDown(): if flags & TREE_HITTEST_ONITEM and self.HasAGWFlag(TR_FULL_ROW_HIGHLIGHT): self.DoSelectItem(item, not self.HasAGWFlag(TR_MULTIPLE)) if self.IsItem3State(item): checked = self.GetItem3StateValue(item) checked = (checked+1)%3 else: checked = not self.IsItemChecked(item) self.CheckItem(item, checked) return # clear the previously selected items, if the # user clicked outside of the present selection. # otherwise, perform the deselection on mouse-up. # this allows multiple drag and drop to work. # but if Cmd is down, toggle selection of the clicked item if not self.IsSelected(item) or event.CmdDown(): if flags & TREE_HITTEST_ONITEM: # how should the selection work for this event? if item.IsHyperText(): self.SetItemVisited(item, True) is_multiple, extended_select, unselect_others = EventFlagsToSelType(self.GetAGWWindowStyleFlag(), event.ShiftDown(), event.CmdDown()) self.DoSelectItem(item, unselect_others, extended_select) # Handle hyperlink items... which are a bit odd sometimes elif self.IsSelected(item) and item.IsHyperText(): self.HandleHyperLink(item) # For some reason, Windows isn't recognizing a left double-click, # so we need to simulate it here. Allow 200 milliseconds for now. if event.LeftDClick(): # double clicking should not start editing the item label if self._editTimer: self._editTimer.Stop() self._lastOnSame = False # send activate event first nevent = TreeEvent(wxEVT_TREE_ITEM_ACTIVATED, self.GetId()) nevent._item = item nevent._pointDrag = self.CalcScrolledPosition(pt) nevent.SetEventObject(self) if not self.GetEventHandler().ProcessEvent(nevent): # if the user code didn't process the activate event, # handle it ourselves by toggling the item when it is # double clicked ## if item.HasPlus(): self.Toggle(item) def OnInternalIdle(self): """ This method is normally only used internally, but sometimes an application may need it to implement functionality that should not be disabled by an application defining an `OnIdle` handler in a derived class. This method may be used to do delayed painting, for example, and most implementations call :meth:`Window.UpdateWindowUI` in order to send update events to the window in idle time. """ # Check if we need to select the root item # because nothing else has been selected. # Delaying it means that we can invoke event handlers # as required, when a first item is selected. if not self.HasAGWFlag(TR_MULTIPLE) and not self.GetSelection(): if self._select_me: self.SelectItem(self._select_me) elif self.GetRootItem(): self.SelectItem(self.GetRootItem()) # after all changes have been done to the tree control, # we actually redraw the tree when everything is over if not self._dirty: return if self._freezeCount: return self._dirty = False self.CalculatePositions() self.Refresh() self.AdjustMyScrollbars() # event.Skip() def CalculateSize(self, item, dc, level=-1, align=0): """ Calculates overall position and size of an item. :param `item`: an instance of :class:`GenericTreeItem`; :param `dc`: an instance of :class:`DC`; :param integer `level`: the item level in the tree hierarchy; :param integer `align`: an integer specifying the alignment type: =============== ========================================= `align` Value Description =============== ========================================= 0 No horizontal alignment of windows (in items with windows). 1 Windows (in items with windows) are aligned at the same horizontal position. 2 Windows (in items with windows) are aligned at the rightmost edge of :class:`CustomTreeCtrl`. =============== ========================================= """ attr = item.GetAttributes() if attr and attr.HasFont(): dc.SetFont(attr.GetFont()) else: if item.IsBold(): dc.SetFont(self._boldFont) elif item.IsItalic(): dc.SetFont(self._italicFont) else: dc.SetFont(self._normalFont) text_w, text_h, dummy = dc.GetMultiLineTextExtent(item.GetText()) text_h+=2 # restore normal font dc.SetFont(self._normalFont) image_w, image_h = 0, 0 image = item.GetCurrentImage() if image != _NO_IMAGE: if self._imageListNormal: image_w, image_h = self._imageListNormal.GetSize(image) image_w += 4 total_h = ((image_h > text_h) and [image_h] or [text_h])[0] checkimage = item.GetCurrentCheckedImage() if checkimage is not None: wcheck, hcheck = self._imageListCheck.GetSize(checkimage) wcheck += 4 else: wcheck = 0 if total_h < 30: total_h += 2 # at least 2 pixels else: total_h += total_h/10 # otherwise 10% extra spacing if total_h > self._lineHeight: self._lineHeight = total_h wnd = item.GetWindow() if not wnd: totalWidth = image_w+text_w+wcheck+2 totalHeight = total_h else: totalWidth = item.GetWindowSize()[0]+image_w+text_w+wcheck+2 totalHeight = max(total_h, item.GetWindowSize()[1]) if level >= 0 and wnd: if align == 0: if level in self.absoluteWindows: self.absoluteWindows[level] = max(self.absoluteWindows[level], image_w+text_w+wcheck+2) else: self.absoluteWindows[level] = image_w+text_w+wcheck+2 elif align == 1: self.absoluteWindows[level] = max(self.absoluteWindows[level], image_w+text_w+wcheck+2) if item.IsSeparator(): totalWidth = self.GetClientSize()[0] totalHeight = total_h item.SetWidth(totalWidth) item.SetHeight(totalHeight) def CalculateLevel(self, item, dc, level, y, align=0): """ Calculates the level of an item inside the tree hierarchy. :param `item`: an instance of :class:`GenericTreeItem`; :param `dc`: an instance of :class:`DC`; :param integer `level`: the item level in the tree hierarchy; :param integer `y`: the current vertical position inside the :class:`PyScrolledWindow`; :param integer `align`: an integer specifying the alignment type: =============== ========================================= `align` Value Description =============== ========================================= 0 No horizontal alignment of windows (in items with windows). 1 Windows (in items with windows) are aligned at the same horizontal position. 2 Windows (in items with windows) are aligned at the rightmost edge of :class:`CustomTreeCtrl`. =============== ========================================= :return: The new `y` vertical position inside the :class:`PyScrolledWindow`. """ x = level*self._indent if not self.HasAGWFlag(TR_HIDE_ROOT): x += self._indent elif level == 0: # a hidden root is not evaluated, but its # children are always calculated children = item.GetChildren() count = len(children) level = level + 1 for n in xrange(count): y = self.CalculateLevel(children[n], dc, level, y, align) # recurse return y self.CalculateSize(item, dc, level, align) # set its position item.SetX(x+self._spacing) item.SetY(y) y += self.GetLineHeight(item) if not item.IsExpanded(): # we don't need to calculate collapsed branches return y children = item.GetChildren() count = len(children) level = level + 1 for n in xrange(count): y = self.CalculateLevel(children[n], dc, level, y, align) # recurse return y def CalculatePositions(self): """ Calculates all the positions of the visible items. """ if not self._anchor: return self.absoluteWindows = {} dc = wx.ClientDC(self) self.PrepareDC(dc) dc.SetFont(self._normalFont) dc.SetPen(self._dottedPen) y = 2 y = self.CalculateLevel(self._anchor, dc, 0, y) # start recursion if self.HasAGWFlag(TR_ALIGN_WINDOWS) or self.HasAGWFlag(TR_ALIGN_WINDOWS_RIGHT): align = (self.HasAGWFlag(TR_ALIGN_WINDOWS) and [1] or [2])[0] y = 2 y = self.CalculateLevel(self._anchor, dc, 0, y, align) # start recursion def RefreshSubtree(self, item): """ Refreshes a damaged subtree of an item. :param `item`: an instance of :class:`GenericTreeItem`. """ if self._dirty: return if self._freezeCount: return client = self.GetClientSize() rect = wx.Rect() x, rect.y = self.CalcScrolledPosition(0, item.GetY()) rect.width = client.x rect.height = client.y self.Refresh(True, rect) self.AdjustMyScrollbars() def RefreshLine(self, item): """ Refreshes a damaged item line. :param `item`: an instance of :class:`GenericTreeItem`. """ if self._dirty: return if self._freezeCount: return rect = wx.Rect() x, rect.y = self.CalcScrolledPosition(0, item.GetY()) rect.width = self.GetClientSize().x rect.height = self.GetLineHeight(item) self.Refresh(True, rect) def RefreshSelected(self): """ Refreshes a damaged selected item line. """ if self._freezeCount: return # TODO: this is awfully inefficient, we should keep the list of all # selected items internally, should be much faster if self._anchor: self.RefreshSelectedUnder(self._anchor) def RefreshSelectedUnder(self, item): """ Refreshes the selected items under the given item. :param `item`: an instance of :class:`GenericTreeItem`. """ if self._freezeCount: return if item.IsSelected(): self.RefreshLine(item) children = item.GetChildren() for child in children: self.RefreshSelectedUnder(child) def RefreshItemWithWindows(self, item=None): """ Refreshes the items with which a window is associated. :param `item`: an instance of :class:`GenericTreeItem`. If `item` is ``None``, then the recursive refresh starts from the root node. :note: This method is called only if the style ``TR_ALIGN_WINDOWS_RIGHT`` is used. """ if self._freezeCount: return if item is None: if self._anchor: self.RefreshItemWithWindows(self._anchor) return wnd = item.GetWindow() if wnd and wnd.IsShown(): self.RefreshLine(item) children = item.GetChildren() for child in children: self.RefreshItemWithWindows(child) def Freeze(self): """ Freeze :class:`CustomTreeCtrl`. Freezes the window or, in other words, prevents any updates from taking place on screen, the window is not redrawn at all. :meth:`~Thaw` must be called to reenable window redrawing. Calls to these two functions may be nested. :note: This method is useful for visual appearance optimization (for example, it is a good idea to use it before doing many large text insertions in a row into a :class:`TextCtrl` under wxGTK) but is not implemented on all platforms nor for all controls so it is mostly just a hint to wxWidgets and not a mandatory directive. """ self._freezeCount = self._freezeCount + 1 def Thaw(self): """ Thaw :class:`CustomTreeCtrl`. Reenables window updating after a previous call to :meth:`~Freeze`. To really thaw the control, it must be called exactly the same number of times as :meth:`~Freeze`. :raise: `Exception` if :meth:`~Thaw` has been called without an un-matching :meth:`~Freeze`. """ if self._freezeCount == 0: raise Exception("\nERROR: Thawing Unfrozen Tree Control?") self._freezeCount = self._freezeCount - 1 if not self._freezeCount: self.Refresh() # ---------------------------------------------------------------------------- # changing colours: we need to refresh the tree control # ---------------------------------------------------------------------------- def SetBackgroundColour(self, colour): """ Changes the background colour of :class:`CustomTreeCtrl`. :param `colour`: the colour to be used as the background colour, pass :class:`NullColour` to reset to the default colour. :return: ``False`` if the underlying :class:`PyScrolledWindow` does not accept the new colour, ``True`` otherwise. :note: The background colour is usually painted by the default :class:`EraseEvent` event handler function under Windows and automatically under GTK. :note: Setting the background colour does not cause an immediate refresh, so you may wish to call :meth:`Window.ClearBackground` or :meth:`Window.Refresh` after calling this function. :note: Overridden from :class:`PyScrolledWindow`. """ if not wx.PyScrolledWindow.SetBackgroundColour(self, colour): return False if self._freezeCount: return True self.Refresh() return True def SetForegroundColour(self, colour): """ Changes the foreground colour of :class:`CustomTreeCtrl`. :param `colour`: the colour to be used as the foreground colour, pass :class:`NullColour` to reset to the default colour. :return: ``False`` if the underlying :class:`PyScrolledWindow` does not accept the new colour, ``True`` otherwise. :note: Overridden from :class:`PyScrolledWindow`. """ if not wx.PyScrolledWindow.SetForegroundColour(self, colour): return False if self._freezeCount: return True self.Refresh() return True def OnGetToolTip(self, event): """ Process the tooltip event, to speed up event processing. Does not actually get a tooltip. :param `event`: a :class:`CommandTreeEvent` event to be processed. """ event.Veto() def DoGetBestSize(self): """ Gets the size which best suits the window: for a control, it would be the minimal size which doesn't truncate the control, for a panel - the same size as it would have after a call to `Fit()`. :return: An instance of :class:`Size`. :note: Overridden from :class:`PyScrolledWindow`. """ # something is better than nothing... # 100x80 is what the MSW version will get from the default # wxControl::DoGetBestSize return wx.Size(100, 80) def GetMaxWidth(self, respect_expansion_state=True): """ Returns the maximum width of the :class:`CustomTreeCtrl`. :param bool `respect_expansion_state`: if ``True``, only the expanded items (and their children) will be measured. Otherwise all the items are expanded and their width measured. :return: the maximum width of :class:`CustomTreeCtrl`, in pixels. """ self.Freeze() root = self.GetRootItem() rect = self.GetBoundingRect(root, True) # It looks like the space between the "+" and the node # rect occupies 4 pixels approximatively maxwidth = rect.x + rect.width + 4 lastheight = rect.y + rect.height if not self.IsExpanded(root): if respect_expansion_state: return maxwidth if not respect_expansion_state: self.ExpandAll() maxwidth, lastheight = self.RecurseOnChildren(root, maxwidth, respect_expansion_state) self.Thaw() return maxwidth def RecurseOnChildren(self, item, maxwidth, respect_expansion_state): """ Recurses over all the children of the spcified items, calculating their maximum width. :param `item`: an instance of :class:`GenericTreeItem`; :param integer `maxwidth`: the current maximum width for :class:`CustomTreeCtrl`, in pixels; :param bool `respect_expansion_state`: if ``True``, only the expanded items (and their children) will be measured. Otherwise all the items are expanded and their width measured. :return: A tuple containing the maximum width and item height, in pixels. """ child, cookie = self.GetFirstChild(item) lastheight = 0 while child: rect = self.GetBoundingRect(child, True) # It looks like the space between the "+" and the node # rect occupies 4 pixels approximatively maxwidth = max(maxwidth, rect.x + rect.width + 4) lastheight = rect.y + rect.height if self.IsExpanded(child) or not respect_expansion_state: maxwidth, lastheight = self.RecurseOnChildren(child, maxwidth, respect_expansion_state) child, cookie = self.GetNextChild(item, cookie) return maxwidth, lastheight def GetClassDefaultAttributes(self): """ Returns the default font and colours which are used by the control. This is useful if you want to use the same font or colour in your own control as in a standard control -- which is a much better idea than hard coding specific colours or fonts which might look completely out of place on the users system, especially if it uses themes. This static method is "overridden'' in many derived classes and so calling, for example, :meth:`Button.GetClassDefaultAttributes` () will typically return the values appropriate for a button which will be normally different from those returned by, say, :meth:`ListCtrl.GetClassDefaultAttributes` (). :return: An instance of :class:`VisualAttributes`. :note: The :class:`VisualAttributes` structure has at least the fields `font`, `colFg` and `colBg`. All of them may be invalid if it was not possible to determine the default control appearance or, especially for the background colour, if the field doesn't make sense as is the case for `colBg` for the controls with themed background. :note: Overridden from :class:`PyControl`. """ attr = wx.VisualAttributes() attr.colFg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOWTEXT) attr.colBg = wx.SystemSettings_GetColour(wx.SYS_COLOUR_LISTBOX) attr.font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT) return attr GetClassDefaultAttributes = classmethod(GetClassDefaultAttributes)
mit
[ 3, 5620, 777, 13, 327, 202, 199, 3, 445, 7698, 47, 5747, 907, 3582, 2431, 4818, 4718, 5025, 10320, 2594, 202, 199, 3, 12062, 1038, 581, 4885, 6061, 5311, 1214, 3444, 21311, 4068, 4818, 9417, 3987, 9778, 14, 202, 199, 3, 202, 199, 3, 6061, 8273, 598, 1214, 6738, 12, 768, 5557, 10162, 8315, 202, 199, 3, 491, 27126, 27095, 26, 8087, 25298, 6029, 12, 7829, 14, 383, 19152, 202, 199, 3, 202, 199, 3, 202, 199, 3, 3254, 3820, 202, 199, 3, 202, 199, 3, 4580, 2786, 2900, 710, 7949, 2093, 24545, 4818, 14, 3987, 9778, 23889, 23840, 12, 6061, 6006, 6596, 510, 6457, 17269, 202, 199, 3, 3091, 22672, 1010, 14791, 18615, 6423, 16230, 4005, 961, 8089, 14, 710, 7758, 3868, 780, 10314, 445, 1377, 83, 202, 199, 3, 4005, 4932, 603, 688, 23889, 26, 202, 199, 3, 202, 199, 3, 413, 14, 7649, 4005, 22467, 437, 16917, 481, 8442, 281, 13, 10146, 10257, 3928, 6047, 1010, 445, 3274, 16485, 202, 199, 3, 259, 32267, 3014, 4236, 1933, 3292, 1809, 6047, 334, 14351, 8388, 3987, 9778, 32090, 5972, 377, 1672, 202, 199, 3, 259, 10257, 3928, 32658, 680, 202, 199, 3, 202, 199, 3, 499, 14, 7649, 4005, 603, 1017, 530, 5417, 4818, 14, 3987, 9778, 18890, 316, 15, 2001, 4762, 1044, 13942, 26, 8388, 3987, 9778, 202, 199, 3, 259, 428, 1181, 848, 590, 7910, 5915, 15, 2001, 4762, 874, 710, 23836, 4068, 603, 7130, 26147, 22117, 710, 653, 1905, 8612, 202, 199, 3, 259, 13481, 6601, 1804, 688, 24545, 298, 51, 11607, 2, 18890, 316, 15, 2001, 4762, 1044, 12, 16485, 437, 644, 811, 14, 473, 7529, 1133, 22207, 202, 199, 3, 259, 1804, 2131, 17685, 4005, 7707, 4005, 4226, 10314, 14, 202, 199, 3, 202, 199, 3, 650, 14, 428, 4536, 4949, 1696, 4068, 30833, 3868, 780, 31, 473, 26858, 3091, 473, 25395, 12, 11842, 8388, 3987, 9778, 6596, 1413, 2577, 202, 199, 3, 259, 22613, 12, 11017, 2136, 7719, 1666, 4068, 428, 2325, 30611, 3746, 14, 202, 199, 3, 202, 199, 3, 202, 199, 3, 2104, 2900, 1804, 688, 24545, 2165, 7561, 12, 20260, 24545, 3447, 14666, 1470, 6061, 21605, 799, 5203, 12, 7754, 202, 199, 3, 6990, 4005, 3194, 2854, 26, 202, 199, 3, 202, 199, 3, 436, 8273, 14, 71, 1214, 6738, 32, 391, 1192, 7697, 382, 14, 957, 202, 199, 3, 436, 8273, 14, 71, 1214, 6738, 32, 6799, 14, 957, 202, 199, 3, 202, 199, 3, 4236, 12, 17985, 2971, 590, 12, 4005, 710, 4818, 4718, 18027, 316, 3820, 21512, 202, 199, 3, 202, 199, 3, 202, 199, 3, 9599, 24545, 5429, 1470, 202, 199, 3, 5620, 777, 13, 327, 8065, 199, 624, 202, 199, 26, 533, 1705, 7223, 3987, 9778, 64, 365, 282, 1021, 626, 24102, 2932, 314, 13942, 402, 520, 533, 1705, 3987, 9778, 3559, 543, 2005, 1655, 202, 199, 287, 14666, 1470, 14, 8065, 199, 5831, 202, 199, 21326, 2999, 199, 26, 533, 1705, 7223, 3987, 9778, 64, 365, 282, 1021, 626, 24102, 2932, 314, 13942, 402, 520, 533, 1705, 3987, 9778, 3559, 543, 18871, 314, 202, 199, 7191, 1300, 805, 10874, 1417, 12254, 2005, 1655, 655, 14666, 1470, 14, 961, 1021, 1630, 440, 19687, 641, 202, 199, 1589, 5438, 3304, 12, 465, 652, 365, 282, 2615, 5771, 13, 5485, 78, 3123, 3304, 14, 202, 199, 33, 2064, 402, 314, 1300, 805, 10874, 1417, 402, 520, 533, 1705, 7223, 3987, 9778, 64, 334, 271, 14922, 5084, 395, 315, 10234, 202, 199, 475, 314, 4465, 520, 533, 1705, 3987, 9778, 64, 13942, 642, 1021, 5171, 26, 2999, 199, 10, 2670, 3532, 13, 466, 2974, 26, 1104, 12922, 787, 8837, 370, 2429, 12, 2951, 4895, 503, 625, 5511, 10292, 1174, 543, 949, 6770, 10876, 315, 7252, 314, 1242, 1159, 4978, 27, 202, 199, 10, 16230, 2291, 367, 650, 13, 929, 574, 24190, 2974, 27, 202, 199, 10, 13514, 4259, 13, 466, 2974, 26, 3967, 473, 325, 2820, 370, 5324, 14070, 2873, 2471, 83, 315, 520, 533, 1705, 7223, 3987, 9778, 3559, 473, 10292, 4346, 2005, 4340, 370, 2429, 3062, 12, 626, 6326, 12249, 14, 2002, 12, 473, 1202, 314, 2569, 18140, 26, 15497, 10292, 446, 2900, 9104, 13, 2415, 626, 787, 14070, 2873, 2471, 83, 911, 506, 16108, 13914, 14, 1010, 1163, 5932, 12, 1128, 1454, 1373, 402, 282, 663, 402, 14070, 2873, 2471, 83, 626, 8663, 282, 2863, 1676, 883, 506, 7923, 737, 1128, 5403, 14, 982, 282, 14070, 2873, 2471, 1031, 15410, 7923, 12, 2066, 1006, 402, 2399, 9104, 14070, 2873, 2471, 83, 1128, 1471, 506, 625, 10718, 14, 10292, 446, 982, 282, 14070, 2873, 2471, 1031, 15410, 625, 10718, 12, 2066, 1006, 402, 2399, 1982, 3380, 911, 8649, 1128, 21325, 14, 2999, 199, 10, 21344, 1073, 13, 466, 2974, 26, 2985, 3648, 2839, 376, 10342, 1073, 12, 543, 314, 5576, 12817, 3920, 641, 10292, 394, 1883, 316, 27, 202, 199, 10, 6879, 604, 1318, 2974, 334, 538, 4610, 26742, 370, 1050, 282, 8057, 4528, 315, 282, 21838, 1242, 12, 15105, 10292, 1124, 14379, 1040, 435, 1124, 8468, 1040, 465, 314, 1124, 8468, 1040, 790, 23016, 365, 16949, 701, 520, 533, 1705, 7223, 3987, 9778, 64, 370, 9578, 10292, 314, 20401, 436, 1124, 9778, 1040, 435, 1124, 8468, 1040, 365, 16949, 701, 314, 4298, 367, 5174, 19191, 2736, 202, 199, 10, 3447, 14744, 15, 2297, 14744, 2974, 334, 6314, 543, 3932, 8971, 503, 21977, 379, 734, 7016, 83, 2736, 202, 199, 10, 2816, 12359, 2222, 13, 13517, 3938, 883, 506, 10102, 2163, 370, 376, 1242, 27, 202, 199, 10, 25987, 4783, 370, 394, 7366, 1183, 6998, 314, 11114, 10102, 370, 3123, 2974, 641, 314, 10292, 2011, 3123, 2166, 14, 202, 199, 10, 25987, 4783, 370, 6998, 314, 11114, 10102, 370, 3123, 2974, 370, 314, 2451, 2786, 6275, 402, 520, 533, 1705, 7223, 3987, 9778, 64, 27, 202, 199, 10, 3758, 7267, 3449, 12, 6709, 334, 11392, 15, 7870, 9, 7267, 3449, 436, 5417, 10292, 19801, 65, 7267, 3449, 27, 202, 199, 10, 8388, 1759, 18981, 436, 5978, 5935, 6137, 641, 314, 23158, 27, 202, 199, 10, 13510, 314, 520, 533, 1705, 7223, 3987, 9778, 64, 1242, 15766, 370, 282, 25994, 1759, 1834, 513, 27, 202, 199, 10, 13510, 314, 520, 533 ]
[ 5620, 777, 13, 327, 202, 199, 3, 445, 7698, 47, 5747, 907, 3582, 2431, 4818, 4718, 5025, 10320, 2594, 202, 199, 3, 12062, 1038, 581, 4885, 6061, 5311, 1214, 3444, 21311, 4068, 4818, 9417, 3987, 9778, 14, 202, 199, 3, 202, 199, 3, 6061, 8273, 598, 1214, 6738, 12, 768, 5557, 10162, 8315, 202, 199, 3, 491, 27126, 27095, 26, 8087, 25298, 6029, 12, 7829, 14, 383, 19152, 202, 199, 3, 202, 199, 3, 202, 199, 3, 3254, 3820, 202, 199, 3, 202, 199, 3, 4580, 2786, 2900, 710, 7949, 2093, 24545, 4818, 14, 3987, 9778, 23889, 23840, 12, 6061, 6006, 6596, 510, 6457, 17269, 202, 199, 3, 3091, 22672, 1010, 14791, 18615, 6423, 16230, 4005, 961, 8089, 14, 710, 7758, 3868, 780, 10314, 445, 1377, 83, 202, 199, 3, 4005, 4932, 603, 688, 23889, 26, 202, 199, 3, 202, 199, 3, 413, 14, 7649, 4005, 22467, 437, 16917, 481, 8442, 281, 13, 10146, 10257, 3928, 6047, 1010, 445, 3274, 16485, 202, 199, 3, 259, 32267, 3014, 4236, 1933, 3292, 1809, 6047, 334, 14351, 8388, 3987, 9778, 32090, 5972, 377, 1672, 202, 199, 3, 259, 10257, 3928, 32658, 680, 202, 199, 3, 202, 199, 3, 499, 14, 7649, 4005, 603, 1017, 530, 5417, 4818, 14, 3987, 9778, 18890, 316, 15, 2001, 4762, 1044, 13942, 26, 8388, 3987, 9778, 202, 199, 3, 259, 428, 1181, 848, 590, 7910, 5915, 15, 2001, 4762, 874, 710, 23836, 4068, 603, 7130, 26147, 22117, 710, 653, 1905, 8612, 202, 199, 3, 259, 13481, 6601, 1804, 688, 24545, 298, 51, 11607, 2, 18890, 316, 15, 2001, 4762, 1044, 12, 16485, 437, 644, 811, 14, 473, 7529, 1133, 22207, 202, 199, 3, 259, 1804, 2131, 17685, 4005, 7707, 4005, 4226, 10314, 14, 202, 199, 3, 202, 199, 3, 650, 14, 428, 4536, 4949, 1696, 4068, 30833, 3868, 780, 31, 473, 26858, 3091, 473, 25395, 12, 11842, 8388, 3987, 9778, 6596, 1413, 2577, 202, 199, 3, 259, 22613, 12, 11017, 2136, 7719, 1666, 4068, 428, 2325, 30611, 3746, 14, 202, 199, 3, 202, 199, 3, 202, 199, 3, 2104, 2900, 1804, 688, 24545, 2165, 7561, 12, 20260, 24545, 3447, 14666, 1470, 6061, 21605, 799, 5203, 12, 7754, 202, 199, 3, 6990, 4005, 3194, 2854, 26, 202, 199, 3, 202, 199, 3, 436, 8273, 14, 71, 1214, 6738, 32, 391, 1192, 7697, 382, 14, 957, 202, 199, 3, 436, 8273, 14, 71, 1214, 6738, 32, 6799, 14, 957, 202, 199, 3, 202, 199, 3, 4236, 12, 17985, 2971, 590, 12, 4005, 710, 4818, 4718, 18027, 316, 3820, 21512, 202, 199, 3, 202, 199, 3, 202, 199, 3, 9599, 24545, 5429, 1470, 202, 199, 3, 5620, 777, 13, 327, 8065, 199, 624, 202, 199, 26, 533, 1705, 7223, 3987, 9778, 64, 365, 282, 1021, 626, 24102, 2932, 314, 13942, 402, 520, 533, 1705, 3987, 9778, 3559, 543, 2005, 1655, 202, 199, 287, 14666, 1470, 14, 8065, 199, 5831, 202, 199, 21326, 2999, 199, 26, 533, 1705, 7223, 3987, 9778, 64, 365, 282, 1021, 626, 24102, 2932, 314, 13942, 402, 520, 533, 1705, 3987, 9778, 3559, 543, 18871, 314, 202, 199, 7191, 1300, 805, 10874, 1417, 12254, 2005, 1655, 655, 14666, 1470, 14, 961, 1021, 1630, 440, 19687, 641, 202, 199, 1589, 5438, 3304, 12, 465, 652, 365, 282, 2615, 5771, 13, 5485, 78, 3123, 3304, 14, 202, 199, 33, 2064, 402, 314, 1300, 805, 10874, 1417, 402, 520, 533, 1705, 7223, 3987, 9778, 64, 334, 271, 14922, 5084, 395, 315, 10234, 202, 199, 475, 314, 4465, 520, 533, 1705, 3987, 9778, 64, 13942, 642, 1021, 5171, 26, 2999, 199, 10, 2670, 3532, 13, 466, 2974, 26, 1104, 12922, 787, 8837, 370, 2429, 12, 2951, 4895, 503, 625, 5511, 10292, 1174, 543, 949, 6770, 10876, 315, 7252, 314, 1242, 1159, 4978, 27, 202, 199, 10, 16230, 2291, 367, 650, 13, 929, 574, 24190, 2974, 27, 202, 199, 10, 13514, 4259, 13, 466, 2974, 26, 3967, 473, 325, 2820, 370, 5324, 14070, 2873, 2471, 83, 315, 520, 533, 1705, 7223, 3987, 9778, 3559, 473, 10292, 4346, 2005, 4340, 370, 2429, 3062, 12, 626, 6326, 12249, 14, 2002, 12, 473, 1202, 314, 2569, 18140, 26, 15497, 10292, 446, 2900, 9104, 13, 2415, 626, 787, 14070, 2873, 2471, 83, 911, 506, 16108, 13914, 14, 1010, 1163, 5932, 12, 1128, 1454, 1373, 402, 282, 663, 402, 14070, 2873, 2471, 83, 626, 8663, 282, 2863, 1676, 883, 506, 7923, 737, 1128, 5403, 14, 982, 282, 14070, 2873, 2471, 1031, 15410, 7923, 12, 2066, 1006, 402, 2399, 9104, 14070, 2873, 2471, 83, 1128, 1471, 506, 625, 10718, 14, 10292, 446, 982, 282, 14070, 2873, 2471, 1031, 15410, 625, 10718, 12, 2066, 1006, 402, 2399, 1982, 3380, 911, 8649, 1128, 21325, 14, 2999, 199, 10, 21344, 1073, 13, 466, 2974, 26, 2985, 3648, 2839, 376, 10342, 1073, 12, 543, 314, 5576, 12817, 3920, 641, 10292, 394, 1883, 316, 27, 202, 199, 10, 6879, 604, 1318, 2974, 334, 538, 4610, 26742, 370, 1050, 282, 8057, 4528, 315, 282, 21838, 1242, 12, 15105, 10292, 1124, 14379, 1040, 435, 1124, 8468, 1040, 465, 314, 1124, 8468, 1040, 790, 23016, 365, 16949, 701, 520, 533, 1705, 7223, 3987, 9778, 64, 370, 9578, 10292, 314, 20401, 436, 1124, 9778, 1040, 435, 1124, 8468, 1040, 365, 16949, 701, 314, 4298, 367, 5174, 19191, 2736, 202, 199, 10, 3447, 14744, 15, 2297, 14744, 2974, 334, 6314, 543, 3932, 8971, 503, 21977, 379, 734, 7016, 83, 2736, 202, 199, 10, 2816, 12359, 2222, 13, 13517, 3938, 883, 506, 10102, 2163, 370, 376, 1242, 27, 202, 199, 10, 25987, 4783, 370, 394, 7366, 1183, 6998, 314, 11114, 10102, 370, 3123, 2974, 641, 314, 10292, 2011, 3123, 2166, 14, 202, 199, 10, 25987, 4783, 370, 6998, 314, 11114, 10102, 370, 3123, 2974, 370, 314, 2451, 2786, 6275, 402, 520, 533, 1705, 7223, 3987, 9778, 64, 27, 202, 199, 10, 3758, 7267, 3449, 12, 6709, 334, 11392, 15, 7870, 9, 7267, 3449, 436, 5417, 10292, 19801, 65, 7267, 3449, 27, 202, 199, 10, 8388, 1759, 18981, 436, 5978, 5935, 6137, 641, 314, 23158, 27, 202, 199, 10, 13510, 314, 520, 533, 1705, 7223, 3987, 9778, 64, 1242, 15766, 370, 282, 25994, 1759, 1834, 513, 27, 202, 199, 10, 13510, 314, 520, 533, 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,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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 ]
lodow/portia-proxy
slyd/slyd/html.py
4
3758
""" Removes JavaScript from HTML This module removes all existing JavaScript in an HTML document. """ import re from scrapely.htmlpage import HtmlTag, HtmlTagType, parse_html from slybot.utils import htmlpage_from_response from slybot.baseurl import insert_base_url from .annotations import add_tagids from .utils import serialize_tag ### Known weaknesses # Doesn't deal with JS hidden in CSS # Doesn't deal with meta redirect javascript URIs INTRINSIC_EVENT_ATTRIBUTES = ("onload", "onunload", "onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", "onmouseout", "onfocus", "onblur", "onkeypress", "onkeydown", "onkeyup", "onsubmit", "onreset", "onselect", "onchange", "onerror", "onbeforeunload") URI_ATTRIBUTES = ("action", "background", "cite", "classid", "codebase", "data", "href", "longdesc", "profile", "src", "usemap") AS_SCRIPT_REGION_BEGIN = "<!-- begin region added by slyd-->" AS_SCRIPT_REGION_END = "<!-- end region added by slyd-->" _AS_COMMENT_BEGIN = "<!-- begin_ascomment:" _AS_COMMENT_END = ":end_ascomment -->" _ENTITY_RE = re.compile("&#(\d+);") def _deentitize_unicode(mystr): """replaces all entities in the form &#\d+; by its unicode equivalent. """ return _ENTITY_RE.sub(lambda m: unichr(int(m.groups()[0])), mystr) def html4annotation(htmlpage, baseurl=None): """Convert the given html document for the annotation UI This adds tags, removes scripts and optionally adds a base url """ htmlpage = add_tagids(htmlpage) cleaned_html = descriptify(htmlpage) if baseurl: cleaned_html = insert_base_url(cleaned_html, baseurl) return cleaned_html def extract_html(response): """Extracts an html page from the response. """ return htmlpage_from_response(response).body def descriptify(doc): """Clean JavaScript in a html source string. """ parsed = parse_html(doc) newdoc = [] inserted_comment = False for element in parsed: if isinstance(element, HtmlTag): if not inserted_comment and element.tag == "script" and element.tag_type == HtmlTagType.OPEN_TAG: newdoc.append(_AS_COMMENT_BEGIN + doc[element.start:element.end] + _AS_COMMENT_END) inserted_comment = True elif element.tag == "script" and element.tag_type == HtmlTagType.CLOSE_TAG: if inserted_comment: inserted_comment = False newdoc.append(_AS_COMMENT_BEGIN + doc[element.start:element.end] + _AS_COMMENT_END) elif element.tag == "noscript": newdoc.append(_AS_COMMENT_BEGIN + doc[element.start:element.end] + _AS_COMMENT_END) else: for key, val in element.attributes.copy().items(): # Empty intrinsic events if key in INTRINSIC_EVENT_ATTRIBUTES: element.attributes[key] = "" # Rewrite javascript URIs elif key in URI_ATTRIBUTES and val is not None and "javascript:" in _deentitize_unicode(val): element.attributes[key] = "about:blank" else: continue newdoc.append(serialize_tag(element)) else: text = doc[element.start:element.end] if inserted_comment and text.strip() and not (text.startswith("<!--") and text.endswith("-->")): newdoc.append(_AS_COMMENT_BEGIN + text + _AS_COMMENT_END) else: newdoc.append(text) return ''.join(newdoc)
bsd-3-clause
[ 624, 272, 23169, 15250, 687, 4163, 339, 961, 859, 14185, 1006, 3411, 15250, 315, 376, 4163, 2213, 14, 199, 199, 624, 199, 646, 295, 199, 504, 10328, 321, 590, 14, 1360, 1606, 492, 20880, 1931, 12, 20880, 1931, 804, 12, 2198, 63, 1360, 199, 504, 308, 590, 3018, 14, 1208, 492, 3517, 1606, 63, 504, 63, 1310, 199, 504, 308, 590, 3018, 14, 28937, 492, 5518, 63, 1095, 63, 633, 199, 504, 1275, 11270, 492, 1050, 63, 1450, 1580, 199, 504, 1275, 1208, 492, 8437, 63, 1450, 199, 199, 5680, 31862, 9282, 17775, 874, 199, 3, 258, 12078, 78, 1133, 7962, 543, 18001, 8752, 315, 15750, 199, 3, 258, 12078, 78, 1133, 7962, 543, 3404, 4660, 18910, 30143, 199, 199, 19652, 10789, 948, 63, 8193, 63, 18166, 275, 1689, 265, 912, 401, 298, 265, 25477, 401, 298, 265, 4891, 401, 298, 265, 26469, 4891, 401, 1169, 298, 265, 573, 2972, 944, 401, 298, 265, 10544, 384, 401, 298, 265, 10544, 1883, 401, 1169, 298, 265, 10544, 1185, 401, 298, 265, 10544, 548, 401, 298, 265, 12283, 401, 1169, 298, 265, 3345, 300, 401, 298, 265, 498, 2915, 401, 298, 265, 498, 2110, 401, 1169, 298, 265, 498, 384, 401, 298, 265, 7275, 401, 298, 265, 3958, 401, 298, 265, 2416, 401, 1169, 298, 18128, 401, 298, 265, 705, 401, 298, 265, 5182, 25477, 531, 199, 199, 7639, 63, 18166, 275, 1689, 1287, 401, 298, 7451, 401, 298, 25171, 401, 298, 12334, 68, 401, 298, 600, 1095, 401, 355, 298, 576, 401, 298, 6399, 401, 298, 2809, 3257, 401, 298, 2913, 401, 298, 2164, 401, 298, 1180, 1130, 531, 199, 199, 1179, 63, 10484, 63, 23030, 63, 15947, 275, 3886, 17722, 5386, 4897, 3483, 701, 308, 590, 68, 306, 4335, 199, 1179, 63, 10484, 63, 23030, 63, 3902, 275, 3886, 17722, 1284, 4897, 3483, 701, 308, 590, 68, 306, 4335, 199, 199, 63, 1179, 63, 10973, 63, 15947, 275, 3886, 17722, 5386, 63, 305, 3349, 5424, 199, 63, 1179, 63, 10973, 63, 3902, 275, 7244, 500, 63, 305, 3349, 1553, 4335, 199, 63, 13630, 63, 907, 275, 295, 14, 2014, 480, 7997, 2961, 68, 11, 2736, 531, 421, 199, 318, 485, 271, 287, 280, 30510, 63, 2975, 8, 1662, 495, 304, 272, 408, 1155, 5862, 1006, 9045, 315, 314, 1824, 1253, 20262, 68, 11, 27, 701, 2399, 272, 2649, 7353, 14, 272, 408, 272, 372, 485, 13630, 63, 907, 14, 954, 8, 2734, 333, 26, 17742, 8, 442, 8, 77, 14, 2634, 3430, 16, 12884, 3002, 495, 9, 421, 199, 318, 3517, 20, 9340, 8, 1360, 1606, 12, 1300, 633, 29, 403, 304, 272, 408, 7306, 314, 1627, 3517, 2213, 367, 314, 11262, 14041, 339, 961, 9584, 3762, 12, 14185, 10554, 436, 14190, 9584, 282, 1300, 1166, 272, 408, 272, 3517, 1606, 275, 1050, 63, 1450, 1580, 8, 1360, 1606, 9, 272, 12364, 63, 1360, 275, 7039, 80, 3338, 8, 1360, 1606, 9, 272, 340, 1300, 633, 26, 267, 12364, 63, 1360, 275, 5518, 63, 1095, 63, 633, 8, 8275, 63, 1360, 12, 1300, 633, 9, 272, 372, 12364, 63, 1360, 421, 199, 318, 5536, 63, 1360, 8, 1310, 304, 272, 408, 12147, 83, 376, 3517, 2034, 687, 314, 1177, 14, 272, 408, 272, 372, 3517, 1606, 63, 504, 63, 1310, 8, 1310, 680, 2030, 421, 199, 318, 7039, 80, 3338, 8, 1301, 304, 272, 408, 6580, 15250, 315, 282, 3517, 1350, 1059, 14, 272, 408, 272, 4565, 275, 2198, 63, 1360, 8, 1301, 9, 272, 892, 1301, 275, 942, 272, 11788, 63, 3349, 275, 756, 272, 367, 1819, 315, 4565, 26, 267, 340, 1228, 8, 2108, 12, 20880, 1931, 304, 288, 340, 440, 11788, 63, 3349, 436, 1819, 14, 1450, 508, 298, 1579, 2, 436, 1819, 14, 1450, 63, 466, 508, 20880, 1931, 804, 14, 9935, 63, 6967, 26, 355, 892, 1301, 14, 740, 1547, 1179, 63, 10973, 63, 15947, 435, 1382, 59, 2108, 14, 928, 26, 2108, 14, 500, 61, 435, 485, 1179, 63, 10973, 63, 3902, 9, 355, 11788, 63, 3349, 275, 715, 288, 916, 1819, 14, 1450, 508, 298, 1579, 2, 436, 1819, 14, 1450, 63, 466, 508, 20880, 1931, 804, 14, 18219, 63, 6967, 26, 355, 340, 11788, 63, 3349, 26, 490, 11788, 63, 3349, 275, 756, 355, 892, 1301, 14, 740, 1547, 1179, 63, 10973, 63, 15947, 435, 1382, 59, 2108, 14, 928, 26, 2108, 14, 500, 61, 435, 485, 1179, 63, 10973, 63, 3902, 9, 288, 916, 1819, 14, 1450, 508, 298, 889, 1579, 582, 355, 892, 1301, 14, 740, 1547, 1179, 63, 10973, 63, 15947, 435, 1382, 59, 2108, 14, 928, 26, 2108, 14, 500, 61, 435, 485, 1179, 63, 10973, 63, 3902, 9, 288, 587, 26, 355, 367, 790, 12, 1139, 315, 1819, 14, 2987, 14, 1574, 1252, 1744, 837, 490, 327, 9630, 31570, 262, 9916, 4474, 490, 340, 790, 315, 1621, 1766, 10789, 948, 63, 8193, 63, 18166, 26, 717, 1819, 14, 2987, 59, 498, 61, 275, 3087, 490, 327, 799, 952, 18910, 30143, 490, 916, 790, 315, 9022, 63, 18166, 436, 1139, 365, 440, 488, 436, 298, 9554, 5424, 315, 485, 271, 287, 280, 30510, 63, 2975, 8, 637, 304, 717, 1819, 14, 2987, 59, 498, 61, 275, 298, 10254, 26, 2500, 2, 490, 587, 26, 717, 1980, 355, 892, 1301, 14, 740, 8, 3549, 63, 1450, 8, 2108, 430, 267, 587, 26, 288, 1318, 275, 1382, 59, 2108, 14, 928, 26, 2108, 14, 500, 61, 288, 340, 11788, 63, 3349, 436, 1318, 14, 1913, 342, 436, 440, 334, 505, 14, 2460, 6757, 17722, 531, 436, 1318, 14, 4130, 6739, 9579, 304, 355, 892, 1301, 14, 740, 1547, 1179, 63, 10973, 63, 15947, 435, 1318, 435, 485, 1179, 63, 10973, 63, 3902, 9, 288, 587, 26, 355, 892, 1301, 14, 740, 8, 505, 9, 339, 372, 6522, 904, 8, 18622, 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 ]
[ 272, 23169, 15250, 687, 4163, 339, 961, 859, 14185, 1006, 3411, 15250, 315, 376, 4163, 2213, 14, 199, 199, 624, 199, 646, 295, 199, 504, 10328, 321, 590, 14, 1360, 1606, 492, 20880, 1931, 12, 20880, 1931, 804, 12, 2198, 63, 1360, 199, 504, 308, 590, 3018, 14, 1208, 492, 3517, 1606, 63, 504, 63, 1310, 199, 504, 308, 590, 3018, 14, 28937, 492, 5518, 63, 1095, 63, 633, 199, 504, 1275, 11270, 492, 1050, 63, 1450, 1580, 199, 504, 1275, 1208, 492, 8437, 63, 1450, 199, 199, 5680, 31862, 9282, 17775, 874, 199, 3, 258, 12078, 78, 1133, 7962, 543, 18001, 8752, 315, 15750, 199, 3, 258, 12078, 78, 1133, 7962, 543, 3404, 4660, 18910, 30143, 199, 199, 19652, 10789, 948, 63, 8193, 63, 18166, 275, 1689, 265, 912, 401, 298, 265, 25477, 401, 298, 265, 4891, 401, 298, 265, 26469, 4891, 401, 1169, 298, 265, 573, 2972, 944, 401, 298, 265, 10544, 384, 401, 298, 265, 10544, 1883, 401, 1169, 298, 265, 10544, 1185, 401, 298, 265, 10544, 548, 401, 298, 265, 12283, 401, 1169, 298, 265, 3345, 300, 401, 298, 265, 498, 2915, 401, 298, 265, 498, 2110, 401, 1169, 298, 265, 498, 384, 401, 298, 265, 7275, 401, 298, 265, 3958, 401, 298, 265, 2416, 401, 1169, 298, 18128, 401, 298, 265, 705, 401, 298, 265, 5182, 25477, 531, 199, 199, 7639, 63, 18166, 275, 1689, 1287, 401, 298, 7451, 401, 298, 25171, 401, 298, 12334, 68, 401, 298, 600, 1095, 401, 355, 298, 576, 401, 298, 6399, 401, 298, 2809, 3257, 401, 298, 2913, 401, 298, 2164, 401, 298, 1180, 1130, 531, 199, 199, 1179, 63, 10484, 63, 23030, 63, 15947, 275, 3886, 17722, 5386, 4897, 3483, 701, 308, 590, 68, 306, 4335, 199, 1179, 63, 10484, 63, 23030, 63, 3902, 275, 3886, 17722, 1284, 4897, 3483, 701, 308, 590, 68, 306, 4335, 199, 199, 63, 1179, 63, 10973, 63, 15947, 275, 3886, 17722, 5386, 63, 305, 3349, 5424, 199, 63, 1179, 63, 10973, 63, 3902, 275, 7244, 500, 63, 305, 3349, 1553, 4335, 199, 63, 13630, 63, 907, 275, 295, 14, 2014, 480, 7997, 2961, 68, 11, 2736, 531, 421, 199, 318, 485, 271, 287, 280, 30510, 63, 2975, 8, 1662, 495, 304, 272, 408, 1155, 5862, 1006, 9045, 315, 314, 1824, 1253, 20262, 68, 11, 27, 701, 2399, 272, 2649, 7353, 14, 272, 408, 272, 372, 485, 13630, 63, 907, 14, 954, 8, 2734, 333, 26, 17742, 8, 442, 8, 77, 14, 2634, 3430, 16, 12884, 3002, 495, 9, 421, 199, 318, 3517, 20, 9340, 8, 1360, 1606, 12, 1300, 633, 29, 403, 304, 272, 408, 7306, 314, 1627, 3517, 2213, 367, 314, 11262, 14041, 339, 961, 9584, 3762, 12, 14185, 10554, 436, 14190, 9584, 282, 1300, 1166, 272, 408, 272, 3517, 1606, 275, 1050, 63, 1450, 1580, 8, 1360, 1606, 9, 272, 12364, 63, 1360, 275, 7039, 80, 3338, 8, 1360, 1606, 9, 272, 340, 1300, 633, 26, 267, 12364, 63, 1360, 275, 5518, 63, 1095, 63, 633, 8, 8275, 63, 1360, 12, 1300, 633, 9, 272, 372, 12364, 63, 1360, 421, 199, 318, 5536, 63, 1360, 8, 1310, 304, 272, 408, 12147, 83, 376, 3517, 2034, 687, 314, 1177, 14, 272, 408, 272, 372, 3517, 1606, 63, 504, 63, 1310, 8, 1310, 680, 2030, 421, 199, 318, 7039, 80, 3338, 8, 1301, 304, 272, 408, 6580, 15250, 315, 282, 3517, 1350, 1059, 14, 272, 408, 272, 4565, 275, 2198, 63, 1360, 8, 1301, 9, 272, 892, 1301, 275, 942, 272, 11788, 63, 3349, 275, 756, 272, 367, 1819, 315, 4565, 26, 267, 340, 1228, 8, 2108, 12, 20880, 1931, 304, 288, 340, 440, 11788, 63, 3349, 436, 1819, 14, 1450, 508, 298, 1579, 2, 436, 1819, 14, 1450, 63, 466, 508, 20880, 1931, 804, 14, 9935, 63, 6967, 26, 355, 892, 1301, 14, 740, 1547, 1179, 63, 10973, 63, 15947, 435, 1382, 59, 2108, 14, 928, 26, 2108, 14, 500, 61, 435, 485, 1179, 63, 10973, 63, 3902, 9, 355, 11788, 63, 3349, 275, 715, 288, 916, 1819, 14, 1450, 508, 298, 1579, 2, 436, 1819, 14, 1450, 63, 466, 508, 20880, 1931, 804, 14, 18219, 63, 6967, 26, 355, 340, 11788, 63, 3349, 26, 490, 11788, 63, 3349, 275, 756, 355, 892, 1301, 14, 740, 1547, 1179, 63, 10973, 63, 15947, 435, 1382, 59, 2108, 14, 928, 26, 2108, 14, 500, 61, 435, 485, 1179, 63, 10973, 63, 3902, 9, 288, 916, 1819, 14, 1450, 508, 298, 889, 1579, 582, 355, 892, 1301, 14, 740, 1547, 1179, 63, 10973, 63, 15947, 435, 1382, 59, 2108, 14, 928, 26, 2108, 14, 500, 61, 435, 485, 1179, 63, 10973, 63, 3902, 9, 288, 587, 26, 355, 367, 790, 12, 1139, 315, 1819, 14, 2987, 14, 1574, 1252, 1744, 837, 490, 327, 9630, 31570, 262, 9916, 4474, 490, 340, 790, 315, 1621, 1766, 10789, 948, 63, 8193, 63, 18166, 26, 717, 1819, 14, 2987, 59, 498, 61, 275, 3087, 490, 327, 799, 952, 18910, 30143, 490, 916, 790, 315, 9022, 63, 18166, 436, 1139, 365, 440, 488, 436, 298, 9554, 5424, 315, 485, 271, 287, 280, 30510, 63, 2975, 8, 637, 304, 717, 1819, 14, 2987, 59, 498, 61, 275, 298, 10254, 26, 2500, 2, 490, 587, 26, 717, 1980, 355, 892, 1301, 14, 740, 8, 3549, 63, 1450, 8, 2108, 430, 267, 587, 26, 288, 1318, 275, 1382, 59, 2108, 14, 928, 26, 2108, 14, 500, 61, 288, 340, 11788, 63, 3349, 436, 1318, 14, 1913, 342, 436, 440, 334, 505, 14, 2460, 6757, 17722, 531, 436, 1318, 14, 4130, 6739, 9579, 304, 355, 892, 1301, 14, 740, 1547, 1179, 63, 10973, 63, 15947, 435, 1318, 435, 485, 1179, 63, 10973, 63, 3902, 9, 288, 587, 26, 355, 892, 1301, 14, 740, 8, 505, 9, 339, 372, 6522, 904, 8, 18622, 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, 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,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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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
lowitty/server
libsDarwin/twisted/conch/ssh/userauth.py
5
26771
# -*- test-case-name: twisted.conch.test.test_userauth -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Implementation of the ssh-userauth service. Currently implemented authentication types are public-key and password. Maintainer: Paul Swartz """ import struct from twisted.conch import error, interfaces from twisted.conch.ssh import keys, transport, service from twisted.conch.ssh.common import NS, getNS from twisted.cred import credentials from twisted.cred.error import UnauthorizedLogin from twisted.internet import defer, reactor from twisted.python import failure, log class SSHUserAuthServer(service.SSHService): """ A service implementing the server side of the 'ssh-userauth' service. It is used to authenticate the user on the other side as being able to access this server. @ivar name: the name of this service: 'ssh-userauth' @type name: C{str} @ivar authenticatedWith: a list of authentication methods that have already been used. @type authenticatedWith: C{list} @ivar loginTimeout: the number of seconds we wait before disconnecting the user for taking too long to authenticate @type loginTimeout: C{int} @ivar attemptsBeforeDisconnect: the number of failed login attempts we allow before disconnecting. @type attemptsBeforeDisconnect: C{int} @ivar loginAttempts: the number of login attempts that have been made @type loginAttempts: C{int} @ivar passwordDelay: the number of seconds to delay when the user gives an incorrect password @type passwordDelay: C{int} @ivar interfaceToMethod: a C{dict} mapping credential interfaces to authentication methods. The server checks to see which of the cred interfaces have checkers and tells the client that those methods are valid for authentication. @type interfaceToMethod: C{dict} @ivar supportedAuthentications: A list of the supported authentication methods. @type supportedAuthentications: C{list} of C{str} @ivar user: the last username the client tried to authenticate with @type user: C{str} @ivar method: the current authentication method @type method: C{str} @ivar nextService: the service the user wants started after authentication has been completed. @type nextService: C{str} @ivar portal: the L{twisted.cred.portal.Portal} we are using for authentication @type portal: L{twisted.cred.portal.Portal} @ivar clock: an object with a callLater method. Stubbed out for testing. """ name = 'ssh-userauth' loginTimeout = 10 * 60 * 60 # 10 minutes before we disconnect them attemptsBeforeDisconnect = 20 # 20 login attempts before a disconnect passwordDelay = 1 # number of seconds to delay on a failed password clock = reactor interfaceToMethod = { credentials.ISSHPrivateKey : 'publickey', credentials.IUsernamePassword : 'password', } def serviceStarted(self): """ Called when the userauth service is started. Set up instance variables, check if we should allow password authentication (only allow if the outgoing connection is encrypted) and set up a login timeout. """ self.authenticatedWith = [] self.loginAttempts = 0 self.user = None self.nextService = None self.portal = self.transport.factory.portal self.supportedAuthentications = [] for i in self.portal.listCredentialsInterfaces(): if i in self.interfaceToMethod: self.supportedAuthentications.append(self.interfaceToMethod[i]) if not self.transport.isEncrypted('in'): # don't let us transport password in plaintext if 'password' in self.supportedAuthentications: self.supportedAuthentications.remove('password') self._cancelLoginTimeout = self.clock.callLater( self.loginTimeout, self.timeoutAuthentication) def serviceStopped(self): """ Called when the userauth service is stopped. Cancel the login timeout if it's still going. """ if self._cancelLoginTimeout: self._cancelLoginTimeout.cancel() self._cancelLoginTimeout = None def timeoutAuthentication(self): """ Called when the user has timed out on authentication. Disconnect with a DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE message. """ self._cancelLoginTimeout = None self.transport.sendDisconnect( transport.DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE, 'you took too long') def tryAuth(self, kind, user, data): """ Try to authenticate the user with the given method. Dispatches to a auth_* method. @param kind: the authentication method to try. @type kind: C{str} @param user: the username the client is authenticating with. @type user: C{str} @param data: authentication specific data sent by the client. @type data: C{str} @return: A Deferred called back if the method succeeded, or erred back if it failed. @rtype: C{defer.Deferred} """ log.msg('%s trying auth %s' % (user, kind)) if kind not in self.supportedAuthentications: return defer.fail( error.ConchError('unsupported authentication, failing')) kind = kind.replace('-', '_') f = getattr(self,'auth_%s'%kind, None) if f: ret = f(data) if not ret: return defer.fail( error.ConchError('%s return None instead of a Deferred' % kind)) else: return ret return defer.fail(error.ConchError('bad auth type: %s' % kind)) def ssh_USERAUTH_REQUEST(self, packet): """ The client has requested authentication. Payload:: string user string next service string method <authentication specific data> @type packet: C{str} """ user, nextService, method, rest = getNS(packet, 3) if user != self.user or nextService != self.nextService: self.authenticatedWith = [] # clear auth state self.user = user self.nextService = nextService self.method = method d = self.tryAuth(method, user, rest) if not d: self._ebBadAuth( failure.Failure(error.ConchError('auth returned none'))) return d.addCallback(self._cbFinishedAuth) d.addErrback(self._ebMaybeBadAuth) d.addErrback(self._ebBadAuth) return d def _cbFinishedAuth(self, (interface, avatar, logout)): """ The callback when user has successfully been authenticated. For a description of the arguments, see L{twisted.cred.portal.Portal.login}. We start the service requested by the user. """ self.transport.avatar = avatar self.transport.logoutFunction = logout service = self.transport.factory.getService(self.transport, self.nextService) if not service: raise error.ConchError('could not get next service: %s' % self.nextService) log.msg('%s authenticated with %s' % (self.user, self.method)) self.transport.sendPacket(MSG_USERAUTH_SUCCESS, '') self.transport.setService(service()) def _ebMaybeBadAuth(self, reason): """ An intermediate errback. If the reason is error.NotEnoughAuthentication, we send a MSG_USERAUTH_FAILURE, but with the partial success indicator set. @type reason: L{twisted.python.failure.Failure} """ reason.trap(error.NotEnoughAuthentication) self.transport.sendPacket(MSG_USERAUTH_FAILURE, NS(','.join(self.supportedAuthentications)) + '\xff') def _ebBadAuth(self, reason): """ The final errback in the authentication chain. If the reason is error.IgnoreAuthentication, we simply return; the authentication method has sent its own response. Otherwise, send a failure message and (if the method is not 'none') increment the number of login attempts. @type reason: L{twisted.python.failure.Failure} """ if reason.check(error.IgnoreAuthentication): return if self.method != 'none': log.msg('%s failed auth %s' % (self.user, self.method)) if reason.check(UnauthorizedLogin): log.msg('unauthorized login: %s' % reason.getErrorMessage()) elif reason.check(error.ConchError): log.msg('reason: %s' % reason.getErrorMessage()) else: log.msg(reason.getTraceback()) self.loginAttempts += 1 if self.loginAttempts > self.attemptsBeforeDisconnect: self.transport.sendDisconnect( transport.DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE, 'too many bad auths') return self.transport.sendPacket( MSG_USERAUTH_FAILURE, NS(','.join(self.supportedAuthentications)) + '\x00') def auth_publickey(self, packet): """ Public key authentication. Payload:: byte has signature string algorithm name string key blob [string signature] (if has signature is True) Create a SSHPublicKey credential and verify it using our portal. """ hasSig = ord(packet[0]) algName, blob, rest = getNS(packet[1:], 2) pubKey = keys.Key.fromString(blob) signature = hasSig and getNS(rest)[0] or None if hasSig: b = (NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) + NS(self.user) + NS(self.nextService) + NS('publickey') + chr(hasSig) + NS(pubKey.sshType()) + NS(blob)) c = credentials.SSHPrivateKey(self.user, algName, blob, b, signature) return self.portal.login(c, None, interfaces.IConchUser) else: c = credentials.SSHPrivateKey(self.user, algName, blob, None, None) return self.portal.login(c, None, interfaces.IConchUser).addErrback(self._ebCheckKey, packet[1:]) def _ebCheckKey(self, reason, packet): """ Called back if the user did not sent a signature. If reason is error.ValidPublicKey then this key is valid for the user to authenticate with. Send MSG_USERAUTH_PK_OK. """ reason.trap(error.ValidPublicKey) # if we make it here, it means that the publickey is valid self.transport.sendPacket(MSG_USERAUTH_PK_OK, packet) return failure.Failure(error.IgnoreAuthentication()) def auth_password(self, packet): """ Password authentication. Payload:: string password Make a UsernamePassword credential and verify it with our portal. """ password = getNS(packet[1:])[0] c = credentials.UsernamePassword(self.user, password) return self.portal.login(c, None, interfaces.IConchUser).addErrback( self._ebPassword) def _ebPassword(self, f): """ If the password is invalid, wait before sending the failure in order to delay brute-force password guessing. """ d = defer.Deferred() self.clock.callLater(self.passwordDelay, d.callback, f) return d class SSHUserAuthClient(service.SSHService): """ A service implementing the client side of 'ssh-userauth'. This service will try all authentication methods provided by the server, making callbacks for more information when necessary. @ivar name: the name of this service: 'ssh-userauth' @type name: C{str} @ivar preferredOrder: a list of authentication methods that should be used first, in order of preference, if supported by the server @type preferredOrder: C{list} @ivar user: the name of the user to authenticate as @type user: C{str} @ivar instance: the service to start after authentication has finished @type instance: L{service.SSHService} @ivar authenticatedWith: a list of strings of authentication methods we've tried @type authenticatedWith: C{list} of C{str} @ivar triedPublicKeys: a list of public key objects that we've tried to authenticate with @type triedPublicKeys: C{list} of L{Key} @ivar lastPublicKey: the last public key object we've tried to authenticate with @type lastPublicKey: L{Key} """ name = 'ssh-userauth' preferredOrder = ['publickey', 'password', 'keyboard-interactive'] def __init__(self, user, instance): self.user = user self.instance = instance def serviceStarted(self): self.authenticatedWith = [] self.triedPublicKeys = [] self.lastPublicKey = None self.askForAuth('none', '') def askForAuth(self, kind, extraData): """ Send a MSG_USERAUTH_REQUEST. @param kind: the authentication method to try. @type kind: C{str} @param extraData: method-specific data to go in the packet @type extraData: C{str} """ self.lastAuth = kind self.transport.sendPacket(MSG_USERAUTH_REQUEST, NS(self.user) + NS(self.instance.name) + NS(kind) + extraData) def tryAuth(self, kind): """ Dispatch to an authentication method. @param kind: the authentication method @type kind: C{str} """ kind = kind.replace('-', '_') log.msg('trying to auth with %s' % (kind,)) f = getattr(self,'auth_%s' % (kind,), None) if f: return f() def _ebAuth(self, ignored, *args): """ Generic callback for a failed authentication attempt. Respond by asking for the list of accepted methods (the 'none' method) """ self.askForAuth('none', '') def ssh_USERAUTH_SUCCESS(self, packet): """ We received a MSG_USERAUTH_SUCCESS. The server has accepted our authentication, so start the next service. """ self.transport.setService(self.instance) def ssh_USERAUTH_FAILURE(self, packet): """ We received a MSG_USERAUTH_FAILURE. Payload:: string methods byte partial success If partial success is C{True}, then the previous method succeeded but is not sufficient for authentication. C{methods} is a comma-separated list of accepted authentication methods. We sort the list of methods by their position in C{self.preferredOrder}, removing methods that have already succeeded. We then call C{self.tryAuth} with the most preferred method. @param packet: the L{MSG_USERAUTH_FAILURE} payload. @type packet: C{str} @return: a L{defer.Deferred} that will be callbacked with C{None} as soon as all authentication methods have been tried, or C{None} if no more authentication methods are available. @rtype: C{defer.Deferred} or C{None} """ canContinue, partial = getNS(packet) partial = ord(partial) if partial: self.authenticatedWith.append(self.lastAuth) def orderByPreference(meth): """ Invoked once per authentication method in order to extract a comparison key which is then used for sorting. @param meth: the authentication method. @type meth: C{str} @return: the comparison key for C{meth}. @rtype: C{int} """ if meth in self.preferredOrder: return self.preferredOrder.index(meth) else: # put the element at the end of the list. return len(self.preferredOrder) canContinue = sorted([meth for meth in canContinue.split(',') if meth not in self.authenticatedWith], key=orderByPreference) log.msg('can continue with: %s' % canContinue) return self._cbUserauthFailure(None, iter(canContinue)) def _cbUserauthFailure(self, result, iterator): if result: return try: method = iterator.next() except StopIteration: self.transport.sendDisconnect( transport.DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE, 'no more authentication methods available') else: d = defer.maybeDeferred(self.tryAuth, method) d.addCallback(self._cbUserauthFailure, iterator) return d def ssh_USERAUTH_PK_OK(self, packet): """ This message (number 60) can mean several different messages depending on the current authentication type. We dispatch to individual methods in order to handle this request. """ func = getattr(self, 'ssh_USERAUTH_PK_OK_%s' % self.lastAuth.replace('-', '_'), None) if func is not None: return func(packet) else: self.askForAuth('none', '') def ssh_USERAUTH_PK_OK_publickey(self, packet): """ This is MSG_USERAUTH_PK. Our public key is valid, so we create a signature and try to authenticate with it. """ publicKey = self.lastPublicKey b = (NS(self.transport.sessionID) + chr(MSG_USERAUTH_REQUEST) + NS(self.user) + NS(self.instance.name) + NS('publickey') + '\x01' + NS(publicKey.sshType()) + NS(publicKey.blob())) d = self.signData(publicKey, b) if not d: self.askForAuth('none', '') # this will fail, we'll move on return d.addCallback(self._cbSignedData) d.addErrback(self._ebAuth) def ssh_USERAUTH_PK_OK_password(self, packet): """ This is MSG_USERAUTH_PASSWD_CHANGEREQ. The password given has expired. We ask for an old password and a new password, then send both back to the server. """ prompt, language, rest = getNS(packet, 2) self._oldPass = self._newPass = None d = self.getPassword('Old Password: ') d = d.addCallbacks(self._setOldPass, self._ebAuth) d.addCallback(lambda ignored: self.getPassword(prompt)) d.addCallbacks(self._setNewPass, self._ebAuth) def ssh_USERAUTH_PK_OK_keyboard_interactive(self, packet): """ This is MSG_USERAUTH_INFO_RESPONSE. The server has sent us the questions it wants us to answer, so we ask the user and sent the responses. """ name, instruction, lang, data = getNS(packet, 3) numPrompts = struct.unpack('!L', data[:4])[0] data = data[4:] prompts = [] for i in range(numPrompts): prompt, data = getNS(data) echo = bool(ord(data[0])) data = data[1:] prompts.append((prompt, echo)) d = self.getGenericAnswers(name, instruction, prompts) d.addCallback(self._cbGenericAnswers) d.addErrback(self._ebAuth) def _cbSignedData(self, signedData): """ Called back out of self.signData with the signed data. Send the authentication request with the signature. @param signedData: the data signed by the user's private key. @type signedData: C{str} """ publicKey = self.lastPublicKey self.askForAuth('publickey', '\x01' + NS(publicKey.sshType()) + NS(publicKey.blob()) + NS(signedData)) def _setOldPass(self, op): """ Called back when we are choosing a new password. Simply store the old password for now. @param op: the old password as entered by the user @type op: C{str} """ self._oldPass = op def _setNewPass(self, np): """ Called back when we are choosing a new password. Get the old password and send the authentication message with both. @param np: the new password as entered by the user @type np: C{str} """ op = self._oldPass self._oldPass = None self.askForAuth('password', '\xff' + NS(op) + NS(np)) def _cbGenericAnswers(self, responses): """ Called back when we are finished answering keyboard-interactive questions. Send the info back to the server in a MSG_USERAUTH_INFO_RESPONSE. @param responses: a list of C{str} responses @type responses: C{list} """ data = struct.pack('!L', len(responses)) for r in responses: data += NS(r.encode('UTF8')) self.transport.sendPacket(MSG_USERAUTH_INFO_RESPONSE, data) def auth_publickey(self): """ Try to authenticate with a public key. Ask the user for a public key; if the user has one, send the request to the server and return True. Otherwise, return False. @rtype: C{bool} """ d = defer.maybeDeferred(self.getPublicKey) d.addBoth(self._cbGetPublicKey) return d def _cbGetPublicKey(self, publicKey): if not isinstance(publicKey, keys.Key): # failure or None publicKey = None if publicKey is not None: self.lastPublicKey = publicKey self.triedPublicKeys.append(publicKey) log.msg('using key of type %s' % publicKey.type()) self.askForAuth('publickey', '\x00' + NS(publicKey.sshType()) + NS(publicKey.blob())) return True else: return False def auth_password(self): """ Try to authenticate with a password. Ask the user for a password. If the user will return a password, return True. Otherwise, return False. @rtype: C{bool} """ d = self.getPassword() if d: d.addCallbacks(self._cbPassword, self._ebAuth) return True else: # returned None, don't do password auth return False def auth_keyboard_interactive(self): """ Try to authenticate with keyboard-interactive authentication. Send the request to the server and return True. @rtype: C{bool} """ log.msg('authing with keyboard-interactive') self.askForAuth('keyboard-interactive', NS('') + NS('')) return True def _cbPassword(self, password): """ Called back when the user gives a password. Send the request to the server. @param password: the password the user entered @type password: C{str} """ self.askForAuth('password', '\x00' + NS(password)) def signData(self, publicKey, signData): """ Sign the given data with the given public key. By default, this will call getPrivateKey to get the private key, then sign the data using Key.sign(). This method is factored out so that it can be overridden to use alternate methods, such as a key agent. @param publicKey: The public key object returned from L{getPublicKey} @type publicKey: L{keys.Key} @param signData: the data to be signed by the private key. @type signData: C{str} @return: a Deferred that's called back with the signature @rtype: L{defer.Deferred} """ key = self.getPrivateKey() if not key: return return key.addCallback(self._cbSignData, signData) def _cbSignData(self, privateKey, signData): """ Called back when the private key is returned. Sign the data and return the signature. @param privateKey: the private key object @type publicKey: L{keys.Key} @param signData: the data to be signed by the private key. @type signData: C{str} @return: the signature @rtype: C{str} """ return privateKey.sign(signData) def getPublicKey(self): """ Return a public key for the user. If no more public keys are available, return C{None}. This implementation always returns C{None}. Override it in a subclass to actually find and return a public key object. @rtype: L{Key} or L{NoneType} """ return None def getPrivateKey(self): """ Return a L{Deferred} that will be called back with the private key object corresponding to the last public key from getPublicKey(). If the private key is not available, errback on the Deferred. @rtype: L{Deferred} called back with L{Key} """ return defer.fail(NotImplementedError()) def getPassword(self, prompt = None): """ Return a L{Deferred} that will be called back with a password. prompt is a string to display for the password, or None for a generic 'user@hostname's password: '. @type prompt: C{str}/C{None} @rtype: L{defer.Deferred} """ return defer.fail(NotImplementedError()) def getGenericAnswers(self, name, instruction, prompts): """ Returns a L{Deferred} with the responses to the promopts. @param name: The name of the authentication currently in progress. @param instruction: Describes what the authentication wants. @param prompts: A list of (prompt, echo) pairs, where prompt is a string to display and echo is a boolean indicating whether the user's response should be echoed as they type it. """ return defer.fail(NotImplementedError()) MSG_USERAUTH_REQUEST = 50 MSG_USERAUTH_FAILURE = 51 MSG_USERAUTH_SUCCESS = 52 MSG_USERAUTH_BANNER = 53 MSG_USERAUTH_INFO_RESPONSE = 61 MSG_USERAUTH_PK_OK = 60 messages = {} for k, v in locals().items(): if k[:4]=='MSG_': messages[v] = k SSHUserAuthServer.protocolMessages = messages SSHUserAuthClient.protocolMessages = messages del messages del v # Doubles, not included in the protocols' mappings MSG_USERAUTH_PASSWD_CHANGEREQ = 60 MSG_USERAUTH_INFO_REQUEST = 60
mit
[ 3, 1882, 511, 13, 2546, 13, 354, 26, 7390, 14, 388, 335, 14, 396, 14, 396, 63, 751, 1178, 1882, 199, 3, 1898, 334, 67, 9, 17078, 8449, 26640, 14, 199, 3, 1666, 5113, 367, 2436, 14, 199, 199, 624, 199, 7921, 402, 314, 8635, 13, 751, 1178, 2435, 14, 199, 31499, 6366, 6299, 2943, 787, 4575, 13, 498, 436, 2505, 14, 199, 199, 11903, 8368, 281, 26, 28574, 16666, 28124, 199, 624, 199, 199, 646, 2702, 199, 504, 7390, 14, 388, 335, 492, 1125, 12, 8386, 199, 504, 7390, 14, 388, 335, 14, 5510, 492, 2883, 12, 7773, 12, 2435, 199, 504, 7390, 14, 388, 335, 14, 5510, 14, 2330, 492, 9380, 12, 664, 2709, 199, 504, 7390, 14, 18639, 492, 6235, 199, 504, 7390, 14, 18639, 14, 705, 492, 1910, 11497, 8880, 199, 504, 7390, 14, 4901, 492, 10133, 12, 9655, 199, 504, 7390, 14, 1548, 492, 5988, 12, 943, 4388, 199, 533, 12027, 1899, 2817, 3120, 8, 1364, 14, 13716, 3167, 304, 272, 408, 272, 437, 2435, 18234, 314, 1654, 5366, 402, 314, 283, 5510, 13, 751, 1178, 7, 2435, 14, 221, 2779, 272, 365, 1202, 370, 12895, 314, 922, 641, 314, 1163, 5366, 465, 3769, 7688, 370, 2879, 272, 642, 1654, 14, 339, 768, 7725, 536, 26, 314, 536, 402, 642, 2435, 26, 283, 5510, 13, 751, 1178, 7, 272, 768, 466, 536, 26, 445, 91, 495, 93, 272, 768, 7725, 15082, 3007, 26, 282, 769, 402, 6299, 3102, 626, 1172, 267, 2575, 2757, 1202, 14, 272, 768, 466, 15082, 3007, 26, 445, 91, 513, 93, 272, 768, 7725, 4676, 6372, 26, 314, 1329, 402, 4696, 781, 3618, 2544, 17639, 316, 267, 314, 922, 367, 16466, 4634, 1846, 370, 12895, 272, 768, 466, 4676, 6372, 26, 445, 91, 442, 93, 272, 768, 7725, 12454, 13569, 16761, 26, 314, 1329, 402, 3405, 4676, 12454, 781, 267, 2040, 2544, 17639, 316, 14, 272, 768, 466, 12454, 13569, 16761, 26, 445, 91, 442, 93, 272, 768, 7725, 4676, 15322, 1086, 26, 314, 1329, 402, 4676, 12454, 626, 1172, 2757, 6326, 272, 768, 466, 4676, 15322, 1086, 26, 445, 91, 442, 93, 272, 768, 7725, 2505, 10796, 26, 314, 1329, 402, 4696, 370, 7339, 1380, 314, 922, 10557, 267, 376, 8927, 2505, 272, 768, 466, 2505, 10796, 26, 445, 91, 442, 93, 272, 768, 7725, 3217, 1378, 3767, 26, 282, 445, 91, 807, 93, 4412, 16338, 8386, 370, 267, 6299, 3102, 14, 221, 710, 1654, 5920, 370, 1937, 1314, 402, 314, 267, 22314, 8386, 1172, 1104, 1192, 436, 26544, 314, 1890, 626, 5204, 3102, 267, 787, 1686, 367, 6299, 14, 272, 768, 466, 3217, 1378, 3767, 26, 445, 91, 807, 93, 272, 768, 7725, 3748, 2817, 2815, 1298, 26, 437, 769, 402, 314, 3748, 6299, 267, 3102, 14, 272, 768, 466, 3748, 2817, 2815, 1298, 26, 445, 91, 513, 93, 402, 445, 91, 495, 93, 272, 768, 7725, 922, 26, 314, 2061, 3434, 314, 1890, 16416, 370, 12895, 543, 272, 768, 466, 922, 26, 445, 91, 495, 93, 272, 768, 7725, 1083, 26, 314, 1453, 6299, 1083, 272, 768, 466, 1083, 26, 445, 91, 495, 93, 272, 768, 7725, 2163, 3167, 26, 314, 2435, 314, 922, 15061, 8239, 2410, 6299, 267, 965, 2757, 9709, 14, 272, 768, 466, 2163, 3167, 26, 445, 91, 495, 93, 272, 768, 7725, 18428, 26, 314, 491, 91, 12145, 14, 18639, 14, 8707, 14, 26708, 93, 781, 787, 1808, 367, 267, 6299, 272, 768, 466, 18428, 26, 491, 91, 12145, 14, 18639, 14, 8707, 14, 26708, 93, 272, 768, 7725, 12516, 26, 376, 909, 543, 282, 1240, 22028, 1083, 14, 221, 23429, 6123, 734, 367, 5343, 14, 272, 408, 2378, 536, 275, 283, 5510, 13, 751, 1178, 7, 272, 4676, 6372, 275, 1616, 627, 5212, 627, 5212, 272, 327, 1616, 9395, 2544, 781, 17639, 3062, 272, 12454, 13569, 16761, 275, 3388, 272, 327, 3388, 4676, 12454, 2544, 282, 17639, 272, 2505, 10796, 275, 413, 327, 1329, 402, 4696, 370, 7339, 641, 282, 3405, 2505, 272, 12516, 275, 9655, 272, 3217, 1378, 3767, 275, 469, 267, 6235, 14, 1311, 3234, 31757, 520, 283, 5645, 8442, 14655, 297, 267, 6235, 14, 41, 13355, 6139, 520, 283, 2060, 297, 272, 789, 2378, 347, 2435, 21031, 8, 277, 304, 267, 408, 267, 12295, 1380, 314, 922, 1178, 2435, 365, 8239, 14, 221, 2494, 1536, 1256, 267, 2860, 12, 1104, 340, 781, 1077, 2040, 2505, 6299, 334, 2118, 267, 2040, 340, 314, 21507, 1950, 365, 14862, 9, 436, 663, 1536, 282, 4676, 267, 2653, 14, 267, 408, 267, 291, 14, 12177, 3007, 275, 942, 267, 291, 14, 2886, 15322, 1086, 275, 378, 267, 291, 14, 751, 275, 488, 267, 291, 14, 2184, 3167, 275, 488, 267, 291, 14, 8707, 275, 291, 14, 5545, 14, 3702, 14, 8707, 398, 291, 14, 4946, 2817, 2815, 1298, 275, 942, 267, 367, 284, 315, 291, 14, 8707, 14, 513, 13428, 18680, 837, 288, 340, 284, 315, 291, 14, 3266, 1378, 3767, 26, 355, 291, 14, 4946, 2817, 2815, 1298, 14, 740, 8, 277, 14, 3266, 1378, 3767, 59, 73, 566, 398, 340, 440, 291, 14, 5545, 14, 374, 1327, 8274, 360, 262, 735, 288, 327, 2793, 1133, 4691, 2739, 7773, 2505, 315, 18577, 288, 340, 283, 2060, 7, 315, 291, 14, 4946, 2817, 2815, 1298, 26, 355, 291, 14, 4946, 2817, 2815, 1298, 14, 2168, 360, 2060, 358, 267, 291, 423, 6406, 8880, 6372, 275, 291, 14, 9597, 14, 1250, 22028, 8, 288, 291, 14, 2886, 6372, 12, 288, 291, 14, 2593, 10348, 9, 2378, 347, 2435, 28500, 8, 277, 304, 267, 408, 267, 12295, 1380, 314, 922, 1178, 2435, 365, 15248, 14, 221, 28374, 314, 4676, 2653, 267, 340, 652, 1159, 5139, 9995, 14, 267, 408, 267, 340, 291, 423, 6406, 8880, 6372, 26, 288, 291, 423, 6406, 8880, 6372, 14, 6406, 342, 288, 291, 423, 6406, 8880, 6372, 275, 488, 2378, 347, 2653, 10348, 8, 277, 304, 267, 408, 267, 12295, 1380, 314, 922, 965, 18590, 734, 641, 6299, 14, 221, 5289, 2242, 267, 543, 282, 7587, 14657, 63, 2826, 63, 45, 5788, 63, 5580, 63, 18383, 63, 17377, 1245, 14, 267, 408, 267, 291, 423, 6406, 8880, 6372, 275, 488, 267, 291, 14, 5545, 14 ]
[ 1882, 511, 13, 2546, 13, 354, 26, 7390, 14, 388, 335, 14, 396, 14, 396, 63, 751, 1178, 1882, 199, 3, 1898, 334, 67, 9, 17078, 8449, 26640, 14, 199, 3, 1666, 5113, 367, 2436, 14, 199, 199, 624, 199, 7921, 402, 314, 8635, 13, 751, 1178, 2435, 14, 199, 31499, 6366, 6299, 2943, 787, 4575, 13, 498, 436, 2505, 14, 199, 199, 11903, 8368, 281, 26, 28574, 16666, 28124, 199, 624, 199, 199, 646, 2702, 199, 504, 7390, 14, 388, 335, 492, 1125, 12, 8386, 199, 504, 7390, 14, 388, 335, 14, 5510, 492, 2883, 12, 7773, 12, 2435, 199, 504, 7390, 14, 388, 335, 14, 5510, 14, 2330, 492, 9380, 12, 664, 2709, 199, 504, 7390, 14, 18639, 492, 6235, 199, 504, 7390, 14, 18639, 14, 705, 492, 1910, 11497, 8880, 199, 504, 7390, 14, 4901, 492, 10133, 12, 9655, 199, 504, 7390, 14, 1548, 492, 5988, 12, 943, 4388, 199, 533, 12027, 1899, 2817, 3120, 8, 1364, 14, 13716, 3167, 304, 272, 408, 272, 437, 2435, 18234, 314, 1654, 5366, 402, 314, 283, 5510, 13, 751, 1178, 7, 2435, 14, 221, 2779, 272, 365, 1202, 370, 12895, 314, 922, 641, 314, 1163, 5366, 465, 3769, 7688, 370, 2879, 272, 642, 1654, 14, 339, 768, 7725, 536, 26, 314, 536, 402, 642, 2435, 26, 283, 5510, 13, 751, 1178, 7, 272, 768, 466, 536, 26, 445, 91, 495, 93, 272, 768, 7725, 15082, 3007, 26, 282, 769, 402, 6299, 3102, 626, 1172, 267, 2575, 2757, 1202, 14, 272, 768, 466, 15082, 3007, 26, 445, 91, 513, 93, 272, 768, 7725, 4676, 6372, 26, 314, 1329, 402, 4696, 781, 3618, 2544, 17639, 316, 267, 314, 922, 367, 16466, 4634, 1846, 370, 12895, 272, 768, 466, 4676, 6372, 26, 445, 91, 442, 93, 272, 768, 7725, 12454, 13569, 16761, 26, 314, 1329, 402, 3405, 4676, 12454, 781, 267, 2040, 2544, 17639, 316, 14, 272, 768, 466, 12454, 13569, 16761, 26, 445, 91, 442, 93, 272, 768, 7725, 4676, 15322, 1086, 26, 314, 1329, 402, 4676, 12454, 626, 1172, 2757, 6326, 272, 768, 466, 4676, 15322, 1086, 26, 445, 91, 442, 93, 272, 768, 7725, 2505, 10796, 26, 314, 1329, 402, 4696, 370, 7339, 1380, 314, 922, 10557, 267, 376, 8927, 2505, 272, 768, 466, 2505, 10796, 26, 445, 91, 442, 93, 272, 768, 7725, 3217, 1378, 3767, 26, 282, 445, 91, 807, 93, 4412, 16338, 8386, 370, 267, 6299, 3102, 14, 221, 710, 1654, 5920, 370, 1937, 1314, 402, 314, 267, 22314, 8386, 1172, 1104, 1192, 436, 26544, 314, 1890, 626, 5204, 3102, 267, 787, 1686, 367, 6299, 14, 272, 768, 466, 3217, 1378, 3767, 26, 445, 91, 807, 93, 272, 768, 7725, 3748, 2817, 2815, 1298, 26, 437, 769, 402, 314, 3748, 6299, 267, 3102, 14, 272, 768, 466, 3748, 2817, 2815, 1298, 26, 445, 91, 513, 93, 402, 445, 91, 495, 93, 272, 768, 7725, 922, 26, 314, 2061, 3434, 314, 1890, 16416, 370, 12895, 543, 272, 768, 466, 922, 26, 445, 91, 495, 93, 272, 768, 7725, 1083, 26, 314, 1453, 6299, 1083, 272, 768, 466, 1083, 26, 445, 91, 495, 93, 272, 768, 7725, 2163, 3167, 26, 314, 2435, 314, 922, 15061, 8239, 2410, 6299, 267, 965, 2757, 9709, 14, 272, 768, 466, 2163, 3167, 26, 445, 91, 495, 93, 272, 768, 7725, 18428, 26, 314, 491, 91, 12145, 14, 18639, 14, 8707, 14, 26708, 93, 781, 787, 1808, 367, 267, 6299, 272, 768, 466, 18428, 26, 491, 91, 12145, 14, 18639, 14, 8707, 14, 26708, 93, 272, 768, 7725, 12516, 26, 376, 909, 543, 282, 1240, 22028, 1083, 14, 221, 23429, 6123, 734, 367, 5343, 14, 272, 408, 2378, 536, 275, 283, 5510, 13, 751, 1178, 7, 272, 4676, 6372, 275, 1616, 627, 5212, 627, 5212, 272, 327, 1616, 9395, 2544, 781, 17639, 3062, 272, 12454, 13569, 16761, 275, 3388, 272, 327, 3388, 4676, 12454, 2544, 282, 17639, 272, 2505, 10796, 275, 413, 327, 1329, 402, 4696, 370, 7339, 641, 282, 3405, 2505, 272, 12516, 275, 9655, 272, 3217, 1378, 3767, 275, 469, 267, 6235, 14, 1311, 3234, 31757, 520, 283, 5645, 8442, 14655, 297, 267, 6235, 14, 41, 13355, 6139, 520, 283, 2060, 297, 272, 789, 2378, 347, 2435, 21031, 8, 277, 304, 267, 408, 267, 12295, 1380, 314, 922, 1178, 2435, 365, 8239, 14, 221, 2494, 1536, 1256, 267, 2860, 12, 1104, 340, 781, 1077, 2040, 2505, 6299, 334, 2118, 267, 2040, 340, 314, 21507, 1950, 365, 14862, 9, 436, 663, 1536, 282, 4676, 267, 2653, 14, 267, 408, 267, 291, 14, 12177, 3007, 275, 942, 267, 291, 14, 2886, 15322, 1086, 275, 378, 267, 291, 14, 751, 275, 488, 267, 291, 14, 2184, 3167, 275, 488, 267, 291, 14, 8707, 275, 291, 14, 5545, 14, 3702, 14, 8707, 398, 291, 14, 4946, 2817, 2815, 1298, 275, 942, 267, 367, 284, 315, 291, 14, 8707, 14, 513, 13428, 18680, 837, 288, 340, 284, 315, 291, 14, 3266, 1378, 3767, 26, 355, 291, 14, 4946, 2817, 2815, 1298, 14, 740, 8, 277, 14, 3266, 1378, 3767, 59, 73, 566, 398, 340, 440, 291, 14, 5545, 14, 374, 1327, 8274, 360, 262, 735, 288, 327, 2793, 1133, 4691, 2739, 7773, 2505, 315, 18577, 288, 340, 283, 2060, 7, 315, 291, 14, 4946, 2817, 2815, 1298, 26, 355, 291, 14, 4946, 2817, 2815, 1298, 14, 2168, 360, 2060, 358, 267, 291, 423, 6406, 8880, 6372, 275, 291, 14, 9597, 14, 1250, 22028, 8, 288, 291, 14, 2886, 6372, 12, 288, 291, 14, 2593, 10348, 9, 2378, 347, 2435, 28500, 8, 277, 304, 267, 408, 267, 12295, 1380, 314, 922, 1178, 2435, 365, 15248, 14, 221, 28374, 314, 4676, 2653, 267, 340, 652, 1159, 5139, 9995, 14, 267, 408, 267, 340, 291, 423, 6406, 8880, 6372, 26, 288, 291, 423, 6406, 8880, 6372, 14, 6406, 342, 288, 291, 423, 6406, 8880, 6372, 275, 488, 2378, 347, 2653, 10348, 8, 277, 304, 267, 408, 267, 12295, 1380, 314, 922, 965, 18590, 734, 641, 6299, 14, 221, 5289, 2242, 267, 543, 282, 7587, 14657, 63, 2826, 63, 45, 5788, 63, 5580, 63, 18383, 63, 17377, 1245, 14, 267, 408, 267, 291, 423, 6406, 8880, 6372, 275, 488, 267, 291, 14, 5545, 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,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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 ]
stevereyes01/pycbc
pycbc/population/rates_functions.py
11
15169
""" A set of helper functions for evaluating rates. """ from scipy import integrate, optimize import numpy as np, h5py from numpy import log import scipy.stats as ss import bisect from pycbc.conversions import mchirp_from_mass1_mass2 def process_full_data(fname, rhomin, mass1, mass2, lo_mchirp, hi_mchirp): """Read the zero-lag and time-lag triggers identified by templates in a specified range of chirp mass. Parameters ---------- hdfile: File that stores all the triggers rhomin: float Minimum value of SNR threhold (will need including ifar) mass1: array First mass of the waveform in the template bank mass2: array Second mass of the waveform in the template bank lo_mchirp: float Minimum chirp mass for the template hi_mchirp: float Maximum chirp mass for the template Returns ------- dictionary containing foreground triggers and background information """ with h5py.File(fname, 'r') as bulk: id_bkg = bulk['background_exc/template_id'][:] id_fg = bulk['foreground/template_id'][:] mchirp_bkg = mchirp_from_mass1_mass2(mass1[id_bkg], mass2[id_bkg]) bound = np.sign((mchirp_bkg - lo_mchirp) * (hi_mchirp - mchirp_bkg)) idx_bkg = np.where(bound == 1) mchirp_fg = mchirp_from_mass1_mass2(mass1[id_fg], mass2[id_fg]) bound = np.sign((mchirp_fg - lo_mchirp) * (hi_mchirp - mchirp_fg)) idx_fg = np.where(bound == 1) zerolagstat = bulk['foreground/stat'][:][idx_fg] cstat_back_exc = bulk['background_exc/stat'][:][idx_bkg] dec_factors = bulk['background_exc/decimation_factor'][:][idx_bkg] return {'zerolagstat': zerolagstat[zerolagstat > rhomin], 'dec_factors': dec_factors[cstat_back_exc > rhomin], 'cstat_back_exc': cstat_back_exc[cstat_back_exc > rhomin]} def save_bkg_falloff(fname_statmap, fname_bank, path, rhomin, lo_mchirp, hi_mchirp): ''' Read the STATMAP files to derive snr falloff for the background events. Save the output to a txt file Bank file is also provided to restrict triggers to BBH templates. Parameters ---------- fname_statmap: string STATMAP file containing trigger information fname_bank: string File name of the template bank path: string Destination where txt file is saved rhomin: float Minimum value of SNR threhold (will need including ifar) lo_mchirp: float Minimum chirp mass for the template hi_mchirp: float Maximum chirp mass for template ''' with h5py.File(fname_bank, 'r') as bulk: mass1_bank = bulk['mass1'][:] mass2_bank = bulk['mass2'][:] full_data = process_full_data(fname_statmap, rhomin, mass1_bank, mass2_bank, lo_mchirp, hi_mchirp) max_bg_stat = np.max(full_data['cstat_back_exc']) bg_bins = np.linspace(rhomin, max_bg_stat, 76) bg_counts = np.histogram(full_data['cstat_back_exc'], weights=full_data['dec_factors'], bins=bg_bins)[0] zerolagstat = full_data['zerolagstat'] coincs = zerolagstat[zerolagstat >= rhomin] bkg = (bg_bins[:-1], bg_bins[1:], bg_counts) return bkg, coincs def log_rho_bg(trigs, bins, counts): ''' Calculate the log of background fall-off Parameters ---------- trigs: array SNR values of all the triggers bins: string bins for histogrammed triggers path: string counts for histogrammed triggers Returns ------- array ''' trigs = np.atleast_1d(trigs) N = sum(counts) assert np.all(trigs >= np.min(bins)), \ 'Trigger SNR values cannot all be below the lowest bin limit!' # If there are any triggers that are louder than the max bin, put one # fictitious count in a bin that extends from the limits of the slide # triggers out to the loudest trigger. # If there is no counts for a foreground trigger put a fictitious count # in the background bin if np.any(trigs >= np.max(bins)): N = N + 1 #log_plimit = -np.log(N) - np.log(np.max(trigs) - bins[-1]) CHECK IT log_rhos = [] for t in trigs: if t >= np.max(bins): log_rhos.append(-log(N)-log(np.max(trigs) - bins[-1])) else: i = bisect.bisect(bins, t) - 1 if counts[i] == 0: counts[i] = 1 log_rhos.append(log(counts[i]) - log(bins[i+1] - bins[i]) - log(N)) return np.array(log_rhos) def log_rho_fgmc(t, injstats, bins): counts, bins = np.histogram(injstats, bins) N = sum(counts) dens = counts / np.diff(bins) / float(N) assert np.min(t) >= np.min(bins) assert np.max(t) < np.max(bins) tinds = np.searchsorted(bins, t) - 1 return log(dens[tinds]) def fgmc(log_fg_ratios, mu_log_vt, sigma_log_vt, Rf, maxfg): ''' Function to fit the likelihood Fixme ''' Lb = np.random.uniform(0., maxfg, len(Rf)) pquit = 0 while pquit < 0.1: # quit when the posterior on Lf is very close to its prior nsamp = len(Lb) Rf_sel = np.random.choice(Rf, nsamp) vt = np.random.lognormal(mu_log_vt, sigma_log_vt, len(Rf_sel)) Lf = Rf_sel * vt log_Lf, log_Lb = log(Lf), log(Lb) plR = 0 for lfr in log_fg_ratios: plR += np.logaddexp(lfr + log_Lf, log_Lb) plR -= (Lf + Lb) plRn = plR - max(plR) idx = np.exp(plRn) > np.random.random(len(plRn)) pquit = ss.stats.ks_2samp(Lb, Lb[idx])[1] Lb = Lb[idx] return Rf_sel[idx], Lf[idx], Lb def _optm(x, alpha, mu, sigma): '''Return probability density of skew-lognormal See scipy.optimize.curve_fit ''' return ss.skewnorm.pdf(x, alpha, mu, sigma) def fit(R): ''' Fit skew - lognormal to the rate samples achived from a prior analysis Parameters ---------- R: array Rate samples Returns ------- ff[0]: float The skewness ff[1]: float The mean ff[2]: float The standard deviation ''' lR = np.log(R) mu_norm, sigma_norm = np.mean(lR), np.std(lR) xs = np.linspace(min(lR), max(lR), 200) kde = ss.gaussian_kde(lR) pxs = kde(xs) # Initial guess has been taken as the mean and std-dev of the data # And a guess assuming small skewness ff = optimize.curve_fit(_optm, xs, pxs, p0 = [0.1, mu_norm, sigma_norm])[0] return ff[0], ff[1], ff[2] def skew_lognormal_samples(alpha, mu, sigma, minrp, maxrp): ''' Returns a large number of Skew lognormal samples Parameters ---------- alpha: float Skewness of the distribution mu: float Mean of the distribution sigma: float Scale of the distribution minrp: float Minimum value for the samples maxrp: float Maximum value for the samples Returns ------- Rfs: array Large number of samples (may need fixing) ''' nsamp = 100000000 lRu = np.random.uniform(minrp, maxrp, nsamp) plRu = ss.skewnorm.pdf(lRu, alpha, mu, sigma) rndn = np.random.random(nsamp) maxp = max(plRu) idx = np.where(plRu/maxp > rndn) log_Rf = lRu[idx] Rfs = np.exp(log_Rf) return Rfs # The flat in log and power-law mass distribution models # # PDF for the two canonical models plus flat in mass model def prob_lnm(m1, m2, s1z, s2z, **kwargs): ''' Return probability density for uniform in log Parameters ---------- m1: array Component masses 1 m2: array Component masses 2 s1z: array Aligned spin 1(Not in use currently) s2z: Aligned spin 2(Not in use currently) **kwargs: string Keyword arguments as model parameters Returns ------- p_m1_m2: array The probability density for m1, m2 pair ''' min_mass = kwargs.get('min_mass', 5.) max_mass = kwargs.get('max_mass', 95.) max_mtotal = min_mass + max_mass m1, m2 = np.array(m1), np.array(m2) C_lnm = integrate.quad(lambda x: (log(max_mtotal - x) - log(min_mass))/x, min_mass, max_mass)[0] xx = np.minimum(m1, m2) m1 = np.maximum(m1, m2) m2 = xx bound = np.sign(max_mtotal - m1 - m2) bound += np.sign(max_mass - m1) * np.sign(m2 - min_mass) idx = np.where(bound != 2) p_m1_m2 = (1/C_lnm)*(1./m1)*(1./m2) p_m1_m2[idx] = 0 return p_m1_m2 def prob_imf(m1, m2, s1z, s2z, **kwargs): ''' Return probability density for power-law Parameters ---------- m1: array Component masses 1 m2: array Component masses 2 s1z: array Aligned spin 1(Not in use currently) s2z: Aligned spin 2(Not in use currently) **kwargs: string Keyword arguments as model parameters Returns ------- p_m1_m2: array the probability density for m1, m2 pair ''' min_mass = kwargs.get('min_mass', 5.) max_mass = kwargs.get('max_mass', 95.) alpha = kwargs.get('alpha', -2.35) max_mtotal = min_mass + max_mass m1, m2 = np.array(m1), np.array(m2) C_imf = max_mass**(alpha + 1)/(alpha + 1) C_imf -= min_mass**(alpha + 1)/(alpha + 1) xx = np.minimum(m1, m2) m1 = np.maximum(m1, m2) m2 = xx bound = np.sign(max_mtotal - m1 - m2) bound += np.sign(max_mass - m1) * np.sign(m2 - min_mass) idx = np.where(bound != 2) p_m1_m2 = np.zeros_like(m1) idx = np.where(m1 <= max_mtotal/2.) p_m1_m2[idx] = (1./C_imf) * m1[idx]**alpha /(m1[idx] - min_mass) idx = np.where(m1 > max_mtotal/2.) p_m1_m2[idx] = (1./C_imf) * m1[idx]**alpha /(max_mass - m1[idx]) p_m1_m2[idx] = 0 return p_m1_m2/2. def prob_flat(m1, m2, s1z, s2z, **kwargs): ''' Return probability density for uniform in component mass Parameters ---------- m1: array Component masses 1 m2: array Component masses 2 s1z: array Aligned spin 1 (not in use currently) s2z: Aligned spin 2 (not in use currently) **kwargs: string Keyword arguments as model parameters Returns ------- p_m1_m2: array the probability density for m1, m2 pair ''' min_mass = kwargs.get('min_mass', 1.) max_mass = kwargs.get('max_mass', 2.) bound = np.sign(m1 - m2) bound += np.sign(max_mass - m1) * np.sign(m2 - min_mass) idx = np.where(bound != 2) p_m1_m2 = 2. / (max_mass - min_mass)**2 p_m1_m2[idx] = 0 return p_m1_m2 # Generate samples for the two canonical models plus flat in mass model def draw_imf_samples(**kwargs): ''' Draw samples for power-law model Parameters ---------- **kwargs: string Keyword arguments as model parameters and number of samples Returns ------- array The first mass array The second mass ''' alpha_salpeter = kwargs.get('alpha', -2.35) nsamples = kwargs.get('nsamples', 1) min_mass = kwargs.get('min_mass', 5.) max_mass = kwargs.get('max_mass', 95.) max_mtotal = min_mass + max_mass a = (max_mass/min_mass)**(alpha_salpeter + 1.0) - 1.0 beta = 1.0 / (alpha_salpeter + 1.0) k = nsamples * int(1.5 + log(1 + 100./nsamples)) aa = min_mass * (1.0 + a * np.random.random(k))**beta bb = np.random.uniform(min_mass, aa, k) idx = np.where(aa + bb < max_mtotal) m1, m2 = (np.maximum(aa, bb))[idx], (np.minimum(aa, bb))[idx] return np.resize(m1, nsamples), np.resize(m2, nsamples) def draw_lnm_samples(**kwargs): ''' Draw samples for uniform-in-log model Parameters ---------- **kwargs: string Keyword arguments as model parameters and number of samples Returns ------- array The first mass array The second mass ''' #PDF doesnt match with sampler nsamples = kwargs.get('nsamples', 1) min_mass = kwargs.get('min_mass', 5.) max_mass = kwargs.get('max_mass', 95.) max_mtotal = min_mass + max_mass lnmmin = log(min_mass) lnmmax = log(max_mass) k = nsamples * int(1.5 + log(1 + 100./nsamples)) aa = np.exp(np.random.uniform(lnmmin, lnmmax, k)) bb = np.exp(np.random.uniform(lnmmin, lnmmax, k)) idx = np.where(aa + bb < max_mtotal) m1, m2 = (np.maximum(aa, bb))[idx], (np.minimum(aa, bb))[idx] return np.resize(m1, nsamples), np.resize(m2, nsamples) def draw_flat_samples(**kwargs): ''' Draw samples for uniform in mass Parameters ---------- **kwargs: string Keyword arguments as model parameters and number of samples Returns ------- array The first mass array The second mass ''' #PDF doesnt match with sampler nsamples = kwargs.get('nsamples', 1) min_mass = kwargs.get('min_mass', 1.) max_mass = kwargs.get('max_mass', 2.) m1 = np.random.uniform(min_mass, max_mass, nsamples) m2 = np.random.uniform(min_mass, max_mass, nsamples) return np.maximum(m1, m2), np.minimum(m1, m2) # Functions to generate chirp mass samples for the two canonical models def mchirp_sampler_lnm(**kwargs): ''' Draw chirp mass samples for uniform-in-log model Parameters ---------- **kwargs: string Keyword arguments as model parameters and number of samples Returns ------- mchirp-astro: array The chirp mass samples for the population ''' m1, m2 = draw_lnm_samples(**kwargs) mchirp_astro = mchirp_from_mass1_mass2(m1, m2) return mchirp_astro def mchirp_sampler_imf(**kwargs): ''' Draw chirp mass samples for power-law model Parameters ---------- **kwargs: string Keyword arguments as model parameters and number of samples Returns ------- mchirp-astro: array The chirp mass samples for the population ''' m1, m2 = draw_imf_samples(**kwargs) mchirp_astro = mchirp_from_mass1_mass2(m1, m2) return mchirp_astro def mchirp_sampler_flat(**kwargs): ''' Draw chirp mass samples for flat in mass model Parameters ---------- **kwargs: string Keyword arguments as model parameters and number of samples Returns ------- mchirp-astro: array The chirp mass samples for the population ''' m1, m2 = draw_flat_samples(**kwargs) mchirp_astro = mchirp_from_mass1_mass2(m1, m2) return mchirp_astro
gpl-3.0
[ 624, 199, 33, 663, 402, 5922, 3423, 367, 27083, 24434, 14, 199, 624, 199, 199, 504, 7026, 492, 21494, 12, 13497, 199, 646, 2680, 465, 980, 12, 394, 21, 647, 199, 504, 2680, 492, 943, 199, 646, 7026, 14, 3200, 465, 10110, 199, 199, 646, 19063, 199, 504, 1134, 19279, 14, 388, 6234, 492, 333, 335, 723, 80, 63, 504, 63, 11535, 17, 63, 11535, 18, 199, 199, 318, 2112, 63, 2861, 63, 576, 8, 5252, 12, 17908, 827, 12, 12250, 17, 12, 12250, 18, 12, 560, 63, 77, 335, 723, 80, 12, 13759, 63, 77, 335, 723, 80, 304, 272, 408, 3284, 314, 4697, 13, 1823, 436, 900, 13, 1823, 18899, 15836, 701, 7009, 315, 2126, 282, 2013, 1425, 402, 682, 723, 80, 12250, 14, 10817, 3897, 2126, 4143, 2126, 18733, 493, 26, 1598, 3814, 626, 14086, 1006, 314, 18899, 2126, 17908, 827, 26, 2069, 1598, 22466, 574, 402, 428, 17774, 294, 264, 12239, 334, 14117, 1929, 5893, 340, 285, 9, 2126, 12250, 17, 26, 1625, 1598, 7758, 12250, 402, 314, 12204, 964, 315, 314, 1978, 16297, 2126, 12250, 18, 26, 1625, 1598, 16707, 12250, 402, 314, 12204, 964, 315, 314, 1978, 16297, 2126, 560, 63, 77, 335, 723, 80, 26, 2069, 1598, 22466, 682, 723, 80, 12250, 367, 314, 1978, 2126, 13759, 63, 77, 335, 723, 80, 26, 2069, 1598, 14212, 682, 723, 80, 12250, 367, 314, 1978, 10817, 1803, 2126, 5514, 2126, 2600, 1598, 3035, 24470, 18899, 436, 8020, 2556, 272, 408, 272, 543, 394, 21, 647, 14, 1173, 8, 5252, 12, 283, 82, 358, 465, 13137, 26, 398, 1305, 63, 66, 9761, 275, 13137, 459, 7451, 63, 2804, 15, 1160, 63, 344, 418, 5873, 267, 1305, 63, 9681, 275, 13137, 459, 23801, 15, 1160, 63, 344, 418, 5873, 398, 333, 335, 723, 80, 63, 66, 9761, 275, 333, 335, 723, 80, 63, 504, 63, 11535, 17, 63, 11535, 18, 8, 11535, 17, 59, 344, 63, 66, 9761, 467, 12250, 18, 59, 344, 63, 66, 9761, 566, 267, 3914, 275, 980, 14, 1037, 1332, 77, 335, 723, 80, 63, 66, 9761, 446, 560, 63, 77, 335, 723, 80, 9, 627, 334, 5812, 63, 77, 335, 723, 80, 446, 333, 335, 723, 80, 63, 66, 9761, 430, 267, 4280, 63, 66, 9761, 275, 980, 14, 4509, 8, 3556, 508, 413, 9, 267, 333, 335, 723, 80, 63, 9681, 275, 333, 335, 723, 80, 63, 504, 63, 11535, 17, 63, 11535, 18, 8, 11535, 17, 59, 344, 63, 9681, 467, 12250, 18, 59, 344, 63, 9681, 566, 267, 3914, 275, 980, 14, 1037, 1332, 77, 335, 723, 80, 63, 9681, 446, 560, 63, 77, 335, 723, 80, 9, 627, 334, 5812, 63, 77, 335, 723, 80, 446, 333, 335, 723, 80, 63, 9681, 430, 267, 4280, 63, 9681, 275, 980, 14, 4509, 8, 3556, 508, 413, 9, 398, 8043, 393, 643, 3736, 275, 13137, 459, 23801, 15, 3736, 418, 1491, 1527, 2996, 63, 9681, 61, 267, 286, 3736, 63, 894, 63, 2804, 275, 13137, 459, 7451, 63, 2804, 15, 3736, 418, 1491, 1527, 2996, 63, 66, 9761, 61, 267, 9700, 63, 16125, 275, 13137, 459, 7451, 63, 2804, 15, 22612, 1615, 63, 4778, 418, 1491, 1527, 2996, 63, 66, 9761, 61, 339, 372, 791, 2282, 393, 643, 3736, 356, 8043, 393, 643, 3736, 59, 2282, 393, 643, 3736, 690, 17908, 827, 467, 1779, 283, 7778, 63, 16125, 356, 9700, 63, 16125, 59, 67, 3736, 63, 894, 63, 2804, 690, 17908, 827, 467, 1779, 283, 67, 3736, 63, 894, 63, 2804, 356, 286, 3736, 63, 894, 63, 2804, 59, 67, 3736, 63, 894, 63, 2804, 690, 17908, 827, 9420, 421, 199, 318, 3354, 63, 66, 9761, 63, 70, 279, 320, 556, 8, 5252, 63, 3736, 1130, 12, 6748, 63, 9860, 12, 931, 12, 17908, 827, 12, 560, 63, 77, 335, 723, 80, 12, 13759, 63, 77, 335, 723, 80, 304, 272, 1449, 5574, 314, 13146, 5443, 1584, 370, 23519, 6895, 82, 289, 279, 320, 556, 367, 314, 8020, 4474, 14, 267, 11063, 314, 1072, 370, 282, 9444, 570, 267, 28721, 570, 365, 2597, 2741, 370, 18152, 18899, 370, 699, 29931, 7009, 14, 398, 3897, 267, 4143, 267, 6748, 63, 3736, 1130, 26, 1059, 2049, 13146, 5443, 570, 3035, 6804, 2556, 267, 6748, 63, 9860, 26, 1059, 2049, 3814, 536, 402, 314, 1978, 16297, 267, 931, 26, 1059, 2049, 28505, 2382, 9444, 570, 365, 6290, 267, 17908, 827, 26, 2069, 2049, 22466, 574, 402, 428, 17774, 294, 264, 12239, 334, 14117, 1929, 5893, 340, 285, 9, 267, 560, 63, 77, 335, 723, 80, 26, 2069, 2049, 22466, 682, 723, 80, 12250, 367, 314, 1978, 267, 13759, 63, 77, 335, 723, 80, 26, 2069, 2049, 14212, 682, 723, 80, 12250, 367, 1978, 272, 1449, 339, 543, 394, 21, 647, 14, 1173, 8, 5252, 63, 9860, 12, 283, 82, 358, 465, 13137, 26, 267, 12250, 17, 63, 9860, 275, 13137, 459, 11535, 17, 418, 5873, 267, 12250, 18, 63, 9860, 275, 13137, 459, 11535, 18, 418, 5873, 267, 2615, 63, 576, 275, 2112, 63, 2861, 63, 576, 8, 5252, 63, 3736, 1130, 12, 17908, 827, 12, 2574, 12250, 17, 63, 9860, 12, 12250, 18, 63, 9860, 12, 560, 63, 77, 335, 723, 80, 12, 13759, 63, 77, 335, 723, 80, 9, 339, 1390, 63, 6856, 63, 3736, 275, 980, 14, 988, 8, 2861, 63, 576, 459, 67, 3736, 63, 894, 63, 2804, 1105, 272, 12994, 63, 11329, 275, 980, 14, 11649, 8, 10412, 827, 12, 1390, 63, 6856, 63, 3736, 12, 14646, 9, 272, 12994, 63, 6851, 275, 980, 14, 14805, 8, 2861, 63, 576, 459, 67, 3736, 63, 894, 63, 2804, 995, 586, 4931, 29, 2861, 63, 576, 459, 7778, 63, 16125, 995, 13341, 29, 6856, 63, 11329, 2788, 16, 61, 339, 8043, 393, 643, 3736, 275, 2615, 63, 576, 459, 2282, 393, 643, 3736, 418, 272, 21914, 1259, 275, 8043, 393, 643, 3736, 59, 2282, 393, 643, 3736, 2356, 17908, 827, 61, 339, 330, 9761, 275, 334, 6856, 63, 11329, 4439, 17, 467, 12994, 63, 11329, 59, 17, 8429, 12994, 63, 6851, 9, 339, 372, 330, 9761, 12, 21914, 1259, 199, 199, 318, 943, 63, 10412, 63, 6856, 8, 599, 458, 12, 13341, 12, 8242 ]
[ 199, 33, 663, 402, 5922, 3423, 367, 27083, 24434, 14, 199, 624, 199, 199, 504, 7026, 492, 21494, 12, 13497, 199, 646, 2680, 465, 980, 12, 394, 21, 647, 199, 504, 2680, 492, 943, 199, 646, 7026, 14, 3200, 465, 10110, 199, 199, 646, 19063, 199, 504, 1134, 19279, 14, 388, 6234, 492, 333, 335, 723, 80, 63, 504, 63, 11535, 17, 63, 11535, 18, 199, 199, 318, 2112, 63, 2861, 63, 576, 8, 5252, 12, 17908, 827, 12, 12250, 17, 12, 12250, 18, 12, 560, 63, 77, 335, 723, 80, 12, 13759, 63, 77, 335, 723, 80, 304, 272, 408, 3284, 314, 4697, 13, 1823, 436, 900, 13, 1823, 18899, 15836, 701, 7009, 315, 2126, 282, 2013, 1425, 402, 682, 723, 80, 12250, 14, 10817, 3897, 2126, 4143, 2126, 18733, 493, 26, 1598, 3814, 626, 14086, 1006, 314, 18899, 2126, 17908, 827, 26, 2069, 1598, 22466, 574, 402, 428, 17774, 294, 264, 12239, 334, 14117, 1929, 5893, 340, 285, 9, 2126, 12250, 17, 26, 1625, 1598, 7758, 12250, 402, 314, 12204, 964, 315, 314, 1978, 16297, 2126, 12250, 18, 26, 1625, 1598, 16707, 12250, 402, 314, 12204, 964, 315, 314, 1978, 16297, 2126, 560, 63, 77, 335, 723, 80, 26, 2069, 1598, 22466, 682, 723, 80, 12250, 367, 314, 1978, 2126, 13759, 63, 77, 335, 723, 80, 26, 2069, 1598, 14212, 682, 723, 80, 12250, 367, 314, 1978, 10817, 1803, 2126, 5514, 2126, 2600, 1598, 3035, 24470, 18899, 436, 8020, 2556, 272, 408, 272, 543, 394, 21, 647, 14, 1173, 8, 5252, 12, 283, 82, 358, 465, 13137, 26, 398, 1305, 63, 66, 9761, 275, 13137, 459, 7451, 63, 2804, 15, 1160, 63, 344, 418, 5873, 267, 1305, 63, 9681, 275, 13137, 459, 23801, 15, 1160, 63, 344, 418, 5873, 398, 333, 335, 723, 80, 63, 66, 9761, 275, 333, 335, 723, 80, 63, 504, 63, 11535, 17, 63, 11535, 18, 8, 11535, 17, 59, 344, 63, 66, 9761, 467, 12250, 18, 59, 344, 63, 66, 9761, 566, 267, 3914, 275, 980, 14, 1037, 1332, 77, 335, 723, 80, 63, 66, 9761, 446, 560, 63, 77, 335, 723, 80, 9, 627, 334, 5812, 63, 77, 335, 723, 80, 446, 333, 335, 723, 80, 63, 66, 9761, 430, 267, 4280, 63, 66, 9761, 275, 980, 14, 4509, 8, 3556, 508, 413, 9, 267, 333, 335, 723, 80, 63, 9681, 275, 333, 335, 723, 80, 63, 504, 63, 11535, 17, 63, 11535, 18, 8, 11535, 17, 59, 344, 63, 9681, 467, 12250, 18, 59, 344, 63, 9681, 566, 267, 3914, 275, 980, 14, 1037, 1332, 77, 335, 723, 80, 63, 9681, 446, 560, 63, 77, 335, 723, 80, 9, 627, 334, 5812, 63, 77, 335, 723, 80, 446, 333, 335, 723, 80, 63, 9681, 430, 267, 4280, 63, 9681, 275, 980, 14, 4509, 8, 3556, 508, 413, 9, 398, 8043, 393, 643, 3736, 275, 13137, 459, 23801, 15, 3736, 418, 1491, 1527, 2996, 63, 9681, 61, 267, 286, 3736, 63, 894, 63, 2804, 275, 13137, 459, 7451, 63, 2804, 15, 3736, 418, 1491, 1527, 2996, 63, 66, 9761, 61, 267, 9700, 63, 16125, 275, 13137, 459, 7451, 63, 2804, 15, 22612, 1615, 63, 4778, 418, 1491, 1527, 2996, 63, 66, 9761, 61, 339, 372, 791, 2282, 393, 643, 3736, 356, 8043, 393, 643, 3736, 59, 2282, 393, 643, 3736, 690, 17908, 827, 467, 1779, 283, 7778, 63, 16125, 356, 9700, 63, 16125, 59, 67, 3736, 63, 894, 63, 2804, 690, 17908, 827, 467, 1779, 283, 67, 3736, 63, 894, 63, 2804, 356, 286, 3736, 63, 894, 63, 2804, 59, 67, 3736, 63, 894, 63, 2804, 690, 17908, 827, 9420, 421, 199, 318, 3354, 63, 66, 9761, 63, 70, 279, 320, 556, 8, 5252, 63, 3736, 1130, 12, 6748, 63, 9860, 12, 931, 12, 17908, 827, 12, 560, 63, 77, 335, 723, 80, 12, 13759, 63, 77, 335, 723, 80, 304, 272, 1449, 5574, 314, 13146, 5443, 1584, 370, 23519, 6895, 82, 289, 279, 320, 556, 367, 314, 8020, 4474, 14, 267, 11063, 314, 1072, 370, 282, 9444, 570, 267, 28721, 570, 365, 2597, 2741, 370, 18152, 18899, 370, 699, 29931, 7009, 14, 398, 3897, 267, 4143, 267, 6748, 63, 3736, 1130, 26, 1059, 2049, 13146, 5443, 570, 3035, 6804, 2556, 267, 6748, 63, 9860, 26, 1059, 2049, 3814, 536, 402, 314, 1978, 16297, 267, 931, 26, 1059, 2049, 28505, 2382, 9444, 570, 365, 6290, 267, 17908, 827, 26, 2069, 2049, 22466, 574, 402, 428, 17774, 294, 264, 12239, 334, 14117, 1929, 5893, 340, 285, 9, 267, 560, 63, 77, 335, 723, 80, 26, 2069, 2049, 22466, 682, 723, 80, 12250, 367, 314, 1978, 267, 13759, 63, 77, 335, 723, 80, 26, 2069, 2049, 14212, 682, 723, 80, 12250, 367, 1978, 272, 1449, 339, 543, 394, 21, 647, 14, 1173, 8, 5252, 63, 9860, 12, 283, 82, 358, 465, 13137, 26, 267, 12250, 17, 63, 9860, 275, 13137, 459, 11535, 17, 418, 5873, 267, 12250, 18, 63, 9860, 275, 13137, 459, 11535, 18, 418, 5873, 267, 2615, 63, 576, 275, 2112, 63, 2861, 63, 576, 8, 5252, 63, 3736, 1130, 12, 17908, 827, 12, 2574, 12250, 17, 63, 9860, 12, 12250, 18, 63, 9860, 12, 560, 63, 77, 335, 723, 80, 12, 13759, 63, 77, 335, 723, 80, 9, 339, 1390, 63, 6856, 63, 3736, 275, 980, 14, 988, 8, 2861, 63, 576, 459, 67, 3736, 63, 894, 63, 2804, 1105, 272, 12994, 63, 11329, 275, 980, 14, 11649, 8, 10412, 827, 12, 1390, 63, 6856, 63, 3736, 12, 14646, 9, 272, 12994, 63, 6851, 275, 980, 14, 14805, 8, 2861, 63, 576, 459, 67, 3736, 63, 894, 63, 2804, 995, 586, 4931, 29, 2861, 63, 576, 459, 7778, 63, 16125, 995, 13341, 29, 6856, 63, 11329, 2788, 16, 61, 339, 8043, 393, 643, 3736, 275, 2615, 63, 576, 459, 2282, 393, 643, 3736, 418, 272, 21914, 1259, 275, 8043, 393, 643, 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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 ]
taotie12010/bigfour
lms/djangoapps/shoppingcart/processors/__init__.py
215
2574
""" Public API for payment processor implementations. The specific implementation is determined at runtime using Django settings: CC_PROCESSOR_NAME: The name of the Python module (in `shoppingcart.processors`) to use. CC_PROCESSOR: Dictionary of configuration options for specific processor implementations, keyed to processor names. """ from django.conf import settings # Import the processor implementation, using `CC_PROCESSOR_NAME` # as the name of the Python module in `shoppingcart.processors` PROCESSOR_MODULE = __import__( 'shoppingcart.processors.' + settings.CC_PROCESSOR_NAME, fromlist=[ 'render_purchase_form_html', 'process_postpay_callback', 'get_purchase_endpoint', 'get_signed_purchase_params', ] ) def render_purchase_form_html(cart, **kwargs): """ Render an HTML form with POSTs to the hosted payment processor. Args: cart (Order): The order model representing items in the user's cart. Returns: unicode: the rendered HTML form """ return PROCESSOR_MODULE.render_purchase_form_html(cart, **kwargs) def process_postpay_callback(params, **kwargs): """ Handle a response from the payment processor. Concrete implementations should: 1) Verify the parameters and determine if the payment was successful. 2) If successful, mark the order as purchased and call `purchased_callbacks` of the cart items. 3) If unsuccessful, try to figure out why and generate a helpful error message. 4) Return a dictionary of the form: {'success': bool, 'order': Order, 'error_html': str} Args: params (dict): Dictionary of parameters received from the payment processor. Keyword Args: Can be used to provide additional information to concrete implementations. Returns: dict """ return PROCESSOR_MODULE.process_postpay_callback(params, **kwargs) def get_purchase_endpoint(): """ Return the URL of the current payment processor's endpoint. Returns: unicode """ return PROCESSOR_MODULE.get_purchase_endpoint() def get_signed_purchase_params(cart, **kwargs): """ Return the parameters to send to the current payment processor. Args: cart (Order): The order model representing items in the user's cart. Keyword Args: Can be used to provide additional information to concrete implementations. Returns: dict """ return PROCESSOR_MODULE.get_signed_purchase_params(cart, **kwargs)
agpl-3.0
[ 624, 199, 9885, 3261, 367, 11628, 12495, 12591, 14, 199, 1918, 2488, 4514, 365, 12037, 737, 8836, 1808, 5634, 2202, 26, 339, 17586, 63, 24341, 63, 2339, 26, 710, 536, 402, 314, 2018, 859, 334, 262, 658, 17788, 14, 10547, 10522, 370, 675, 14, 339, 17586, 63, 24341, 26, 11932, 402, 2897, 1511, 367, 2488, 12495, 12591, 12, 267, 19272, 370, 12495, 1561, 14, 199, 199, 624, 199, 199, 504, 1639, 14, 2190, 492, 2202, 421, 199, 3, 3161, 314, 12495, 4514, 12, 1808, 658, 2571, 63, 24341, 63, 2339, 64, 199, 3, 465, 314, 536, 402, 314, 2018, 859, 315, 658, 17788, 14, 10547, 64, 199, 24341, 63, 10001, 275, 636, 646, 721, 272, 283, 17788, 14, 10547, 3530, 435, 2202, 14, 2571, 63, 24341, 63, 2339, 12, 272, 25321, 1524, 267, 283, 3352, 63, 9533, 63, 964, 63, 1360, 297, 267, 283, 1412, 63, 1932, 5989, 63, 3058, 297, 267, 283, 362, 63, 9533, 63, 6520, 297, 267, 283, 362, 63, 1737, 63, 9533, 63, 1162, 297, 272, 1622, 199, 9, 421, 199, 318, 3795, 63, 9533, 63, 964, 63, 1360, 8, 8153, 12, 1011, 958, 304, 272, 408, 272, 17769, 376, 4163, 1824, 543, 8761, 83, 370, 314, 28311, 11628, 12495, 14, 339, 3033, 26, 267, 16942, 334, 4738, 304, 710, 1865, 1402, 6144, 2974, 315, 314, 922, 1159, 16942, 14, 339, 1803, 26, 267, 2649, 26, 314, 8018, 4163, 1824, 339, 408, 272, 372, 3611, 35, 1608, 726, 63, 10001, 14, 3352, 63, 9533, 63, 964, 63, 1360, 8, 8153, 12, 1011, 958, 9, 421, 199, 318, 2112, 63, 1932, 5989, 63, 3058, 8, 1162, 12, 1011, 958, 304, 272, 408, 272, 8690, 282, 1177, 687, 314, 11628, 12495, 14, 339, 1448, 7564, 12591, 1077, 26, 267, 413, 9, 7635, 314, 2633, 436, 6705, 340, 314, 11628, 1990, 9512, 14, 267, 499, 9, 982, 9512, 12, 2216, 314, 1865, 465, 15932, 68, 436, 1240, 658, 9533, 68, 63, 11948, 64, 402, 314, 16942, 2974, 14, 267, 650, 9, 982, 625, 18157, 12, 862, 370, 9658, 734, 10842, 436, 3550, 282, 24606, 1125, 1245, 14, 267, 841, 9, 1432, 282, 2600, 402, 314, 1824, 26, 288, 791, 3742, 356, 2155, 12, 283, 1648, 356, 9240, 12, 283, 705, 63, 1360, 356, 620, 93, 339, 3033, 26, 267, 1862, 334, 807, 304, 11932, 402, 2633, 3086, 687, 314, 11628, 12495, 14, 339, 6431, 3033, 26, 267, 6855, 506, 1202, 370, 5647, 4722, 2556, 370, 13801, 12591, 14, 339, 1803, 26, 267, 1211, 339, 408, 272, 372, 3611, 35, 1608, 726, 63, 10001, 14, 1412, 63, 1932, 5989, 63, 3058, 8, 1162, 12, 1011, 958, 9, 421, 199, 318, 664, 63, 9533, 63, 6520, 837, 272, 408, 272, 1432, 314, 2851, 402, 314, 1453, 11628, 12495, 1159, 6037, 14, 339, 1803, 26, 267, 2649, 339, 408, 272, 372, 3611, 35, 1608, 726, 63, 10001, 14, 362, 63, 9533, 63, 6520, 342, 421, 199, 318, 664, 63, 1737, 63, 9533, 63, 1162, 8, 8153, 12, 1011, 958, 304, 272, 408, 272, 1432, 314, 2633, 370, 3222, 370, 314, 1453, 11628, 12495, 14, 339, 3033, 26, 267, 16942, 334, 4738, 304, 710, 1865, 1402, 6144, 2974, 315, 314, 922, 1159, 16942, 14, 339, 6431, 3033, 26, 267, 6855, 506, 1202, 370, 5647, 4722, 2556, 370, 13801, 12591, 14, 339, 1803, 26, 267, 1211, 339, 408, 272, 372, 3611, 35, 1608, 726, 63, 10001, 14, 362, 63, 1737, 63, 9533, 63, 1162, 8, 8153, 12, 1011, 958, 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 ]
[ 199, 9885, 3261, 367, 11628, 12495, 12591, 14, 199, 1918, 2488, 4514, 365, 12037, 737, 8836, 1808, 5634, 2202, 26, 339, 17586, 63, 24341, 63, 2339, 26, 710, 536, 402, 314, 2018, 859, 334, 262, 658, 17788, 14, 10547, 10522, 370, 675, 14, 339, 17586, 63, 24341, 26, 11932, 402, 2897, 1511, 367, 2488, 12495, 12591, 12, 267, 19272, 370, 12495, 1561, 14, 199, 199, 624, 199, 199, 504, 1639, 14, 2190, 492, 2202, 421, 199, 3, 3161, 314, 12495, 4514, 12, 1808, 658, 2571, 63, 24341, 63, 2339, 64, 199, 3, 465, 314, 536, 402, 314, 2018, 859, 315, 658, 17788, 14, 10547, 64, 199, 24341, 63, 10001, 275, 636, 646, 721, 272, 283, 17788, 14, 10547, 3530, 435, 2202, 14, 2571, 63, 24341, 63, 2339, 12, 272, 25321, 1524, 267, 283, 3352, 63, 9533, 63, 964, 63, 1360, 297, 267, 283, 1412, 63, 1932, 5989, 63, 3058, 297, 267, 283, 362, 63, 9533, 63, 6520, 297, 267, 283, 362, 63, 1737, 63, 9533, 63, 1162, 297, 272, 1622, 199, 9, 421, 199, 318, 3795, 63, 9533, 63, 964, 63, 1360, 8, 8153, 12, 1011, 958, 304, 272, 408, 272, 17769, 376, 4163, 1824, 543, 8761, 83, 370, 314, 28311, 11628, 12495, 14, 339, 3033, 26, 267, 16942, 334, 4738, 304, 710, 1865, 1402, 6144, 2974, 315, 314, 922, 1159, 16942, 14, 339, 1803, 26, 267, 2649, 26, 314, 8018, 4163, 1824, 339, 408, 272, 372, 3611, 35, 1608, 726, 63, 10001, 14, 3352, 63, 9533, 63, 964, 63, 1360, 8, 8153, 12, 1011, 958, 9, 421, 199, 318, 2112, 63, 1932, 5989, 63, 3058, 8, 1162, 12, 1011, 958, 304, 272, 408, 272, 8690, 282, 1177, 687, 314, 11628, 12495, 14, 339, 1448, 7564, 12591, 1077, 26, 267, 413, 9, 7635, 314, 2633, 436, 6705, 340, 314, 11628, 1990, 9512, 14, 267, 499, 9, 982, 9512, 12, 2216, 314, 1865, 465, 15932, 68, 436, 1240, 658, 9533, 68, 63, 11948, 64, 402, 314, 16942, 2974, 14, 267, 650, 9, 982, 625, 18157, 12, 862, 370, 9658, 734, 10842, 436, 3550, 282, 24606, 1125, 1245, 14, 267, 841, 9, 1432, 282, 2600, 402, 314, 1824, 26, 288, 791, 3742, 356, 2155, 12, 283, 1648, 356, 9240, 12, 283, 705, 63, 1360, 356, 620, 93, 339, 3033, 26, 267, 1862, 334, 807, 304, 11932, 402, 2633, 3086, 687, 314, 11628, 12495, 14, 339, 6431, 3033, 26, 267, 6855, 506, 1202, 370, 5647, 4722, 2556, 370, 13801, 12591, 14, 339, 1803, 26, 267, 1211, 339, 408, 272, 372, 3611, 35, 1608, 726, 63, 10001, 14, 1412, 63, 1932, 5989, 63, 3058, 8, 1162, 12, 1011, 958, 9, 421, 199, 318, 664, 63, 9533, 63, 6520, 837, 272, 408, 272, 1432, 314, 2851, 402, 314, 1453, 11628, 12495, 1159, 6037, 14, 339, 1803, 26, 267, 2649, 339, 408, 272, 372, 3611, 35, 1608, 726, 63, 10001, 14, 362, 63, 9533, 63, 6520, 342, 421, 199, 318, 664, 63, 1737, 63, 9533, 63, 1162, 8, 8153, 12, 1011, 958, 304, 272, 408, 272, 1432, 314, 2633, 370, 3222, 370, 314, 1453, 11628, 12495, 14, 339, 3033, 26, 267, 16942, 334, 4738, 304, 710, 1865, 1402, 6144, 2974, 315, 314, 922, 1159, 16942, 14, 339, 6431, 3033, 26, 267, 6855, 506, 1202, 370, 5647, 4722, 2556, 370, 13801, 12591, 14, 339, 1803, 26, 267, 1211, 339, 408, 272, 372, 3611, 35, 1608, 726, 63, 10001, 14, 362, 63, 1737, 63, 9533, 63, 1162, 8, 8153, 12, 1011, 958, 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, 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, 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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 ]
copyliu/acfun_live_speech
utils.py
1
1318
# -*- coding: UTF-8 -*- __author__ = 'Administrator' import struct acfun_magic_num=689 def acfunencode(d): """ 类似urllib.urlencode()的功能 不过是给ACFUN用的 :param d: @type dict :return: str """ #print d result="" if isinstance(d,dict): for k,v in d.items(): result += "%s@=%s/" % (k, str(v).replace("@","@A").replace("/","@S")) result=str(result) result=struct.pack("I",len(result)+9)+struct.pack("I",len(result)+9)+struct.pack("I",acfun_magic_num)+result result+="\x00" print result return result else: return "" def acfundecode(d): """ 这个是解码的 :param d:str :return : dict """ if len(d)<12: return {} start=0 ent=d result=[] while ent: if len(ent)<4:return result length=struct.unpack("I",d[start:start+4])[0] ent=d[start+12:start+4+length] start=start+4+length dic={} body=ent.split("/") for i in body: if not i:continue entry=i.split("@=") if len(entry)<2:continue dic[entry[0]]=str(entry[1]).replace("@A","@").replace("@S","/") result.append(dic) ent=d[start:] print result return result
gpl-2.0
[ 3, 221, 1882, 2803, 26, 9094, 13, 24, 1882, 199, 363, 2502, 363, 275, 283, 31972, 7, 199, 646, 2702, 199, 199, 645, 7036, 63, 11523, 63, 1507, 29, 29114, 4388, 199, 318, 1066, 7036, 2143, 8, 68, 304, 272, 408, 272, 9112, 110, 120, 17848, 121, 4078, 14, 10738, 342, 8106, 12163, 254, 28371, 221, 19594, 13201, 230, 9729, 9360, 248, 1348, 9309, 11428, 8106, 272, 520, 635, 366, 26, 768, 466, 1211, 272, 520, 1107, 26, 620, 272, 408, 272, 327, 1361, 366, 272, 754, 9287, 272, 340, 1228, 8, 68, 12, 807, 304, 267, 367, 1022, 12, 86, 315, 366, 14, 1744, 837, 288, 754, 847, 2071, 83, 32, 2458, 83, 6687, 450, 334, 75, 12, 620, 8, 86, 680, 1814, 25915, 2266, 32, 33, 3471, 1814, 4769, 2266, 32, 51, 2237, 267, 754, 29, 495, 8, 1099, 9, 267, 754, 29, 1820, 14, 1389, 480, 41, 401, 552, 8, 1099, 6393, 25, 6393, 1820, 14, 1389, 480, 41, 401, 552, 8, 1099, 6393, 25, 6393, 1820, 14, 1389, 480, 41, 401, 645, 7036, 63, 11523, 63, 1507, 6393, 1099, 267, 754, 11, 21024, 88, 383, 2, 267, 870, 754, 267, 372, 754, 268, 2286, 587, 26, 267, 372, 3087, 199, 199, 318, 1066, 7036, 2708, 8, 68, 304, 272, 408, 272, 9065, 124, 248, 10722, 9729, 21482, 97, 8967, 8106, 272, 520, 635, 366, 26, 495, 272, 520, 1107, 520, 1211, 272, 408, 272, 340, 822, 8, 68, 21528, 713, 26, 267, 372, 1052, 339, 1343, 29, 16, 272, 15992, 29, 68, 272, 754, 9811, 272, 1830, 15992, 26, 267, 340, 822, 8, 484, 21528, 20, 26, 1107, 754, 267, 2582, 29, 1820, 14, 5301, 480, 41, 401, 68, 59, 928, 26, 928, 11, 20, 11057, 16, 61, 267, 15992, 29, 68, 59, 928, 11, 713, 26, 928, 11, 20, 11, 1267, 61, 267, 1343, 29, 928, 11, 20, 11, 1267, 267, 12219, 7622, 398, 2396, 29, 484, 14, 1294, 19031, 267, 367, 284, 315, 2396, 26, 288, 340, 440, 284, 26, 6958, 288, 2397, 29, 73, 14, 1294, 25915, 23758, 288, 340, 822, 8, 2373, 21528, 18, 26, 6958, 288, 12219, 59, 2373, 59, 16, 2677, 29, 495, 8, 2373, 59, 17, 6575, 1814, 25915, 33, 2266, 32, 3471, 1814, 25915, 51, 2266, 13589, 267, 754, 14, 740, 8, 5000, 9, 267, 15992, 29, 68, 59, 928, 2938, 272, 870, 754, 272, 372, 754, 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 ]
[ 221, 1882, 2803, 26, 9094, 13, 24, 1882, 199, 363, 2502, 363, 275, 283, 31972, 7, 199, 646, 2702, 199, 199, 645, 7036, 63, 11523, 63, 1507, 29, 29114, 4388, 199, 318, 1066, 7036, 2143, 8, 68, 304, 272, 408, 272, 9112, 110, 120, 17848, 121, 4078, 14, 10738, 342, 8106, 12163, 254, 28371, 221, 19594, 13201, 230, 9729, 9360, 248, 1348, 9309, 11428, 8106, 272, 520, 635, 366, 26, 768, 466, 1211, 272, 520, 1107, 26, 620, 272, 408, 272, 327, 1361, 366, 272, 754, 9287, 272, 340, 1228, 8, 68, 12, 807, 304, 267, 367, 1022, 12, 86, 315, 366, 14, 1744, 837, 288, 754, 847, 2071, 83, 32, 2458, 83, 6687, 450, 334, 75, 12, 620, 8, 86, 680, 1814, 25915, 2266, 32, 33, 3471, 1814, 4769, 2266, 32, 51, 2237, 267, 754, 29, 495, 8, 1099, 9, 267, 754, 29, 1820, 14, 1389, 480, 41, 401, 552, 8, 1099, 6393, 25, 6393, 1820, 14, 1389, 480, 41, 401, 552, 8, 1099, 6393, 25, 6393, 1820, 14, 1389, 480, 41, 401, 645, 7036, 63, 11523, 63, 1507, 6393, 1099, 267, 754, 11, 21024, 88, 383, 2, 267, 870, 754, 267, 372, 754, 268, 2286, 587, 26, 267, 372, 3087, 199, 199, 318, 1066, 7036, 2708, 8, 68, 304, 272, 408, 272, 9065, 124, 248, 10722, 9729, 21482, 97, 8967, 8106, 272, 520, 635, 366, 26, 495, 272, 520, 1107, 520, 1211, 272, 408, 272, 340, 822, 8, 68, 21528, 713, 26, 267, 372, 1052, 339, 1343, 29, 16, 272, 15992, 29, 68, 272, 754, 9811, 272, 1830, 15992, 26, 267, 340, 822, 8, 484, 21528, 20, 26, 1107, 754, 267, 2582, 29, 1820, 14, 5301, 480, 41, 401, 68, 59, 928, 26, 928, 11, 20, 11057, 16, 61, 267, 15992, 29, 68, 59, 928, 11, 713, 26, 928, 11, 20, 11, 1267, 61, 267, 1343, 29, 928, 11, 20, 11, 1267, 267, 12219, 7622, 398, 2396, 29, 484, 14, 1294, 19031, 267, 367, 284, 315, 2396, 26, 288, 340, 440, 284, 26, 6958, 288, 2397, 29, 73, 14, 1294, 25915, 23758, 288, 340, 822, 8, 2373, 21528, 18, 26, 6958, 288, 12219, 59, 2373, 59, 16, 2677, 29, 495, 8, 2373, 59, 17, 6575, 1814, 25915, 33, 2266, 32, 3471, 1814, 25915, 51, 2266, 13589, 267, 754, 14, 740, 8, 5000, 9, 267, 15992, 29, 68, 59, 928, 2938, 272, 870, 754, 272, 372, 754, 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, 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, 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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 ]
florian-dacosta/OCB
addons/mrp/__openerp__.py
52
3781
# -*- 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': 'MRP', 'version': '1.1', 'author': 'OpenERP SA', 'website': 'https://www.odoo.com/page/manufacturing', 'category': 'Manufacturing', 'sequence': 18, 'summary': 'Manufacturing Orders, Bill of Materials, Routing', 'images': ['images/bill_of_materials.jpeg', 'images/manufacturing_order.jpeg', 'images/planning_manufacturing_order.jpeg', 'images/manufacturing_analysis.jpeg', 'images/routings.jpeg','images/work_centers.jpeg'], 'depends': ['product', 'procurement', 'stock_account', 'resource', 'report'], 'description': """ Manage the Manufacturing process in OpenERP =========================================== The manufacturing module allows you to cover planning, ordering, stocks and the manufacturing or assembly of products from raw materials and components. It handles the consumption and production of products according to a bill of materials and the necessary operations on machinery, tools or human resources according to routings. It supports complete integration and planification of stockable goods, consumables or services. Services are completely integrated with the rest of the software. For instance, you can set up a sub-contracting service in a bill of materials to automatically purchase on order the assembly of your production. Key Features ------------ * Make to Stock/Make to Order * Multi-level bill of materials, no limit * Multi-level routing, no limit * Routing and work center integrated with analytic accounting * Periodical scheduler computation * Allows to browse bills of materials in a complete structure that includes child and phantom bills of materials Dashboard / Reports for MRP will include: ----------------------------------------- * Procurements in Exception (Graph) * Stock Value Variation (Graph) * Work Order Analysis """, 'data': [ 'security/mrp_security.xml', 'security/ir.model.access.csv', 'mrp_workflow.xml', 'mrp_data.xml', 'wizard/mrp_product_produce_view.xml', 'wizard/change_production_qty_view.xml', 'wizard/mrp_price_view.xml', 'wizard/mrp_workcenter_load_view.xml', 'wizard/stock_move_view.xml', 'mrp_view.xml', 'mrp_report.xml', 'company_view.xml', 'report/mrp_report_view.xml', 'res_config_view.xml', 'views/report_mrporder.xml', 'views/report_mrpbomstructure.xml', ], 'demo': ['mrp_demo.xml'], 'test': [ 'test/bom_with_service_type_product.yml', 'test/mrp_users.yml', 'test/order_demo.yml', 'test/order_process.yml', 'test/cancel_order.yml', ], 'installable': True, 'application': 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, 421, 199, 91, 272, 283, 354, 356, 283, 45, 18612, 297, 272, 283, 1023, 356, 283, 17, 14, 17, 297, 272, 283, 2502, 356, 283, 25347, 13950, 297, 272, 283, 7360, 356, 283, 2859, 921, 1544, 14, 22058, 14, 957, 15, 1606, 15, 1237, 7415, 319, 4039, 297, 272, 283, 3710, 356, 283, 2395, 7415, 319, 4039, 297, 272, 283, 4041, 356, 6155, 12, 272, 283, 4705, 356, 283, 2395, 7415, 319, 4039, 4236, 7735, 12, 699, 778, 402, 26570, 83, 12, 30790, 316, 297, 272, 283, 4782, 356, 788, 4782, 15, 19815, 63, 1618, 63, 23231, 14, 14230, 297, 283, 4782, 15, 1237, 7415, 319, 4039, 63, 1648, 14, 14230, 297, 283, 4782, 15, 1168, 11495, 63, 1237, 7415, 319, 4039, 63, 1648, 14, 14230, 297, 283, 4782, 15, 1237, 7415, 319, 4039, 63, 10466, 14, 14230, 297, 283, 4782, 15, 12791, 780, 14, 14230, 1673, 4782, 15, 800, 63, 15660, 14, 14230, 995, 272, 283, 8912, 356, 788, 2558, 297, 283, 18546, 297, 283, 6088, 63, 2048, 297, 283, 1927, 297, 283, 3070, 995, 272, 283, 1802, 356, 408, 199, 20588, 314, 4688, 7415, 319, 4039, 2112, 315, 7653, 199, 2486, 21326, 199, 199, 1918, 2169, 7415, 319, 4039, 859, 6127, 1265, 370, 8486, 1620, 11495, 12, 7794, 12, 10952, 83, 436, 314, 2169, 7415, 319, 4039, 503, 24869, 402, 7585, 687, 3066, 8418, 436, 7323, 14, 2779, 10022, 314, 13447, 15052, 436, 9920, 402, 7585, 7182, 370, 282, 330, 778, 402, 8418, 436, 314, 5784, 5331, 641, 28540, 12, 7249, 503, 11779, 5944, 7182, 370, 8659, 780, 14, 199, 199, 7940, 5171, 4890, 13150, 436, 8683, 7313, 402, 10952, 461, 6954, 83, 12, 406, 1838, 5921, 503, 8500, 14, 21813, 787, 14793, 17806, 972, 543, 314, 4618, 402, 314, 2032, 14, 2104, 1256, 12, 1265, 883, 663, 1536, 282, 1007, 13, 14624, 316, 2435, 315, 282, 330, 778, 402, 8418, 370, 5847, 15932, 641, 1865, 314, 24869, 402, 2195, 9920, 14, 199, 199, 1197, 7949, 2093, 199, 4559, 199, 10, 4155, 370, 28406, 15, 5483, 370, 9240, 199, 10, 6879, 13, 1896, 330, 778, 402, 8418, 12, 949, 2304, 199, 10, 6879, 13, 1896, 14870, 12, 949, 2304, 199, 10, 30790, 316, 436, 1736, 8126, 17806, 972, 543, 20705, 24772, 199, 10, 3492, 2308, 328, 915, 11899, 14009, 221, 199, 10, 22819, 370, 19249, 330, 15350, 402, 8418, 315, 282, 4890, 5523, 626, 6952, 1982, 436, 3945, 290, 3151, 330, 15350, 402, 8418, 199, 199, 30122, 1182, 799, 5203, 367, 603, 18612, 911, 2387, 26, 199, 1444, 9960, 199, 10, 29625, 608, 1470, 315, 2186, 334, 4578, 9, 199, 10, 28406, 1594, 21107, 425, 334, 4578, 9, 199, 10, 9361, 9240, 21916, 272, 10327, 272, 283, 576, 356, 359, 267, 283, 4416, 15, 17058, 63, 4416, 14, 1652, 297, 267, 283, 4416, 15, 723, 14, 1238, 14, 2732, 14, 4737, 297, 267, 283, 17058, 63, 8856, 14, 1652, 297, 267, 283, 17058, 63, 576, 14, 1652, 297, 267, 283, 9819, 15, 17058, 63, 2558, 63, 7832, 63, 1345, 14, 1652, 297, 267, 283, 9819, 15, 1461, 63, 10777, 63, 5643, 63, 1345, 14, 1652, 297, 267, 283, 9819, 15, 17058, 63, 4777, 63, 1345, 14, 1652, 297, 267, 283, 9819, 15, 17058, 63, 23963, 63, 912, 63, 1345, 14, 1652, 297, 267, 283, 9819, 15, 6088, 63, 1185, 63, 1345, 14, 1652, 297, 267, 283, 17058, 63, 1345, 14, 1652, 297, 267, 283, 17058, 63, 3070, 14, 1652, 297, 267, 283, 4627, 63, 1345, 14, 1652, 297, 267, 283, 3070, 15, 17058, 63, 3070, 63, 1345, 14, 1652, 297, 267, 283, 470, 63, 888, 63, 1345, 14, 1652, 297, 267, 283, 4196, 15, 3070, 63, 17058, 1648, 14, 1652, 297, 267, 283, 4196, 15, 3070, 63, 17058, 16302, 6976, 14, 1652, 297, 272, 2156, 272, 283, 8768, 356, 788, 17058, 63, 8768, 14, 1652, 995, 272, 283, 396, 356, 359, 268, 283, 396, 15, 16302, 63, 1045, 63, 1364, 63, 466, 63, 2558, 14, 11714, 297, 268, 283, 396, 15, 17058, 63, 3707, 14, 11714, 297, 268, 283, 396, 15, 1648, 63, 8768, 14, 11714, 297, 268, 283, 396, 15, 1648, 63, 1412, 14, 11714, 297, 268, 283, 396, 15, 6406, 63, 1648, 14, 11714, 297, 272, 2156, 272, 283, 21762, 356, 715, 12, 272, 283, 3578, 356, 715, 12, 272, 283, 2495, 63, 3174, 356, 756, 12, 199, 93, 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 ]
[ 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, 421, 199, 91, 272, 283, 354, 356, 283, 45, 18612, 297, 272, 283, 1023, 356, 283, 17, 14, 17, 297, 272, 283, 2502, 356, 283, 25347, 13950, 297, 272, 283, 7360, 356, 283, 2859, 921, 1544, 14, 22058, 14, 957, 15, 1606, 15, 1237, 7415, 319, 4039, 297, 272, 283, 3710, 356, 283, 2395, 7415, 319, 4039, 297, 272, 283, 4041, 356, 6155, 12, 272, 283, 4705, 356, 283, 2395, 7415, 319, 4039, 4236, 7735, 12, 699, 778, 402, 26570, 83, 12, 30790, 316, 297, 272, 283, 4782, 356, 788, 4782, 15, 19815, 63, 1618, 63, 23231, 14, 14230, 297, 283, 4782, 15, 1237, 7415, 319, 4039, 63, 1648, 14, 14230, 297, 283, 4782, 15, 1168, 11495, 63, 1237, 7415, 319, 4039, 63, 1648, 14, 14230, 297, 283, 4782, 15, 1237, 7415, 319, 4039, 63, 10466, 14, 14230, 297, 283, 4782, 15, 12791, 780, 14, 14230, 1673, 4782, 15, 800, 63, 15660, 14, 14230, 995, 272, 283, 8912, 356, 788, 2558, 297, 283, 18546, 297, 283, 6088, 63, 2048, 297, 283, 1927, 297, 283, 3070, 995, 272, 283, 1802, 356, 408, 199, 20588, 314, 4688, 7415, 319, 4039, 2112, 315, 7653, 199, 2486, 21326, 199, 199, 1918, 2169, 7415, 319, 4039, 859, 6127, 1265, 370, 8486, 1620, 11495, 12, 7794, 12, 10952, 83, 436, 314, 2169, 7415, 319, 4039, 503, 24869, 402, 7585, 687, 3066, 8418, 436, 7323, 14, 2779, 10022, 314, 13447, 15052, 436, 9920, 402, 7585, 7182, 370, 282, 330, 778, 402, 8418, 436, 314, 5784, 5331, 641, 28540, 12, 7249, 503, 11779, 5944, 7182, 370, 8659, 780, 14, 199, 199, 7940, 5171, 4890, 13150, 436, 8683, 7313, 402, 10952, 461, 6954, 83, 12, 406, 1838, 5921, 503, 8500, 14, 21813, 787, 14793, 17806, 972, 543, 314, 4618, 402, 314, 2032, 14, 2104, 1256, 12, 1265, 883, 663, 1536, 282, 1007, 13, 14624, 316, 2435, 315, 282, 330, 778, 402, 8418, 370, 5847, 15932, 641, 1865, 314, 24869, 402, 2195, 9920, 14, 199, 199, 1197, 7949, 2093, 199, 4559, 199, 10, 4155, 370, 28406, 15, 5483, 370, 9240, 199, 10, 6879, 13, 1896, 330, 778, 402, 8418, 12, 949, 2304, 199, 10, 6879, 13, 1896, 14870, 12, 949, 2304, 199, 10, 30790, 316, 436, 1736, 8126, 17806, 972, 543, 20705, 24772, 199, 10, 3492, 2308, 328, 915, 11899, 14009, 221, 199, 10, 22819, 370, 19249, 330, 15350, 402, 8418, 315, 282, 4890, 5523, 626, 6952, 1982, 436, 3945, 290, 3151, 330, 15350, 402, 8418, 199, 199, 30122, 1182, 799, 5203, 367, 603, 18612, 911, 2387, 26, 199, 1444, 9960, 199, 10, 29625, 608, 1470, 315, 2186, 334, 4578, 9, 199, 10, 28406, 1594, 21107, 425, 334, 4578, 9, 199, 10, 9361, 9240, 21916, 272, 10327, 272, 283, 576, 356, 359, 267, 283, 4416, 15, 17058, 63, 4416, 14, 1652, 297, 267, 283, 4416, 15, 723, 14, 1238, 14, 2732, 14, 4737, 297, 267, 283, 17058, 63, 8856, 14, 1652, 297, 267, 283, 17058, 63, 576, 14, 1652, 297, 267, 283, 9819, 15, 17058, 63, 2558, 63, 7832, 63, 1345, 14, 1652, 297, 267, 283, 9819, 15, 1461, 63, 10777, 63, 5643, 63, 1345, 14, 1652, 297, 267, 283, 9819, 15, 17058, 63, 4777, 63, 1345, 14, 1652, 297, 267, 283, 9819, 15, 17058, 63, 23963, 63, 912, 63, 1345, 14, 1652, 297, 267, 283, 9819, 15, 6088, 63, 1185, 63, 1345, 14, 1652, 297, 267, 283, 17058, 63, 1345, 14, 1652, 297, 267, 283, 17058, 63, 3070, 14, 1652, 297, 267, 283, 4627, 63, 1345, 14, 1652, 297, 267, 283, 3070, 15, 17058, 63, 3070, 63, 1345, 14, 1652, 297, 267, 283, 470, 63, 888, 63, 1345, 14, 1652, 297, 267, 283, 4196, 15, 3070, 63, 17058, 1648, 14, 1652, 297, 267, 283, 4196, 15, 3070, 63, 17058, 16302, 6976, 14, 1652, 297, 272, 2156, 272, 283, 8768, 356, 788, 17058, 63, 8768, 14, 1652, 995, 272, 283, 396, 356, 359, 268, 283, 396, 15, 16302, 63, 1045, 63, 1364, 63, 466, 63, 2558, 14, 11714, 297, 268, 283, 396, 15, 17058, 63, 3707, 14, 11714, 297, 268, 283, 396, 15, 1648, 63, 8768, 14, 11714, 297, 268, 283, 396, 15, 1648, 63, 1412, 14, 11714, 297, 268, 283, 396, 15, 6406, 63, 1648, 14, 11714, 297, 272, 2156, 272, 283, 21762, 356, 715, 12, 272, 283, 3578, 356, 715, 12, 272, 283, 2495, 63, 3174, 356, 756, 12, 199, 93, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
mahim97/zulip
zilencer/models.py
2
1101
import datetime from typing import Text from django.db import models import zerver.models def get_remote_server_by_uuid(uuid: Text) -> 'RemoteZulipServer': return RemoteZulipServer.objects.get(uuid=uuid) class RemoteZulipServer(models.Model): uuid = models.CharField(max_length=36, unique=True) # type: Text api_key = models.CharField(max_length=64) # type: Text hostname = models.CharField(max_length=128, unique=True) # type: Text contact_email = models.EmailField(blank=True, null=False) # type: Text last_updated = models.DateTimeField('last updated', auto_now=True) # type: datetime.datetime # Variant of PushDeviceToken for a remote server. class RemotePushDeviceToken(zerver.models.AbstractPushDeviceToken): server = models.ForeignKey(RemoteZulipServer) # type: RemoteZulipServer # The user id on the remote server for this device device this is user_id = models.BigIntegerField(db_index=True) # type: int token = models.CharField(max_length=4096, db_index=True) # type: bytes class Meta: unique_together = ("server", "token")
apache-2.0
[ 646, 2197, 199, 504, 14090, 492, 4516, 199, 199, 504, 1639, 14, 697, 492, 1709, 199, 199, 646, 19959, 14, 992, 199, 199, 318, 664, 63, 3846, 63, 1000, 63, 991, 63, 2580, 8, 2580, 26, 4516, 9, 1035, 283, 6713, 58, 11294, 3120, 356, 272, 372, 17283, 58, 11294, 3120, 14, 1462, 14, 362, 8, 2580, 29, 2580, 9, 199, 199, 533, 17283, 58, 11294, 3120, 8, 992, 14, 1685, 304, 272, 5377, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1344, 12, 3747, 29, 549, 9, 221, 327, 730, 26, 4516, 272, 2986, 63, 498, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 772, 9, 221, 327, 730, 26, 4516, 339, 6246, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3933, 12, 3747, 29, 549, 9, 221, 327, 730, 26, 4516, 272, 8966, 63, 2123, 275, 1709, 14, 16577, 8, 2500, 29, 549, 12, 2973, 29, 797, 9, 221, 327, 730, 26, 4516, 272, 2061, 63, 5334, 275, 1709, 14, 4626, 360, 2019, 4588, 297, 2599, 63, 2131, 29, 549, 9, 221, 327, 730, 26, 2197, 14, 2083, 199, 199, 3, 21107, 867, 402, 22643, 2510, 3264, 367, 282, 3982, 1654, 14, 199, 533, 17283, 10731, 2510, 3264, 8, 26996, 14, 992, 14, 8458, 10731, 2510, 3264, 304, 272, 1654, 275, 1709, 14, 3190, 8, 6713, 58, 11294, 3120, 9, 221, 327, 730, 26, 17283, 58, 11294, 3120, 272, 327, 710, 922, 1305, 641, 314, 3982, 1654, 367, 642, 2243, 2243, 642, 365, 272, 922, 63, 344, 275, 1709, 14, 25175, 8, 697, 63, 1080, 29, 549, 9, 221, 327, 730, 26, 1109, 272, 1526, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 20579, 12, 1592, 63, 1080, 29, 549, 9, 221, 327, 730, 26, 2783, 339, 1021, 6288, 26, 267, 3747, 63, 6314, 275, 1689, 1000, 401, 298, 1418, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2197, 199, 504, 14090, 492, 4516, 199, 199, 504, 1639, 14, 697, 492, 1709, 199, 199, 646, 19959, 14, 992, 199, 199, 318, 664, 63, 3846, 63, 1000, 63, 991, 63, 2580, 8, 2580, 26, 4516, 9, 1035, 283, 6713, 58, 11294, 3120, 356, 272, 372, 17283, 58, 11294, 3120, 14, 1462, 14, 362, 8, 2580, 29, 2580, 9, 199, 199, 533, 17283, 58, 11294, 3120, 8, 992, 14, 1685, 304, 272, 5377, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1344, 12, 3747, 29, 549, 9, 221, 327, 730, 26, 4516, 272, 2986, 63, 498, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 772, 9, 221, 327, 730, 26, 4516, 339, 6246, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 3933, 12, 3747, 29, 549, 9, 221, 327, 730, 26, 4516, 272, 8966, 63, 2123, 275, 1709, 14, 16577, 8, 2500, 29, 549, 12, 2973, 29, 797, 9, 221, 327, 730, 26, 4516, 272, 2061, 63, 5334, 275, 1709, 14, 4626, 360, 2019, 4588, 297, 2599, 63, 2131, 29, 549, 9, 221, 327, 730, 26, 2197, 14, 2083, 199, 199, 3, 21107, 867, 402, 22643, 2510, 3264, 367, 282, 3982, 1654, 14, 199, 533, 17283, 10731, 2510, 3264, 8, 26996, 14, 992, 14, 8458, 10731, 2510, 3264, 304, 272, 1654, 275, 1709, 14, 3190, 8, 6713, 58, 11294, 3120, 9, 221, 327, 730, 26, 17283, 58, 11294, 3120, 272, 327, 710, 922, 1305, 641, 314, 3982, 1654, 367, 642, 2243, 2243, 642, 365, 272, 922, 63, 344, 275, 1709, 14, 25175, 8, 697, 63, 1080, 29, 549, 9, 221, 327, 730, 26, 1109, 272, 1526, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 20579, 12, 1592, 63, 1080, 29, 549, 9, 221, 327, 730, 26, 2783, 339, 1021, 6288, 26, 267, 3747, 63, 6314, 275, 1689, 1000, 401, 298, 1418, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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,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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 ]
tareqalayan/ansible
lib/ansible/modules/clustering/k8s/k8s_facts.py
5
4805
#!/usr/bin/python # -*- coding: utf-8 -*- # (c) 2018, Will Thames <@willthames> # 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: k8s_facts short_description: Describe Kubernetes (K8s) objects version_added: "2.7" author: - "Will Thames (@willthames)" description: - Use the OpenShift Python client to perform read operations on K8s objects. - Access to the full range of K8s APIs. - Authenticate using either a config file, certificates, password or token. - Supports check mode. options: api_version: description: - Use to specify the API version. in conjunction with I(kind), I(name), and I(namespace) to identify a specific object. default: v1 aliases: - api - version kind: description: - Use to specify an object model. Use in conjunction with I(api_version), I(name), and I(namespace) to identify a specific object. required: yes name: description: - Use to specify an object name. Use in conjunction with I(api_version), I(kind) and I(namespace) to identify a specific object. namespace: description: - Use to specify an object namespace. Use in conjunction with I(api_version), I(kind), and I(name) to identify a specfic object. label_selectors: description: List of label selectors to use to filter results field_selectors: description: List of field selectors to use to filter results extends_documentation_fragment: - k8s_auth_options requirements: - "python >= 2.7" - "openshift >= 0.6" - "PyYAML >= 3.11" ''' EXAMPLES = ''' - name: Get an existing Service object k8s_facts: api_version: v1 kind: Service name: web namespace: testing register: web_service - name: Get a list of all service objects k8s_facts: api_version: v1 kind: Service namespace: testing register: service_list - name: Get a list of all pods from any namespace k8s_facts: kind: Pod register: pod_list - name: Search for all Pods labelled app=web k8s_facts: kind: Pod label_selectors: - app = web - tier in (dev, test) - name: Search for all running pods k8s_facts: kind: Pod field_selectors: - status.phase = running ''' RETURN = ''' items: description: - The object(s) that exists returned: success type: complex contains: api_version: description: The versioned schema of this representation of an object. returned: success type: str kind: description: Represents the REST resource this object represents. returned: success type: str metadata: description: Standard object metadata. Includes name, namespace, annotations, labels, etc. returned: success type: dict spec: description: Specific attributes of the object. Will vary based on the I(api_version) and I(kind). returned: success type: dict status: description: Current status details for the object. returned: success type: dict ''' from ansible.module_utils.k8s.common import KubernetesAnsibleModule, AUTH_ARG_SPEC import copy class KubernetesFactsModule(KubernetesAnsibleModule): def __init__(self, *args, **kwargs): KubernetesAnsibleModule.__init__(self, *args, supports_check_mode=True, **kwargs) def execute_module(self): self.client = self.get_api_client() self.exit_json(changed=False, **self.kubernetes_facts(self.params['kind'], self.params['api_version'], self.params['name'], self.params['namespace'], self.params['label_selectors'], self.params['field_selectors'])) @property def argspec(self): args = copy.deepcopy(AUTH_ARG_SPEC) args.update( dict( kind=dict(required=True), api_version=dict(default='v1', aliases=['api', 'version']), name=dict(), namespace=dict(), label_selectors=dict(type='list', default=[]), field_selectors=dict(type='list', default=[]), ) ) return args def main(): KubernetesFactsModule().execute_module() 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, 334, 67, 9, 14894, 12, 12823, 3868, 14015, 665, 32, 14117, 273, 14015, 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, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 199, 199, 8948, 275, 1449, 199, 578, 26, 1022, 24, 83, 63, 5047, 199, 199, 3612, 63, 1802, 26, 28571, 1235, 28723, 334, 43, 24, 83, 9, 2251, 199, 199, 1023, 63, 3270, 26, 298, 18, 14, 23, 2, 199, 199, 2502, 26, 272, 446, 298, 20326, 3868, 14015, 8593, 14117, 273, 14015, 2924, 199, 199, 1802, 26, 523, 446, 3645, 314, 3232, 14379, 2018, 1890, 370, 5147, 1586, 5331, 641, 1804, 24, 83, 2251, 14, 523, 446, 11003, 370, 314, 2615, 1425, 402, 1804, 24, 83, 15913, 14, 523, 446, 3590, 7672, 1808, 1902, 282, 1101, 570, 12, 14512, 12, 2505, 503, 1526, 14, 523, 446, 32090, 1104, 818, 14, 199, 199, 1419, 26, 523, 2986, 63, 1023, 26, 272, 1369, 26, 272, 446, 3645, 370, 4165, 314, 3261, 1015, 14, 315, 22888, 543, 473, 8, 5091, 395, 473, 8, 354, 395, 436, 473, 8, 3251, 9, 370, 10405, 282, 489, 2488, 909, 14, 272, 849, 26, 373, 17, 272, 5481, 26, 272, 446, 2986, 272, 446, 1015, 523, 4928, 26, 272, 1369, 26, 272, 446, 3645, 370, 4165, 376, 909, 1402, 14, 3645, 315, 22888, 543, 473, 8, 1246, 63, 1023, 395, 473, 8, 354, 395, 436, 473, 8, 3251, 9, 370, 10405, 282, 489, 2488, 909, 14, 272, 1415, 26, 9456, 523, 536, 26, 272, 1369, 26, 272, 446, 3645, 370, 4165, 376, 909, 536, 14, 221, 3645, 315, 22888, 543, 473, 8, 1246, 63, 1023, 395, 473, 8, 5091, 9, 436, 473, 8, 3251, 9, 370, 10405, 282, 489, 2488, 909, 14, 523, 3231, 26, 272, 1369, 26, 272, 446, 3645, 370, 4165, 376, 909, 3231, 14, 3645, 315, 22888, 543, 473, 8, 1246, 63, 1023, 395, 473, 8, 5091, 395, 436, 473, 8, 354, 9, 489, 370, 10405, 282, 3158, 1792, 909, 14, 523, 1768, 63, 6662, 83, 26, 272, 1369, 26, 3820, 402, 1768, 9759, 83, 370, 675, 370, 2457, 2058, 523, 901, 63, 6662, 83, 26, 272, 1369, 26, 3820, 402, 901, 9759, 83, 370, 675, 370, 2457, 2058, 199, 199, 11036, 63, 9970, 63, 7677, 26, 523, 446, 1022, 24, 83, 63, 1178, 63, 1419, 199, 199, 7538, 26, 523, 446, 298, 1548, 2356, 499, 14, 23, 2, 523, 446, 298, 22858, 2356, 378, 14, 22, 2, 523, 446, 298, 2713, 23103, 2356, 650, 14, 845, 2, 199, 2344, 199, 199, 8918, 275, 1449, 199, 13, 536, 26, 2372, 376, 3411, 7591, 909, 523, 1022, 24, 83, 63, 5047, 26, 272, 2986, 63, 1023, 26, 373, 17, 272, 4928, 26, 7591, 272, 536, 26, 3330, 272, 3231, 26, 5343, 523, 2274, 26, 3330, 63, 1364, 199, 199, 13, 536, 26, 2372, 282, 769, 402, 1006, 2435, 2251, 523, 1022, 24, 83, 63, 5047, 26, 272, 2986, 63, 1023, 26, 373, 17, 272, 4928, 26, 7591, 272, 3231, 26, 5343, 523, 2274, 26, 2435, 63, 513, 199, 199, 13, 536, 26, 2372, 282, 769, 402, 1006, 15329, 83, 687, 1263, 3231, 523, 1022, 24, 83, 63, 5047, 26, 272, 4928, 26, 510, 364, 523, 2274, 26, 15329, 63, 513, 199, 199, 13, 536, 26, 8730, 367, 1006, 510, 364, 83, 1768, 1146, 1145, 29, 2520, 523, 1022, 24, 83, 63, 5047, 26, 272, 4928, 26, 510, 364, 272, 1768, 63, 6662, 83, 26, 489, 446, 1145, 275, 3330, 489, 446, 31800, 315, 334, 2374, 12, 511, 9, 199, 199, 13, 536, 26, 8730, 367, 1006, 3879, 15329, 83, 523, 1022, 24, 83, 63, 5047, 26, 272, 4928, 26, 510, 364, 272, 901, 63, 6662, 83, 26, 489, 446, 2004, 14, 6971, 275, 3879, 199, 2344, 199, 199, 9677, 275, 1449, 199, 1744, 26, 523, 1369, 26, 523, 446, 710, 909, 8, 83, 9, 626, 3495, 523, 2138, 26, 3182, 523, 730, 26, 6114, 523, 3509, 26, 272, 2986, 63, 1023, 26, 489, 1369, 26, 710, 31792, 4177, 402, 642, 6025, 402, 376, 909, 14, 489, 2138, 26, 3182, 489, 730, 26, 620, 272, 4928, 26, 489, 1369, 26, 21591, 314, 14880, 2073, 642, 909, 8469, 14, 489, 2138, 26, 3182, 489, 730, 26, 620, 272, 3341, 26, 489, 1369, 26, 9739, 909, 3341, 14, 15783, 83, 536, 12, 3231, 12, 15538, 12, 3628, 12, 5423, 14, 489, 2138, 26, 3182, 489, 730, 26, 1211, 272, 3158, 26, 489, 1369, 26, 20411, 3004, 402, 314, 909, 14, 12823, 17083, 4079, 641, 314, 473, 8, 1246, 63, 1023, 9, 436, 473, 8, 5091, 680, 489, 2138, 26, 3182, 489, 730, 26, 1211, 272, 2004, 26, 489, 1369, 26, 9338, 2004, 2436, 367, 314, 909, 14, 489, 2138, 26, 3182, 489, 730, 26, 1211, 199, 2344, 421, 199, 504, 3242, 14, 578, 63, 1208, 14, 75, 24, 83, 14, 2330, 492, 28723, 10047, 2377, 12, 7560, 63, 11611, 63, 24147, 199, 646, 1331, 421, 199, 533, 28723, 25821, 2377, 8, 43, 12183, 10047, 2377, 304, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 28723, 10047, 2377, 855, 826, 721, 277, 12, 627, 589, 12, 1460, 5171, 63, 1074, 63, 632, 29, 549, 12, 1460, 1011, 958, 9, 339, 347, 5341, 63, 578, 8, 277, 304, 267, 291, 14, 1258, 275, 291, 14, 362, 63, 1246, 63, 1258, 342, 398, 291, 14, 2224, 63, 1001, 8, 2489, 29, 797, 12, 2432, 1011, 277, 14, 17422, 63, 5047, 8, 277, 14, 1162, 459, 5091, 995, 6901, 291, 14, 1162, 459, 1246, 63, 1023, 995, 6901, 291, 14, 1162, 459, 354, 995, 6901, 291, 14, 1162, 459 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 14894, 12, 12823, 3868, 14015, 665, 32, 14117, 273, 14015, 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, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 199, 199, 8948, 275, 1449, 199, 578, 26, 1022, 24, 83, 63, 5047, 199, 199, 3612, 63, 1802, 26, 28571, 1235, 28723, 334, 43, 24, 83, 9, 2251, 199, 199, 1023, 63, 3270, 26, 298, 18, 14, 23, 2, 199, 199, 2502, 26, 272, 446, 298, 20326, 3868, 14015, 8593, 14117, 273, 14015, 2924, 199, 199, 1802, 26, 523, 446, 3645, 314, 3232, 14379, 2018, 1890, 370, 5147, 1586, 5331, 641, 1804, 24, 83, 2251, 14, 523, 446, 11003, 370, 314, 2615, 1425, 402, 1804, 24, 83, 15913, 14, 523, 446, 3590, 7672, 1808, 1902, 282, 1101, 570, 12, 14512, 12, 2505, 503, 1526, 14, 523, 446, 32090, 1104, 818, 14, 199, 199, 1419, 26, 523, 2986, 63, 1023, 26, 272, 1369, 26, 272, 446, 3645, 370, 4165, 314, 3261, 1015, 14, 315, 22888, 543, 473, 8, 5091, 395, 473, 8, 354, 395, 436, 473, 8, 3251, 9, 370, 10405, 282, 489, 2488, 909, 14, 272, 849, 26, 373, 17, 272, 5481, 26, 272, 446, 2986, 272, 446, 1015, 523, 4928, 26, 272, 1369, 26, 272, 446, 3645, 370, 4165, 376, 909, 1402, 14, 3645, 315, 22888, 543, 473, 8, 1246, 63, 1023, 395, 473, 8, 354, 395, 436, 473, 8, 3251, 9, 370, 10405, 282, 489, 2488, 909, 14, 272, 1415, 26, 9456, 523, 536, 26, 272, 1369, 26, 272, 446, 3645, 370, 4165, 376, 909, 536, 14, 221, 3645, 315, 22888, 543, 473, 8, 1246, 63, 1023, 395, 473, 8, 5091, 9, 436, 473, 8, 3251, 9, 370, 10405, 282, 489, 2488, 909, 14, 523, 3231, 26, 272, 1369, 26, 272, 446, 3645, 370, 4165, 376, 909, 3231, 14, 3645, 315, 22888, 543, 473, 8, 1246, 63, 1023, 395, 473, 8, 5091, 395, 436, 473, 8, 354, 9, 489, 370, 10405, 282, 3158, 1792, 909, 14, 523, 1768, 63, 6662, 83, 26, 272, 1369, 26, 3820, 402, 1768, 9759, 83, 370, 675, 370, 2457, 2058, 523, 901, 63, 6662, 83, 26, 272, 1369, 26, 3820, 402, 901, 9759, 83, 370, 675, 370, 2457, 2058, 199, 199, 11036, 63, 9970, 63, 7677, 26, 523, 446, 1022, 24, 83, 63, 1178, 63, 1419, 199, 199, 7538, 26, 523, 446, 298, 1548, 2356, 499, 14, 23, 2, 523, 446, 298, 22858, 2356, 378, 14, 22, 2, 523, 446, 298, 2713, 23103, 2356, 650, 14, 845, 2, 199, 2344, 199, 199, 8918, 275, 1449, 199, 13, 536, 26, 2372, 376, 3411, 7591, 909, 523, 1022, 24, 83, 63, 5047, 26, 272, 2986, 63, 1023, 26, 373, 17, 272, 4928, 26, 7591, 272, 536, 26, 3330, 272, 3231, 26, 5343, 523, 2274, 26, 3330, 63, 1364, 199, 199, 13, 536, 26, 2372, 282, 769, 402, 1006, 2435, 2251, 523, 1022, 24, 83, 63, 5047, 26, 272, 2986, 63, 1023, 26, 373, 17, 272, 4928, 26, 7591, 272, 3231, 26, 5343, 523, 2274, 26, 2435, 63, 513, 199, 199, 13, 536, 26, 2372, 282, 769, 402, 1006, 15329, 83, 687, 1263, 3231, 523, 1022, 24, 83, 63, 5047, 26, 272, 4928, 26, 510, 364, 523, 2274, 26, 15329, 63, 513, 199, 199, 13, 536, 26, 8730, 367, 1006, 510, 364, 83, 1768, 1146, 1145, 29, 2520, 523, 1022, 24, 83, 63, 5047, 26, 272, 4928, 26, 510, 364, 272, 1768, 63, 6662, 83, 26, 489, 446, 1145, 275, 3330, 489, 446, 31800, 315, 334, 2374, 12, 511, 9, 199, 199, 13, 536, 26, 8730, 367, 1006, 3879, 15329, 83, 523, 1022, 24, 83, 63, 5047, 26, 272, 4928, 26, 510, 364, 272, 901, 63, 6662, 83, 26, 489, 446, 2004, 14, 6971, 275, 3879, 199, 2344, 199, 199, 9677, 275, 1449, 199, 1744, 26, 523, 1369, 26, 523, 446, 710, 909, 8, 83, 9, 626, 3495, 523, 2138, 26, 3182, 523, 730, 26, 6114, 523, 3509, 26, 272, 2986, 63, 1023, 26, 489, 1369, 26, 710, 31792, 4177, 402, 642, 6025, 402, 376, 909, 14, 489, 2138, 26, 3182, 489, 730, 26, 620, 272, 4928, 26, 489, 1369, 26, 21591, 314, 14880, 2073, 642, 909, 8469, 14, 489, 2138, 26, 3182, 489, 730, 26, 620, 272, 3341, 26, 489, 1369, 26, 9739, 909, 3341, 14, 15783, 83, 536, 12, 3231, 12, 15538, 12, 3628, 12, 5423, 14, 489, 2138, 26, 3182, 489, 730, 26, 1211, 272, 3158, 26, 489, 1369, 26, 20411, 3004, 402, 314, 909, 14, 12823, 17083, 4079, 641, 314, 473, 8, 1246, 63, 1023, 9, 436, 473, 8, 5091, 680, 489, 2138, 26, 3182, 489, 730, 26, 1211, 272, 2004, 26, 489, 1369, 26, 9338, 2004, 2436, 367, 314, 909, 14, 489, 2138, 26, 3182, 489, 730, 26, 1211, 199, 2344, 421, 199, 504, 3242, 14, 578, 63, 1208, 14, 75, 24, 83, 14, 2330, 492, 28723, 10047, 2377, 12, 7560, 63, 11611, 63, 24147, 199, 646, 1331, 421, 199, 533, 28723, 25821, 2377, 8, 43, 12183, 10047, 2377, 304, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 28723, 10047, 2377, 855, 826, 721, 277, 12, 627, 589, 12, 1460, 5171, 63, 1074, 63, 632, 29, 549, 12, 1460, 1011, 958, 9, 339, 347, 5341, 63, 578, 8, 277, 304, 267, 291, 14, 1258, 275, 291, 14, 362, 63, 1246, 63, 1258, 342, 398, 291, 14, 2224, 63, 1001, 8, 2489, 29, 797, 12, 2432, 1011, 277, 14, 17422, 63, 5047, 8, 277, 14, 1162, 459, 5091, 995, 6901, 291, 14, 1162, 459, 1246, 63, 1023, 995, 6901, 291, 14, 1162, 459, 354, 995, 6901, 291, 14, 1162, 459, 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, 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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 ]
bjolivot/ansible
test/units/modules/system/test_known_hosts.py
61
4114
import os import tempfile from ansible.compat.tests import unittest from ansible.module_utils._text import to_bytes from ansible.modules.system.known_hosts import compute_diff class KnownHostsDiffTestCase(unittest.TestCase): def _create_file(self, content): tmp_file = tempfile.NamedTemporaryFile(prefix='ansible-test-', suffix='-known_hosts', delete=False) tmp_file.write(to_bytes(content)) tmp_file.close() self.addCleanup(os.unlink, tmp_file.name) return tmp_file.name def test_no_existing_file(self): path = tempfile.mktemp(prefix='ansible-test-', suffix='-known_hosts') key = 'example.com ssh-rsa AAAAetc\n' diff = compute_diff(path, found_line=None, replace_or_add=False, state='present', key=key) self.assertEqual(diff, { 'before_header': '/dev/null', 'after_header': path, 'before': '', 'after': 'example.com ssh-rsa AAAAetc\n', }) def test_key_addition(self): path = self._create_file( 'two.example.com ssh-rsa BBBBetc\n' ) key = 'one.example.com ssh-rsa AAAAetc\n' diff = compute_diff(path, found_line=None, replace_or_add=False, state='present', key=key) self.assertEqual(diff, { 'before_header': path, 'after_header': path, 'before': 'two.example.com ssh-rsa BBBBetc\n', 'after': 'two.example.com ssh-rsa BBBBetc\n' 'one.example.com ssh-rsa AAAAetc\n', }) def test_no_change(self): path = self._create_file( 'one.example.com ssh-rsa AAAAetc\n' 'two.example.com ssh-rsa BBBBetc\n' ) key = 'one.example.com ssh-rsa AAAAetc\n' diff = compute_diff(path, found_line=1, replace_or_add=False, state='present', key=key) self.assertEqual(diff, { 'before_header': path, 'after_header': path, 'before': 'one.example.com ssh-rsa AAAAetc\n' 'two.example.com ssh-rsa BBBBetc\n', 'after': 'one.example.com ssh-rsa AAAAetc\n' 'two.example.com ssh-rsa BBBBetc\n', }) def test_key_change(self): path = self._create_file( 'one.example.com ssh-rsa AAAaetc\n' 'two.example.com ssh-rsa BBBBetc\n' ) key = 'one.example.com ssh-rsa AAAAetc\n' diff = compute_diff(path, found_line=1, replace_or_add=True, state='present', key=key) self.assertEqual(diff, { 'before_header': path, 'after_header': path, 'before': 'one.example.com ssh-rsa AAAaetc\n' 'two.example.com ssh-rsa BBBBetc\n', 'after': 'two.example.com ssh-rsa BBBBetc\n' 'one.example.com ssh-rsa AAAAetc\n', }) def test_key_removal(self): path = self._create_file( 'one.example.com ssh-rsa AAAAetc\n' 'two.example.com ssh-rsa BBBBetc\n' ) key = 'one.example.com ssh-rsa AAAAetc\n' diff = compute_diff(path, found_line=1, replace_or_add=False, state='absent', key=key) self.assertEqual(diff, { 'before_header': path, 'after_header': path, 'before': 'one.example.com ssh-rsa AAAAetc\n' 'two.example.com ssh-rsa BBBBetc\n', 'after': 'two.example.com ssh-rsa BBBBetc\n', }) def test_key_removal_no_change(self): path = self._create_file( 'two.example.com ssh-rsa BBBBetc\n' ) key = 'one.example.com ssh-rsa AAAAetc\n' diff = compute_diff(path, found_line=None, replace_or_add=False, state='absent', key=key) self.assertEqual(diff, { 'before_header': path, 'after_header': path, 'before': 'two.example.com ssh-rsa BBBBetc\n', 'after': 'two.example.com ssh-rsa BBBBetc\n', })
gpl-3.0
[ 646, 747, 199, 646, 5549, 199, 199, 504, 3242, 14, 5819, 14, 2219, 492, 2882, 199, 504, 3242, 14, 578, 63, 1208, 423, 505, 492, 370, 63, 2394, 199, 199, 504, 3242, 14, 3112, 14, 2253, 14, 3159, 63, 5146, 492, 4526, 63, 3028, 421, 199, 533, 31862, 19620, 10746, 1746, 8, 2796, 14, 1746, 304, 339, 347, 485, 981, 63, 493, 8, 277, 12, 1564, 304, 267, 3529, 63, 493, 275, 5549, 14, 19320, 8, 1861, 534, 4853, 13, 396, 14382, 4739, 18274, 3159, 63, 5146, 297, 3145, 29, 797, 9, 267, 3529, 63, 493, 14, 952, 8, 475, 63, 2394, 8, 1317, 430, 267, 3529, 63, 493, 14, 1600, 342, 267, 291, 14, 12808, 8, 736, 14, 7162, 12, 3529, 63, 493, 14, 354, 9, 267, 372, 3529, 63, 493, 14, 354, 339, 347, 511, 63, 889, 63, 5952, 63, 493, 8, 277, 304, 267, 931, 275, 5549, 14, 22136, 8, 1861, 534, 4853, 13, 396, 14382, 4739, 18274, 3159, 63, 5146, 358, 267, 790, 275, 283, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 403, 12, 3350, 63, 269, 63, 525, 29, 797, 12, 1174, 534, 1881, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 1994, 2374, 15, 2307, 297, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 3260, 288, 283, 4399, 356, 283, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 498, 63, 26799, 8, 277, 304, 267, 931, 275, 291, 423, 981, 63, 493, 8, 288, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 267, 776, 267, 790, 275, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 403, 12, 3350, 63, 269, 63, 525, 29, 797, 12, 1174, 534, 1881, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 931, 12, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 288, 283, 4399, 356, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 889, 63, 1461, 8, 277, 304, 267, 931, 275, 291, 423, 981, 63, 493, 8, 288, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 288, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 267, 776, 267, 790, 275, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 17, 12, 3350, 63, 269, 63, 525, 29, 797, 12, 1174, 534, 1881, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 931, 12, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 288, 283, 4399, 356, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 498, 63, 1461, 8, 277, 304, 267, 931, 275, 291, 423, 981, 63, 493, 8, 288, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 2276, 65, 6839, 60, 78, 7, 288, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 267, 776, 267, 790, 275, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 17, 12, 3350, 63, 269, 63, 525, 29, 549, 12, 1174, 534, 1881, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 931, 12, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 2276, 65, 6839, 60, 78, 7, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 288, 283, 4399, 356, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 498, 63, 25818, 8, 277, 304, 267, 931, 275, 291, 423, 981, 63, 493, 8, 288, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 288, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 267, 776, 267, 790, 275, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 17, 12, 3350, 63, 269, 63, 525, 29, 797, 12, 1174, 534, 5575, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 931, 12, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 288, 283, 4399, 356, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 498, 63, 25818 ]
[ 747, 199, 646, 5549, 199, 199, 504, 3242, 14, 5819, 14, 2219, 492, 2882, 199, 504, 3242, 14, 578, 63, 1208, 423, 505, 492, 370, 63, 2394, 199, 199, 504, 3242, 14, 3112, 14, 2253, 14, 3159, 63, 5146, 492, 4526, 63, 3028, 421, 199, 533, 31862, 19620, 10746, 1746, 8, 2796, 14, 1746, 304, 339, 347, 485, 981, 63, 493, 8, 277, 12, 1564, 304, 267, 3529, 63, 493, 275, 5549, 14, 19320, 8, 1861, 534, 4853, 13, 396, 14382, 4739, 18274, 3159, 63, 5146, 297, 3145, 29, 797, 9, 267, 3529, 63, 493, 14, 952, 8, 475, 63, 2394, 8, 1317, 430, 267, 3529, 63, 493, 14, 1600, 342, 267, 291, 14, 12808, 8, 736, 14, 7162, 12, 3529, 63, 493, 14, 354, 9, 267, 372, 3529, 63, 493, 14, 354, 339, 347, 511, 63, 889, 63, 5952, 63, 493, 8, 277, 304, 267, 931, 275, 5549, 14, 22136, 8, 1861, 534, 4853, 13, 396, 14382, 4739, 18274, 3159, 63, 5146, 358, 267, 790, 275, 283, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 403, 12, 3350, 63, 269, 63, 525, 29, 797, 12, 1174, 534, 1881, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 1994, 2374, 15, 2307, 297, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 3260, 288, 283, 4399, 356, 283, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 498, 63, 26799, 8, 277, 304, 267, 931, 275, 291, 423, 981, 63, 493, 8, 288, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 267, 776, 267, 790, 275, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 403, 12, 3350, 63, 269, 63, 525, 29, 797, 12, 1174, 534, 1881, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 931, 12, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 288, 283, 4399, 356, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 889, 63, 1461, 8, 277, 304, 267, 931, 275, 291, 423, 981, 63, 493, 8, 288, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 288, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 267, 776, 267, 790, 275, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 17, 12, 3350, 63, 269, 63, 525, 29, 797, 12, 1174, 534, 1881, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 931, 12, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 288, 283, 4399, 356, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 498, 63, 1461, 8, 277, 304, 267, 931, 275, 291, 423, 981, 63, 493, 8, 288, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 2276, 65, 6839, 60, 78, 7, 288, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 267, 776, 267, 790, 275, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 17, 12, 3350, 63, 269, 63, 525, 29, 549, 12, 1174, 534, 1881, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 931, 12, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 2276, 65, 6839, 60, 78, 7, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 288, 283, 4399, 356, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 498, 63, 25818, 8, 277, 304, 267, 931, 275, 291, 423, 981, 63, 493, 8, 288, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 288, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 7, 267, 776, 267, 790, 275, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 267, 3915, 275, 4526, 63, 3028, 8, 515, 12, 1911, 63, 604, 29, 17, 12, 3350, 63, 269, 63, 525, 29, 797, 12, 1174, 534, 5575, 297, 790, 29, 498, 9, 267, 291, 14, 629, 8, 3028, 12, 469, 288, 283, 5182, 63, 1291, 356, 931, 12, 288, 283, 4399, 63, 1291, 356, 931, 12, 288, 283, 5182, 356, 355, 283, 368, 14, 2694, 14, 957, 8635, 13, 13487, 437, 10985, 6839, 60, 78, 7, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 288, 283, 4399, 356, 355, 283, 5601, 14, 2694, 14, 957, 8635, 13, 13487, 699, 27137, 6839, 60, 78, 297, 267, 3828, 339, 347, 511, 63, 498, 63, 25818, 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 ]
matthijsvk/multimodalSR
code/Experiments/neon-master/examples/faster-rcnn/convert_xml_to_json.py
1
5828
# ---------------------------------------------------------------------------- # Copyright 2016 Nervana Systems 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 json import glob import collections import os from os.path import join import xml.etree.ElementTree as et from collections import defaultdict import argparse # http://stackoverflow.com/questions/7684333/converting-xml-to-dictionary-using-elementtree def etree_to_dict(t): d = {t.tag: {} if t.attrib else None} children = list(t) if children: dd = defaultdict(list) for dc in map(etree_to_dict, children): for k, v in dc.items(): dd[k].append(v) d = {t.tag: {k: v[0] if len(v) == 1 else v for k, v in dd.items()}} if t.attrib: d[t.tag].update(('@' + k, v) for k, v in t.attrib.items()) if t.text: text = t.text.strip() if children or t.attrib: if text: d[t.tag]['#text'] = text else: d[t.tag] = text return d def validate_metadata(jobj, file): boxlist = jobj['object'] if not isinstance(boxlist, collections.Sequence): print('{0} is not a sequence').format(file) return False index = 0 for box in boxlist: if 'part' in box: parts = box['part'] if not isinstance(parts, collections.Sequence): print('parts {0} is not a sequence').format(file) return False index += 1 return True def convert_xml_to_json(input_path, output_path, difficult): if not os.path.exists(output_path): os.makedirs(output_path) onlyfiles = glob.glob(join(input_path, '*.xml')) onlyfiles.sort() for file in onlyfiles: outfile = join(output_path, os.path.basename(file)) outfile = os.path.splitext(outfile)[0] + '.json' trimmed = parse_single_file(join(input_path, file), difficult) if validate_metadata(trimmed, file): result = json.dumps(trimmed, sort_keys=True, indent=4, separators=(',', ': ')) f = open(outfile, 'w') f.write(result) else: print('error parsing metadata {0}').format(file) def parse_single_file(path, difficult): tree = et.parse(path) root = tree.getroot() d = etree_to_dict(root) trimmed = d['annotation'] olist = trimmed['object'] if not isinstance(olist, collections.Sequence): trimmed['object'] = [olist] olist = trimmed['object'] size = trimmed['size'] # Add version number to json trimmed['version'] = {'major': 1, 'minor': 0} # convert all numbers from string representation to number so json does not quote them # all of the bounding box numbers are one based so subtract 1 size['width'] = int(size['width']) size['height'] = int(size['height']) size['depth'] = int(size['depth']) width = trimmed['size']['width'] height = trimmed['size']['height'] for obj in olist: obj['difficult'] = int(obj['difficult']) != 0 obj['truncated'] = int(obj['truncated']) != 0 box = obj['bndbox'] box['xmax'] = int(box['xmax']) - 1 box['xmin'] = int(box['xmin']) - 1 box['ymax'] = int(box['ymax']) - 1 box['ymin'] = int(box['ymin']) - 1 if 'part' in obj: for part in obj['part']: box = part['bndbox'] box['xmax'] = float(box['xmax']) - 1 box['xmin'] = float(box['xmin']) - 1 box['ymax'] = float(box['ymax']) - 1 box['ymin'] = float(box['ymin']) - 1 xmax = box['xmax'] xmin = box['xmin'] ymax = box['ymax'] ymin = box['ymin'] if xmax > width - 1: print('xmax {0} exceeds width {1}').format(xmax, width) if xmin < 0: print('xmin {0} exceeds width {1}').format(xmin, width) if ymax > height - 1: print('ymax {0} exceeds width {1}').format(ymax, height) if ymin < 0: print('ymin {0} exceeds width {1}').format(ymin, height) # exclude difficult objects if not difficult: trimmed['object'] = [o for o in trimmed['object'] if not o['difficult']] return trimmed if __name__ == "__main__": parser = argparse.ArgumentParser(description="convert xml to json for pascalvoc dataset") parser.add_argument('-i, --input', dest='input', help='input directory with xml files.') parser.add_argument('-o, --output', dest='output', help='output directory of json files.') parser.add_argument('-p, --parse', dest='parse', help='parse a single xml file.') parser.add_argument('--difficult', dest='difficult', action='store_true', help='include objects with the difficult tag. Default is to exclude.') args = parser.parse_args() input_path = args.input output_path = args.output parse_file = args.parse if parse_file: print(parse_file) parsed = parse_single_file(parse_file, args.difficult) json1 = json.dumps(parsed, sort_keys=True, indent=4, separators=(',', ': ')) print(json1) elif input_path: convert_xml_to_json(input_path, output_path, args.difficult)
mit
[ 3, 27103, 199, 3, 1898, 7800, 653, 281, 86, 6738, 15285, 3277, 14, 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, 3, 27103, 199, 646, 2022, 199, 646, 5739, 199, 646, 5055, 199, 646, 747, 199, 504, 747, 14, 515, 492, 4263, 199, 646, 2748, 14, 9464, 14, 15325, 465, 10844, 199, 504, 5055, 492, 10018, 199, 646, 7534, 421, 199, 3, 1455, 921, 23153, 14, 957, 15, 16069, 15, 2114, 1349, 11769, 15, 6435, 1337, 13, 1652, 13, 475, 13, 9086, 13, 4941, 13, 2108, 2350, 199, 318, 7559, 63, 475, 63, 807, 8, 84, 304, 272, 366, 275, 469, 84, 14, 1450, 26, 1052, 340, 307, 14, 6640, 587, 488, 93, 272, 4978, 275, 769, 8, 84, 9, 272, 340, 4978, 26, 267, 13972, 275, 10018, 8, 513, 9, 267, 367, 12326, 315, 2341, 8, 9464, 63, 475, 63, 807, 12, 4978, 304, 288, 367, 1022, 12, 373, 315, 12326, 14, 1744, 837, 355, 13972, 59, 75, 1055, 740, 8, 86, 9, 267, 366, 275, 469, 84, 14, 1450, 26, 469, 75, 26, 373, 59, 16, 61, 340, 822, 8, 86, 9, 508, 413, 587, 373, 367, 1022, 12, 373, 315, 13972, 14, 1744, 342, 4863, 272, 340, 307, 14, 6640, 26, 267, 366, 59, 84, 14, 1450, 1055, 873, 4725, 32, 7, 435, 1022, 12, 373, 9, 367, 1022, 12, 373, 315, 307, 14, 6640, 14, 1744, 1012, 272, 340, 307, 14, 505, 26, 267, 1318, 275, 307, 14, 505, 14, 1913, 342, 267, 340, 4978, 503, 307, 14, 6640, 26, 288, 340, 1318, 26, 355, 366, 59, 84, 14, 1450, 2733, 3, 505, 418, 275, 1318, 267, 587, 26, 288, 366, 59, 84, 14, 1450, 61, 275, 1318, 272, 372, 366, 421, 199, 318, 4107, 63, 2343, 8, 743, 468, 12, 570, 304, 272, 5689, 513, 275, 5225, 468, 459, 785, 418, 272, 340, 440, 1228, 8, 1977, 513, 12, 5055, 14, 5826, 304, 267, 870, 11117, 16, 93, 365, 440, 282, 3414, 1959, 908, 8, 493, 9, 267, 372, 756, 339, 1478, 275, 378, 272, 367, 5689, 315, 5689, 513, 26, 267, 340, 283, 2064, 7, 315, 5689, 26, 288, 4184, 275, 5689, 459, 2064, 418, 288, 340, 440, 1228, 8, 4181, 12, 5055, 14, 5826, 304, 355, 870, 360, 4181, 469, 16, 93, 365, 440, 282, 3414, 1959, 908, 8, 493, 9, 355, 372, 756, 267, 1478, 847, 413, 272, 372, 715, 421, 199, 318, 3957, 63, 1652, 63, 475, 63, 1001, 8, 1210, 63, 515, 12, 1072, 63, 515, 12, 29870, 304, 339, 340, 440, 747, 14, 515, 14, 2444, 8, 1199, 63, 515, 304, 267, 747, 14, 8347, 8, 1199, 63, 515, 9, 272, 1454, 1725, 275, 5739, 14, 6463, 8, 904, 8, 1210, 63, 515, 12, 11937, 1652, 1333, 272, 1454, 1725, 14, 3191, 342, 272, 367, 570, 315, 1454, 1725, 26, 267, 4386, 275, 4263, 8, 1199, 63, 515, 12, 747, 14, 515, 14, 4846, 8, 493, 430, 267, 4386, 275, 747, 14, 515, 14, 7973, 8, 4984, 2788, 16, 61, 435, 1987, 1001, 7, 267, 24196, 275, 2198, 63, 4780, 63, 493, 8, 904, 8, 1210, 63, 515, 12, 570, 395, 29870, 9, 267, 340, 4107, 63, 2343, 8, 12263, 3594, 12, 570, 304, 288, 754, 275, 2022, 14, 4180, 8, 12263, 3594, 12, 4069, 63, 1612, 29, 549, 12, 4363, 29, 20, 12, 17658, 2687, 23324, 7596, 20005, 288, 289, 275, 1551, 8, 4984, 12, 283, 87, 358, 288, 289, 14, 952, 8, 1099, 9, 267, 587, 26, 288, 870, 360, 705, 6057, 3341, 469, 16, 93, 1959, 908, 8, 493, 9, 421, 199, 318, 2198, 63, 4780, 63, 493, 8, 515, 12, 29870, 304, 272, 3123, 275, 10844, 14, 1122, 8, 515, 9, 272, 1738, 275, 3123, 14, 24544, 342, 272, 366, 275, 7559, 63, 475, 63, 807, 8, 1231, 9, 272, 24196, 275, 366, 459, 9340, 418, 272, 312, 513, 275, 24196, 459, 785, 418, 272, 340, 440, 1228, 8, 79, 513, 12, 5055, 14, 5826, 304, 267, 24196, 459, 785, 418, 275, 359, 79, 513, 61, 267, 312, 513, 275, 24196, 459, 785, 418, 272, 1568, 275, 24196, 459, 890, 418, 339, 327, 2654, 1015, 1329, 370, 2022, 272, 24196, 459, 1023, 418, 275, 791, 8452, 356, 413, 12, 283, 11067, 356, 378, 93, 339, 327, 3957, 1006, 5579, 687, 1059, 6025, 370, 1329, 880, 2022, 1630, 440, 6313, 3062, 272, 327, 1006, 402, 314, 16842, 5689, 5579, 787, 1373, 4079, 880, 24129, 413, 272, 1568, 459, 2063, 418, 275, 1109, 8, 890, 459, 2063, 1105, 272, 1568, 459, 3333, 418, 275, 1109, 8, 890, 459, 3333, 1105, 272, 1568, 459, 4631, 418, 275, 1109, 8, 890, 459, 4631, 1105, 272, 3462, 275, 24196, 459, 890, 2545, 2063, 418, 272, 4569, 275, 24196, 459, 890, 2545, 3333, 418, 272, 367, 1559, 315, 312, 513, 26, 267, 1559, 459, 7330, 1792, 427, 418, 275, 1109, 8, 1113, 459, 7330, 1792, 427, 1105, 1137, 378, 267, 1559, 459, 19347, 418, 275, 1109, 8, 1113, 459, 19347, 1105, 1137, 378, 267, 5689, 275, 1559, 459, 66, 977, 1977, 418, 267, 5689, 459, 28961, 418, 275, 1109, 8, 1977, 459, 28961, 1105, 446, 413, 267, 5689, 459, 21601, 418, 275, 1109, 8, 1977, 459, 21601, 1105, 446, 413, 267, 5689, 459, 30036, 418, 275, 1109, 8, 1977, 459, 30036, 1105, 446, 413, 267, 5689, 459, 27429, 418, 275, 1109, 8, 1977, 459, 27429, 1105, 446, 413, 267, 340, 283, 2064, 7 ]
[ 27103, 199, 3, 1898, 7800, 653, 281, 86, 6738, 15285, 3277, 14, 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, 3, 27103, 199, 646, 2022, 199, 646, 5739, 199, 646, 5055, 199, 646, 747, 199, 504, 747, 14, 515, 492, 4263, 199, 646, 2748, 14, 9464, 14, 15325, 465, 10844, 199, 504, 5055, 492, 10018, 199, 646, 7534, 421, 199, 3, 1455, 921, 23153, 14, 957, 15, 16069, 15, 2114, 1349, 11769, 15, 6435, 1337, 13, 1652, 13, 475, 13, 9086, 13, 4941, 13, 2108, 2350, 199, 318, 7559, 63, 475, 63, 807, 8, 84, 304, 272, 366, 275, 469, 84, 14, 1450, 26, 1052, 340, 307, 14, 6640, 587, 488, 93, 272, 4978, 275, 769, 8, 84, 9, 272, 340, 4978, 26, 267, 13972, 275, 10018, 8, 513, 9, 267, 367, 12326, 315, 2341, 8, 9464, 63, 475, 63, 807, 12, 4978, 304, 288, 367, 1022, 12, 373, 315, 12326, 14, 1744, 837, 355, 13972, 59, 75, 1055, 740, 8, 86, 9, 267, 366, 275, 469, 84, 14, 1450, 26, 469, 75, 26, 373, 59, 16, 61, 340, 822, 8, 86, 9, 508, 413, 587, 373, 367, 1022, 12, 373, 315, 13972, 14, 1744, 342, 4863, 272, 340, 307, 14, 6640, 26, 267, 366, 59, 84, 14, 1450, 1055, 873, 4725, 32, 7, 435, 1022, 12, 373, 9, 367, 1022, 12, 373, 315, 307, 14, 6640, 14, 1744, 1012, 272, 340, 307, 14, 505, 26, 267, 1318, 275, 307, 14, 505, 14, 1913, 342, 267, 340, 4978, 503, 307, 14, 6640, 26, 288, 340, 1318, 26, 355, 366, 59, 84, 14, 1450, 2733, 3, 505, 418, 275, 1318, 267, 587, 26, 288, 366, 59, 84, 14, 1450, 61, 275, 1318, 272, 372, 366, 421, 199, 318, 4107, 63, 2343, 8, 743, 468, 12, 570, 304, 272, 5689, 513, 275, 5225, 468, 459, 785, 418, 272, 340, 440, 1228, 8, 1977, 513, 12, 5055, 14, 5826, 304, 267, 870, 11117, 16, 93, 365, 440, 282, 3414, 1959, 908, 8, 493, 9, 267, 372, 756, 339, 1478, 275, 378, 272, 367, 5689, 315, 5689, 513, 26, 267, 340, 283, 2064, 7, 315, 5689, 26, 288, 4184, 275, 5689, 459, 2064, 418, 288, 340, 440, 1228, 8, 4181, 12, 5055, 14, 5826, 304, 355, 870, 360, 4181, 469, 16, 93, 365, 440, 282, 3414, 1959, 908, 8, 493, 9, 355, 372, 756, 267, 1478, 847, 413, 272, 372, 715, 421, 199, 318, 3957, 63, 1652, 63, 475, 63, 1001, 8, 1210, 63, 515, 12, 1072, 63, 515, 12, 29870, 304, 339, 340, 440, 747, 14, 515, 14, 2444, 8, 1199, 63, 515, 304, 267, 747, 14, 8347, 8, 1199, 63, 515, 9, 272, 1454, 1725, 275, 5739, 14, 6463, 8, 904, 8, 1210, 63, 515, 12, 11937, 1652, 1333, 272, 1454, 1725, 14, 3191, 342, 272, 367, 570, 315, 1454, 1725, 26, 267, 4386, 275, 4263, 8, 1199, 63, 515, 12, 747, 14, 515, 14, 4846, 8, 493, 430, 267, 4386, 275, 747, 14, 515, 14, 7973, 8, 4984, 2788, 16, 61, 435, 1987, 1001, 7, 267, 24196, 275, 2198, 63, 4780, 63, 493, 8, 904, 8, 1210, 63, 515, 12, 570, 395, 29870, 9, 267, 340, 4107, 63, 2343, 8, 12263, 3594, 12, 570, 304, 288, 754, 275, 2022, 14, 4180, 8, 12263, 3594, 12, 4069, 63, 1612, 29, 549, 12, 4363, 29, 20, 12, 17658, 2687, 23324, 7596, 20005, 288, 289, 275, 1551, 8, 4984, 12, 283, 87, 358, 288, 289, 14, 952, 8, 1099, 9, 267, 587, 26, 288, 870, 360, 705, 6057, 3341, 469, 16, 93, 1959, 908, 8, 493, 9, 421, 199, 318, 2198, 63, 4780, 63, 493, 8, 515, 12, 29870, 304, 272, 3123, 275, 10844, 14, 1122, 8, 515, 9, 272, 1738, 275, 3123, 14, 24544, 342, 272, 366, 275, 7559, 63, 475, 63, 807, 8, 1231, 9, 272, 24196, 275, 366, 459, 9340, 418, 272, 312, 513, 275, 24196, 459, 785, 418, 272, 340, 440, 1228, 8, 79, 513, 12, 5055, 14, 5826, 304, 267, 24196, 459, 785, 418, 275, 359, 79, 513, 61, 267, 312, 513, 275, 24196, 459, 785, 418, 272, 1568, 275, 24196, 459, 890, 418, 339, 327, 2654, 1015, 1329, 370, 2022, 272, 24196, 459, 1023, 418, 275, 791, 8452, 356, 413, 12, 283, 11067, 356, 378, 93, 339, 327, 3957, 1006, 5579, 687, 1059, 6025, 370, 1329, 880, 2022, 1630, 440, 6313, 3062, 272, 327, 1006, 402, 314, 16842, 5689, 5579, 787, 1373, 4079, 880, 24129, 413, 272, 1568, 459, 2063, 418, 275, 1109, 8, 890, 459, 2063, 1105, 272, 1568, 459, 3333, 418, 275, 1109, 8, 890, 459, 3333, 1105, 272, 1568, 459, 4631, 418, 275, 1109, 8, 890, 459, 4631, 1105, 272, 3462, 275, 24196, 459, 890, 2545, 2063, 418, 272, 4569, 275, 24196, 459, 890, 2545, 3333, 418, 272, 367, 1559, 315, 312, 513, 26, 267, 1559, 459, 7330, 1792, 427, 418, 275, 1109, 8, 1113, 459, 7330, 1792, 427, 1105, 1137, 378, 267, 1559, 459, 19347, 418, 275, 1109, 8, 1113, 459, 19347, 1105, 1137, 378, 267, 5689, 275, 1559, 459, 66, 977, 1977, 418, 267, 5689, 459, 28961, 418, 275, 1109, 8, 1977, 459, 28961, 1105, 446, 413, 267, 5689, 459, 21601, 418, 275, 1109, 8, 1977, 459, 21601, 1105, 446, 413, 267, 5689, 459, 30036, 418, 275, 1109, 8, 1977, 459, 30036, 1105, 446, 413, 267, 5689, 459, 27429, 418, 275, 1109, 8, 1977, 459, 27429, 1105, 446, 413, 267, 340, 283, 2064, 7, 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,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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 ]
odoomrp/odoomrp-utils
stock_incoterm_extension/models/account_invoice.py
2
1915
# -*- 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/>. # ############################################################################## from openerp import models, fields, api class AccountInvoice(models.Model): _inherit = 'account.invoice' @api.model def _get_selection_transport_type(self): return self.env['sale.order'].fields_get( allfields=['transport_type'])['transport_type']['selection'] incoterm = fields.Many2one('stock.incoterms', string="Incoterm") req_destination_port = fields.Boolean(string="Requires destination port", related="incoterm.destination_port") req_transport_type = fields.Boolean(string="Requires transport type", related="incoterm.transport_type") destination_port = fields.Char(string="Destination port") transport_type = fields.Selection( selection='_get_selection_transport_type', string="Transport type") @api.onchange('incoterm') def _onchange_incoterm(self): for invoice in self: invoice.destination_port = ( invoice.incoterm.default_destination_port)
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 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, 492, 1709, 12, 1504, 12, 2986, 421, 199, 533, 9973, 21092, 8, 992, 14, 1685, 304, 339, 485, 6486, 275, 283, 2048, 14, 5404, 7, 339, 768, 1246, 14, 1238, 272, 347, 485, 362, 63, 5592, 63, 5545, 63, 466, 8, 277, 304, 267, 372, 291, 14, 1813, 459, 8515, 14, 1648, 2278, 955, 63, 362, 8, 288, 741, 24603, 83, 2968, 5545, 63, 466, 1105, 459, 5545, 63, 466, 2545, 5592, 418, 339, 315, 331, 5125, 275, 1504, 14, 4089, 18, 368, 360, 6088, 14, 262, 331, 9187, 297, 1059, 628, 607, 331, 5125, 531, 272, 2648, 63, 6881, 63, 719, 275, 1504, 14, 4082, 8, 875, 628, 18153, 5724, 1844, 401, 5101, 4048, 628, 262, 331, 5125, 14, 6881, 63, 719, 531, 272, 2648, 63, 5545, 63, 466, 275, 1504, 14, 4082, 8, 875, 628, 18153, 7773, 730, 401, 3147, 4048, 628, 262, 331, 5125, 14, 5545, 63, 466, 531, 272, 5724, 63, 719, 275, 1504, 14, 1610, 8, 875, 628, 13151, 1844, 531, 272, 7773, 63, 466, 275, 1504, 14, 7713, 8, 267, 7267, 17574, 362, 63, 5592, 63, 5545, 63, 466, 297, 1059, 628, 7836, 730, 531, 339, 768, 1246, 14, 18128, 360, 262, 331, 5125, 358, 272, 347, 485, 18128, 63, 262, 331, 5125, 8, 277, 304, 267, 367, 8485, 315, 291, 26, 288, 8485, 14, 6881, 63, 719, 275, 334, 355, 8485, 14, 262, 331, 5125, 14, 885, 63, 6881, 63, 719, 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 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 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, 492, 1709, 12, 1504, 12, 2986, 421, 199, 533, 9973, 21092, 8, 992, 14, 1685, 304, 339, 485, 6486, 275, 283, 2048, 14, 5404, 7, 339, 768, 1246, 14, 1238, 272, 347, 485, 362, 63, 5592, 63, 5545, 63, 466, 8, 277, 304, 267, 372, 291, 14, 1813, 459, 8515, 14, 1648, 2278, 955, 63, 362, 8, 288, 741, 24603, 83, 2968, 5545, 63, 466, 1105, 459, 5545, 63, 466, 2545, 5592, 418, 339, 315, 331, 5125, 275, 1504, 14, 4089, 18, 368, 360, 6088, 14, 262, 331, 9187, 297, 1059, 628, 607, 331, 5125, 531, 272, 2648, 63, 6881, 63, 719, 275, 1504, 14, 4082, 8, 875, 628, 18153, 5724, 1844, 401, 5101, 4048, 628, 262, 331, 5125, 14, 6881, 63, 719, 531, 272, 2648, 63, 5545, 63, 466, 275, 1504, 14, 4082, 8, 875, 628, 18153, 7773, 730, 401, 3147, 4048, 628, 262, 331, 5125, 14, 5545, 63, 466, 531, 272, 5724, 63, 719, 275, 1504, 14, 1610, 8, 875, 628, 13151, 1844, 531, 272, 7773, 63, 466, 275, 1504, 14, 7713, 8, 267, 7267, 17574, 362, 63, 5592, 63, 5545, 63, 466, 297, 1059, 628, 7836, 730, 531, 339, 768, 1246, 14, 18128, 360, 262, 331, 5125, 358, 272, 347, 485, 18128, 63, 262, 331, 5125, 8, 277, 304, 267, 367, 8485, 315, 291, 26, 288, 8485, 14, 6881, 63, 719, 275, 334, 355, 8485, 14, 262, 331, 5125, 14, 885, 63, 6881, 63, 719, 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, 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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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 ]
lazycoder-ru/pelican
pelican/cache.py
25
5247
# -*- coding: utf-8 -*- from __future__ import unicode_literals import hashlib import logging import os from six.moves import cPickle as pickle from pelican.utils import mkdir_p logger = logging.getLogger(__name__) class FileDataCacher(object): """Class that can cache data contained in files""" def __init__(self, settings, cache_name, caching_policy, load_policy): """Load the specified cache within CACHE_PATH in settings only if *load_policy* is True, May use gzip if GZIP_CACHE ins settings is True. Sets caching policy according to *caching_policy*. """ self.settings = settings self._cache_path = os.path.join(self.settings['CACHE_PATH'], cache_name) self._cache_data_policy = caching_policy if self.settings['GZIP_CACHE']: import gzip self._cache_open = gzip.open else: self._cache_open = open if load_policy: try: with self._cache_open(self._cache_path, 'rb') as fhandle: self._cache = pickle.load(fhandle) except (IOError, OSError) as err: logger.debug('Cannot load cache %s (this is normal on first ' 'run). Proceeding with empty cache.\n%s', self._cache_path, err) self._cache = {} except pickle.PickleError as err: logger.warning('Cannot unpickle cache %s, cache may be using ' 'an incompatible protocol (see pelican ' 'caching docs). ' 'Proceeding with empty cache.\n%s', self._cache_path, err) self._cache = {} else: self._cache = {} def cache_data(self, filename, data): """Cache data for given file""" if self._cache_data_policy: self._cache[filename] = data def get_cached_data(self, filename, default=None): """Get cached data for the given file if no data is cached, return the default object """ return self._cache.get(filename, default) def save_cache(self): """Save the updated cache""" if self._cache_data_policy: try: mkdir_p(self.settings['CACHE_PATH']) with self._cache_open(self._cache_path, 'wb') as fhandle: pickle.dump(self._cache, fhandle) except (IOError, OSError, pickle.PicklingError) as err: logger.warning('Could not save cache %s\n ... %s', self._cache_path, err) class FileStampDataCacher(FileDataCacher): """Subclass that also caches the stamp of the file""" def __init__(self, settings, cache_name, caching_policy, load_policy): """This sublcass additionally sets filestamp function and base path for filestamping operations """ super(FileStampDataCacher, self).__init__(settings, cache_name, caching_policy, load_policy) method = self.settings['CHECK_MODIFIED_METHOD'] if method == 'mtime': self._filestamp_func = os.path.getmtime else: try: hash_func = getattr(hashlib, method) def filestamp_func(filename): """return hash of file contents""" with open(filename, 'rb') as fhandle: return hash_func(fhandle.read()).digest() self._filestamp_func = filestamp_func except AttributeError as err: logger.warning('Could not get hashing function\n\t%s', err) self._filestamp_func = None def cache_data(self, filename, data): """Cache stamp and data for the given file""" stamp = self._get_file_stamp(filename) super(FileStampDataCacher, self).cache_data(filename, (stamp, data)) def _get_file_stamp(self, filename): """Check if the given file has been modified since the previous build. depending on CHECK_MODIFIED_METHOD a float may be returned for 'mtime', a hash for a function name in the hashlib module or an empty bytes string otherwise """ try: return self._filestamp_func(filename) except (IOError, OSError, TypeError) as err: logger.warning('Cannot get modification stamp for %s\n\t%s', filename, err) return '' def get_cached_data(self, filename, default=None): """Get the cached data for the given filename if the file has not been modified. If no record exists or file has been modified, return default. Modification is checked by comparing the cached and current file stamp. """ stamp, data = super(FileStampDataCacher, self).get_cached_data( filename, (None, default)) if stamp != self._get_file_stamp(filename): return default return data
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 8337, 199, 646, 2050, 199, 646, 747, 199, 199, 504, 3816, 14, 4912, 492, 17572, 465, 5927, 199, 199, 504, 4837, 28091, 14, 1208, 492, 20366, 63, 80, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 3814, 1451, 35, 19728, 8, 785, 304, 272, 408, 2543, 626, 883, 2581, 666, 10470, 315, 1584, 624, 339, 347, 636, 826, 721, 277, 12, 2202, 12, 2581, 63, 354, 12, 13627, 63, 3185, 12, 2248, 63, 3185, 304, 267, 408, 6200, 314, 2013, 2581, 4453, 7240, 4576, 63, 3243, 315, 2202, 398, 1454, 340, 627, 912, 63, 3185, 10, 365, 715, 12, 267, 10162, 675, 11756, 340, 598, 16977, 63, 8677, 5261, 2202, 365, 715, 14, 267, 10729, 13627, 4592, 7182, 370, 627, 22738, 63, 3185, 4856, 267, 408, 267, 291, 14, 1751, 275, 2202, 267, 291, 423, 1637, 63, 515, 275, 747, 14, 515, 14, 904, 8, 277, 14, 1751, 459, 8677, 63, 3243, 995, 3147, 2581, 63, 354, 9, 267, 291, 423, 1637, 63, 576, 63, 3185, 275, 13627, 63, 3185, 267, 340, 291, 14, 1751, 459, 39, 16977, 63, 8677, 2565, 288, 492, 11756, 288, 291, 423, 1637, 63, 1490, 275, 11756, 14, 1490, 267, 587, 26, 288, 291, 423, 1637, 63, 1490, 275, 1551, 267, 340, 2248, 63, 3185, 26, 288, 862, 26, 355, 543, 291, 423, 1637, 63, 1490, 8, 277, 423, 1637, 63, 515, 12, 283, 4848, 358, 465, 289, 2479, 26, 490, 291, 423, 1637, 275, 5927, 14, 912, 8, 70, 2479, 9, 288, 871, 334, 13760, 12, 6440, 9, 465, 2329, 26, 355, 2512, 14, 1757, 360, 6612, 2248, 2581, 450, 83, 334, 3749, 365, 3293, 641, 1642, 283, 2490, 283, 1065, 680, 2165, 15648, 316, 543, 2701, 2581, 3134, 78, 5, 83, 297, 2490, 291, 423, 1637, 63, 515, 12, 2329, 9, 355, 291, 423, 1637, 275, 1052, 288, 871, 5927, 14, 12755, 547, 465, 2329, 26, 355, 2512, 14, 3764, 360, 6612, 625, 8092, 2581, 450, 83, 12, 2581, 1443, 506, 1808, 283, 3044, 283, 290, 18457, 4113, 334, 3239, 4837, 28091, 283, 3044, 283, 22738, 9149, 680, 283, 3044, 283, 919, 15648, 316, 543, 2701, 2581, 3134, 78, 5, 83, 297, 3044, 291, 423, 1637, 63, 515, 12, 2329, 9, 355, 291, 423, 1637, 275, 1052, 267, 587, 26, 288, 291, 423, 1637, 275, 1052, 339, 347, 2581, 63, 576, 8, 277, 12, 1788, 12, 666, 304, 267, 408, 4437, 666, 367, 1627, 570, 624, 267, 340, 291, 423, 1637, 63, 576, 63, 3185, 26, 288, 291, 423, 1637, 59, 1501, 61, 275, 666, 339, 347, 664, 63, 5245, 63, 576, 8, 277, 12, 1788, 12, 849, 29, 403, 304, 267, 408, 1002, 6328, 666, 367, 314, 1627, 570, 398, 340, 949, 666, 365, 6328, 12, 372, 314, 849, 909, 267, 408, 267, 372, 291, 423, 1637, 14, 362, 8, 1501, 12, 849, 9, 339, 347, 3354, 63, 1637, 8, 277, 304, 267, 408, 8229, 314, 4588, 2581, 624, 267, 340, 291, 423, 1637, 63, 576, 63, 3185, 26, 288, 862, 26, 355, 20366, 63, 80, 8, 277, 14, 1751, 459, 8677, 63, 3243, 1105, 355, 543, 291, 423, 1637, 63, 1490, 8, 277, 423, 1637, 63, 515, 12, 283, 6603, 358, 465, 289, 2479, 26, 490, 5927, 14, 2724, 8, 277, 423, 1637, 12, 289, 2479, 9, 288, 871, 334, 13760, 12, 6440, 12, 5927, 14, 8587, 2983, 547, 9, 465, 2329, 26, 355, 2512, 14, 3764, 360, 6531, 440, 3354, 2581, 450, 83, 60, 78, 2263, 450, 83, 297, 3044, 291, 423, 1637, 63, 515, 12, 2329, 9, 421, 199, 533, 3814, 16649, 1451, 35, 19728, 8, 1173, 1451, 35, 19728, 304, 272, 408, 23636, 626, 2597, 18014, 314, 16206, 402, 314, 570, 624, 339, 347, 636, 826, 721, 277, 12, 2202, 12, 2581, 63, 354, 12, 13627, 63, 3185, 12, 2248, 63, 3185, 304, 267, 408, 2765, 1007, 10181, 405, 10234, 1183, 5951, 570, 2359, 805, 267, 436, 1300, 931, 367, 570, 2359, 316, 5331, 267, 408, 398, 1613, 8, 1173, 16649, 1451, 35, 19728, 12, 291, 2843, 826, 721, 1751, 12, 2581, 63, 354, 12, 8179, 13627, 63, 3185, 12, 8179, 2248, 63, 3185, 9, 398, 1083, 275, 291, 14, 1751, 459, 8936, 63, 30389, 63, 9977, 418, 267, 340, 1083, 508, 283, 8180, 356, 288, 291, 423, 493, 2359, 63, 1532, 275, 747, 14, 515, 14, 26628, 267, 587, 26, 288, 862, 26, 355, 2631, 63, 1532, 275, 2519, 8, 24722, 12, 1083, 9, 2234, 347, 570, 2359, 63, 1532, 8, 1501, 304, 490, 408, 1107, 2631, 402, 570, 4072, 624, 490, 543, 1551, 8, 1501, 12, 283, 4848, 358, 465, 289, 2479, 26, 717, 372, 2631, 63, 1532, 8, 70, 2479, 14, 739, 8801, 5671, 342, 2234, 291, 423, 493, 2359, 63, 1532, 275, 570, 2359, 63, 1532, 288, 871, 4281, 465, 2329, 26, 355, 2512, 14, 3764, 360, 6531, 440, 664, 25223, 805, 60, 78, 60, 84, 5, 83, 297, 2329, 9, 355, 291, 423, 493, 2359, 63, 1532, 275, 488, 339, 347, 2581, 63, 576, 8, 277, 12, 1788, 12, 666, 304, 267, 408, 4437, 16206, 436, 666, 367, 314, 1627, 570, 624, 267, 16206, 275, 291, 423, 362, 63, 493, 63, 2359, 8, 1501, 9, 267, 1613, 8, 1173, 16649, 1451, 35, 19728, 12, 291, 680, 1637, 63, 576, 8, 1501, 12, 334, 2359, 12, 666, 430, 339, 347, 485, 362, 63, 493, 63, 2359, 8, 277, 12, 1788, 304, 267, 408, 1799, 340, 314, 1627, 570, 965, 2757, 6042, 267, 3967, 314, 4136, 1900, 14, 398, 10298, 641, 17654, 63, 30389, 63, 9977, 267, 282, 2069, 1443, 506, 2138, 367, 283, 8180, 297, 267, 282, 2631, 367, 282, 805, 536, 315, 314, 8337, 859, 267, 503, 376, 2701, 2783, 1059, 4257, 267, 408, 398, 862, 26, 288, 372, 291, 423, 493, 2359, 63, 1532, 8, 1501, 9, 267, 871, 334, 13760, 12, 6440, 12, 3146, 9, 465, 2329, 26, 288, 2512, 14, 3764, 360, 6612, 664, 7100, 16206, 367, 450, 83, 60, 78, 60, 84, 5, 83, 297, 2574, 1788, 12 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 8337, 199, 646, 2050, 199, 646, 747, 199, 199, 504, 3816, 14, 4912, 492, 17572, 465, 5927, 199, 199, 504, 4837, 28091, 14, 1208, 492, 20366, 63, 80, 199, 199, 2921, 275, 2050, 14, 5572, 3460, 354, 3368, 421, 199, 533, 3814, 1451, 35, 19728, 8, 785, 304, 272, 408, 2543, 626, 883, 2581, 666, 10470, 315, 1584, 624, 339, 347, 636, 826, 721, 277, 12, 2202, 12, 2581, 63, 354, 12, 13627, 63, 3185, 12, 2248, 63, 3185, 304, 267, 408, 6200, 314, 2013, 2581, 4453, 7240, 4576, 63, 3243, 315, 2202, 398, 1454, 340, 627, 912, 63, 3185, 10, 365, 715, 12, 267, 10162, 675, 11756, 340, 598, 16977, 63, 8677, 5261, 2202, 365, 715, 14, 267, 10729, 13627, 4592, 7182, 370, 627, 22738, 63, 3185, 4856, 267, 408, 267, 291, 14, 1751, 275, 2202, 267, 291, 423, 1637, 63, 515, 275, 747, 14, 515, 14, 904, 8, 277, 14, 1751, 459, 8677, 63, 3243, 995, 3147, 2581, 63, 354, 9, 267, 291, 423, 1637, 63, 576, 63, 3185, 275, 13627, 63, 3185, 267, 340, 291, 14, 1751, 459, 39, 16977, 63, 8677, 2565, 288, 492, 11756, 288, 291, 423, 1637, 63, 1490, 275, 11756, 14, 1490, 267, 587, 26, 288, 291, 423, 1637, 63, 1490, 275, 1551, 267, 340, 2248, 63, 3185, 26, 288, 862, 26, 355, 543, 291, 423, 1637, 63, 1490, 8, 277, 423, 1637, 63, 515, 12, 283, 4848, 358, 465, 289, 2479, 26, 490, 291, 423, 1637, 275, 5927, 14, 912, 8, 70, 2479, 9, 288, 871, 334, 13760, 12, 6440, 9, 465, 2329, 26, 355, 2512, 14, 1757, 360, 6612, 2248, 2581, 450, 83, 334, 3749, 365, 3293, 641, 1642, 283, 2490, 283, 1065, 680, 2165, 15648, 316, 543, 2701, 2581, 3134, 78, 5, 83, 297, 2490, 291, 423, 1637, 63, 515, 12, 2329, 9, 355, 291, 423, 1637, 275, 1052, 288, 871, 5927, 14, 12755, 547, 465, 2329, 26, 355, 2512, 14, 3764, 360, 6612, 625, 8092, 2581, 450, 83, 12, 2581, 1443, 506, 1808, 283, 3044, 283, 290, 18457, 4113, 334, 3239, 4837, 28091, 283, 3044, 283, 22738, 9149, 680, 283, 3044, 283, 919, 15648, 316, 543, 2701, 2581, 3134, 78, 5, 83, 297, 3044, 291, 423, 1637, 63, 515, 12, 2329, 9, 355, 291, 423, 1637, 275, 1052, 267, 587, 26, 288, 291, 423, 1637, 275, 1052, 339, 347, 2581, 63, 576, 8, 277, 12, 1788, 12, 666, 304, 267, 408, 4437, 666, 367, 1627, 570, 624, 267, 340, 291, 423, 1637, 63, 576, 63, 3185, 26, 288, 291, 423, 1637, 59, 1501, 61, 275, 666, 339, 347, 664, 63, 5245, 63, 576, 8, 277, 12, 1788, 12, 849, 29, 403, 304, 267, 408, 1002, 6328, 666, 367, 314, 1627, 570, 398, 340, 949, 666, 365, 6328, 12, 372, 314, 849, 909, 267, 408, 267, 372, 291, 423, 1637, 14, 362, 8, 1501, 12, 849, 9, 339, 347, 3354, 63, 1637, 8, 277, 304, 267, 408, 8229, 314, 4588, 2581, 624, 267, 340, 291, 423, 1637, 63, 576, 63, 3185, 26, 288, 862, 26, 355, 20366, 63, 80, 8, 277, 14, 1751, 459, 8677, 63, 3243, 1105, 355, 543, 291, 423, 1637, 63, 1490, 8, 277, 423, 1637, 63, 515, 12, 283, 6603, 358, 465, 289, 2479, 26, 490, 5927, 14, 2724, 8, 277, 423, 1637, 12, 289, 2479, 9, 288, 871, 334, 13760, 12, 6440, 12, 5927, 14, 8587, 2983, 547, 9, 465, 2329, 26, 355, 2512, 14, 3764, 360, 6531, 440, 3354, 2581, 450, 83, 60, 78, 2263, 450, 83, 297, 3044, 291, 423, 1637, 63, 515, 12, 2329, 9, 421, 199, 533, 3814, 16649, 1451, 35, 19728, 8, 1173, 1451, 35, 19728, 304, 272, 408, 23636, 626, 2597, 18014, 314, 16206, 402, 314, 570, 624, 339, 347, 636, 826, 721, 277, 12, 2202, 12, 2581, 63, 354, 12, 13627, 63, 3185, 12, 2248, 63, 3185, 304, 267, 408, 2765, 1007, 10181, 405, 10234, 1183, 5951, 570, 2359, 805, 267, 436, 1300, 931, 367, 570, 2359, 316, 5331, 267, 408, 398, 1613, 8, 1173, 16649, 1451, 35, 19728, 12, 291, 2843, 826, 721, 1751, 12, 2581, 63, 354, 12, 8179, 13627, 63, 3185, 12, 8179, 2248, 63, 3185, 9, 398, 1083, 275, 291, 14, 1751, 459, 8936, 63, 30389, 63, 9977, 418, 267, 340, 1083, 508, 283, 8180, 356, 288, 291, 423, 493, 2359, 63, 1532, 275, 747, 14, 515, 14, 26628, 267, 587, 26, 288, 862, 26, 355, 2631, 63, 1532, 275, 2519, 8, 24722, 12, 1083, 9, 2234, 347, 570, 2359, 63, 1532, 8, 1501, 304, 490, 408, 1107, 2631, 402, 570, 4072, 624, 490, 543, 1551, 8, 1501, 12, 283, 4848, 358, 465, 289, 2479, 26, 717, 372, 2631, 63, 1532, 8, 70, 2479, 14, 739, 8801, 5671, 342, 2234, 291, 423, 493, 2359, 63, 1532, 275, 570, 2359, 63, 1532, 288, 871, 4281, 465, 2329, 26, 355, 2512, 14, 3764, 360, 6531, 440, 664, 25223, 805, 60, 78, 60, 84, 5, 83, 297, 2329, 9, 355, 291, 423, 493, 2359, 63, 1532, 275, 488, 339, 347, 2581, 63, 576, 8, 277, 12, 1788, 12, 666, 304, 267, 408, 4437, 16206, 436, 666, 367, 314, 1627, 570, 624, 267, 16206, 275, 291, 423, 362, 63, 493, 63, 2359, 8, 1501, 9, 267, 1613, 8, 1173, 16649, 1451, 35, 19728, 12, 291, 680, 1637, 63, 576, 8, 1501, 12, 334, 2359, 12, 666, 430, 339, 347, 485, 362, 63, 493, 63, 2359, 8, 277, 12, 1788, 304, 267, 408, 1799, 340, 314, 1627, 570, 965, 2757, 6042, 267, 3967, 314, 4136, 1900, 14, 398, 10298, 641, 17654, 63, 30389, 63, 9977, 267, 282, 2069, 1443, 506, 2138, 367, 283, 8180, 297, 267, 282, 2631, 367, 282, 805, 536, 315, 314, 8337, 859, 267, 503, 376, 2701, 2783, 1059, 4257, 267, 408, 398, 862, 26, 288, 372, 291, 423, 493, 2359, 63, 1532, 8, 1501, 9, 267, 871, 334, 13760, 12, 6440, 12, 3146, 9, 465, 2329, 26, 288, 2512, 14, 3764, 360, 6612, 664, 7100, 16206, 367, 450, 83, 60, 78, 60, 84, 5, 83, 297, 2574, 1788, 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,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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 ]
PetrDlouhy/django
django/template/engine.py
9
9807
import warnings from django.core.exceptions import ImproperlyConfigured from django.utils import lru_cache, six from django.utils.deprecation import RemovedInDjango20Warning from django.utils.functional import cached_property from django.utils.module_loading import import_string from .base import Context, Template, TemplateDoesNotExist from .context import _builtin_context_processors _context_instance_undefined = object() _dictionary_undefined = object() _dirs_undefined = object() class Engine(object): def __init__(self, dirs=None, app_dirs=False, allowed_include_roots=None, context_processors=None, debug=False, loaders=None, string_if_invalid='', file_charset='utf-8'): if dirs is None: dirs = [] if allowed_include_roots is None: allowed_include_roots = [] if context_processors is None: context_processors = [] if loaders is None: loaders = ['django.template.loaders.filesystem.Loader'] if app_dirs: loaders += ['django.template.loaders.app_directories.Loader'] else: if app_dirs: raise ImproperlyConfigured( "app_dirs must not be set when loaders is defined.") if isinstance(allowed_include_roots, six.string_types): raise ImproperlyConfigured( "allowed_include_roots must be a tuple, not a string.") self.dirs = dirs self.app_dirs = app_dirs self.allowed_include_roots = allowed_include_roots self.context_processors = context_processors self.debug = debug self.loaders = loaders self.string_if_invalid = string_if_invalid self.file_charset = file_charset @staticmethod @lru_cache.lru_cache() def get_default(): """ When only one DjangoTemplates backend is configured, returns it. Raises ImproperlyConfigured otherwise. This is required for preserving historical APIs that rely on a globally available, implicitly configured engine such as: >>> from django.template import Context, Template >>> template = Template("Hello {{ name }}!") >>> context = Context({'name': "world"}) >>> template.render(context) 'Hello world!' """ # Since Engine is imported in django.template and since # DjangoTemplates is a wrapper around this Engine class, # local imports are required to avoid import loops. from django.template import engines from django.template.backends.django import DjangoTemplates django_engines = [engine for engine in engines.all() if isinstance(engine, DjangoTemplates)] if len(django_engines) == 1: # Unwrap the Engine instance inside DjangoTemplates return django_engines[0].engine elif len(django_engines) == 0: raise ImproperlyConfigured( "No DjangoTemplates backend is configured.") else: raise ImproperlyConfigured( "Several DjangoTemplates backends are configured. " "You must select one explicitly.") @cached_property def template_context_processors(self): context_processors = _builtin_context_processors context_processors += tuple(self.context_processors) return tuple(import_string(path) for path in context_processors) @cached_property def template_loaders(self): return self.get_template_loaders(self.loaders) def get_template_loaders(self, template_loaders): loaders = [] for template_loader in template_loaders: loader = self.find_template_loader(template_loader) if loader is not None: loaders.append(loader) return loaders def find_template_loader(self, loader): if isinstance(loader, (tuple, list)): args = list(loader[1:]) loader = loader[0] else: args = [] if isinstance(loader, six.string_types): loader_class = import_string(loader) if getattr(loader_class, '_accepts_engine_in_init', False): args.insert(0, self) else: warnings.warn( "%s inherits from django.template.loader.BaseLoader " "instead of django.template.loaders.base.Loader. " % loader, RemovedInDjango20Warning, stacklevel=2) return loader_class(*args) else: raise ImproperlyConfigured( "Invalid value in template loaders configuration: %r" % loader) def find_template(self, name, dirs=None): for loader in self.template_loaders: try: source, display_name = loader(name, dirs) origin = self.make_origin(display_name, loader, name, dirs) return source, origin except TemplateDoesNotExist: pass raise TemplateDoesNotExist(name) def from_string(self, template_code): """ Returns a compiled Template object for the given template code, handling template inheritance recursively. """ return Template(template_code, engine=self) def get_template(self, template_name, dirs=_dirs_undefined): """ Returns a compiled Template object for the given template name, handling template inheritance recursively. """ if dirs is _dirs_undefined: dirs = None else: warnings.warn( "The dirs argument of get_template is deprecated.", RemovedInDjango20Warning, stacklevel=2) template, origin = self.find_template(template_name, dirs) if not hasattr(template, 'render'): # template needs to be compiled template = Template(template, origin, template_name, engine=self) return template # This method was originally a function defined in django.template.loader. # It was moved here in Django 1.8 when encapsulating the Django template # engine in this Engine class. It's still called by deprecated code but it # will be removed in Django 2.0. It's superseded by a new render_to_string # function in django.template.loader. def render_to_string(self, template_name, context=None, context_instance=_context_instance_undefined, dirs=_dirs_undefined, dictionary=_dictionary_undefined): if context_instance is _context_instance_undefined: context_instance = None else: warnings.warn( "The context_instance argument of render_to_string is " "deprecated.", RemovedInDjango20Warning, stacklevel=2) if dirs is _dirs_undefined: # Do not set dirs to None here to avoid triggering the deprecation # warning in select_template or get_template. pass else: warnings.warn( "The dirs argument of render_to_string is deprecated.", RemovedInDjango20Warning, stacklevel=2) if dictionary is _dictionary_undefined: dictionary = None else: warnings.warn( "The dictionary argument of render_to_string was renamed to " "context.", RemovedInDjango20Warning, stacklevel=2) context = dictionary if isinstance(template_name, (list, tuple)): t = self.select_template(template_name, dirs) else: t = self.get_template(template_name, dirs) if not context_instance: # Django < 1.8 accepted a Context in `context` even though that's # unintended. Preserve this ability but don't rewrap `context`. if isinstance(context, Context): return t.render(context) else: return t.render(Context(context)) if not context: return t.render(context_instance) # Add the context to the context stack, ensuring it gets removed again # to keep the context_instance in the same state it started in. with context_instance.push(context): return t.render(context_instance) def select_template(self, template_name_list, dirs=_dirs_undefined): """ Given a list of template names, returns the first that can be loaded. """ if dirs is _dirs_undefined: # Do not set dirs to None here to avoid triggering the deprecation # warning in get_template. pass else: warnings.warn( "The dirs argument of select_template is deprecated.", RemovedInDjango20Warning, stacklevel=2) if not template_name_list: raise TemplateDoesNotExist("No template names provided") not_found = [] for template_name in template_name_list: try: return self.get_template(template_name, dirs) except TemplateDoesNotExist as exc: if exc.args[0] not in not_found: not_found.append(exc.args[0]) continue # If we get here, none of the templates could be loaded raise TemplateDoesNotExist(', '.join(not_found)) def make_origin(self, display_name, loader, name, dirs): if self.debug and display_name: # Inner import to avoid circular dependency from .loader import LoaderOrigin return LoaderOrigin(display_name, loader, name, dirs) else: return None
bsd-3-clause
[ 646, 3598, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1208, 492, 634, 6558, 63, 1637, 12, 3816, 199, 504, 1639, 14, 1208, 14, 15383, 492, 23687, 1165, 3849, 199, 504, 1639, 14, 1208, 14, 15481, 492, 6328, 63, 1829, 199, 504, 1639, 14, 1208, 14, 578, 63, 8786, 492, 492, 63, 875, 199, 199, 504, 1275, 1095, 492, 9470, 12, 5458, 12, 27193, 199, 504, 1275, 1100, 492, 485, 5351, 63, 1100, 63, 10547, 199, 199, 63, 1100, 63, 842, 63, 10705, 275, 909, 342, 199, 63, 9086, 63, 10705, 275, 909, 342, 199, 63, 3220, 63, 10705, 275, 909, 342, 421, 199, 533, 12580, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 7606, 29, 403, 12, 1145, 63, 3220, 29, 797, 12, 326, 4370, 63, 2613, 63, 12065, 29, 403, 12, 1067, 63, 10547, 29, 403, 12, 326, 3105, 29, 797, 12, 25520, 29, 403, 12, 1059, 63, 692, 63, 3197, 4581, 326, 570, 63, 6043, 534, 1624, 13, 24, 735, 267, 340, 7606, 365, 488, 26, 288, 7606, 275, 942, 267, 340, 4370, 63, 2613, 63, 12065, 365, 488, 26, 288, 4370, 63, 2613, 63, 12065, 275, 942, 267, 340, 1067, 63, 10547, 365, 488, 26, 288, 1067, 63, 10547, 275, 942, 267, 340, 25520, 365, 488, 26, 288, 25520, 275, 788, 1176, 14, 1160, 14, 16370, 14, 11381, 14, 5455, 418, 288, 340, 1145, 63, 3220, 26, 355, 25520, 847, 788, 1176, 14, 1160, 14, 16370, 14, 571, 63, 12629, 14, 5455, 418, 267, 587, 26, 288, 340, 1145, 63, 3220, 26, 355, 746, 11897, 8, 490, 298, 571, 63, 3220, 1471, 440, 506, 663, 1380, 25520, 365, 3247, 2685, 398, 340, 1228, 8, 6541, 63, 2613, 63, 12065, 12, 3816, 14, 875, 63, 1313, 304, 288, 746, 11897, 8, 355, 298, 6541, 63, 2613, 63, 12065, 1471, 506, 282, 2008, 12, 440, 282, 1059, 2685, 398, 291, 14, 3220, 275, 7606, 267, 291, 14, 571, 63, 3220, 275, 1145, 63, 3220, 267, 291, 14, 6541, 63, 2613, 63, 12065, 275, 4370, 63, 2613, 63, 12065, 267, 291, 14, 1100, 63, 10547, 275, 1067, 63, 10547, 267, 291, 14, 1757, 275, 3105, 267, 291, 14, 16370, 275, 25520, 267, 291, 14, 875, 63, 692, 63, 3197, 275, 1059, 63, 692, 63, 3197, 267, 291, 14, 493, 63, 6043, 275, 570, 63, 6043, 339, 768, 4639, 272, 768, 25003, 63, 1637, 14, 25003, 63, 1637, 342, 272, 347, 664, 63, 885, 837, 267, 408, 267, 3979, 1454, 1373, 5634, 17969, 4865, 365, 7526, 12, 2529, 652, 14, 398, 6218, 11897, 4257, 14, 398, 961, 365, 1415, 367, 876, 14717, 32530, 15913, 626, 19687, 641, 282, 267, 26662, 2808, 12, 19796, 7526, 6869, 4066, 465, 26, 398, 1306, 687, 1639, 14, 1160, 492, 9470, 12, 5458, 267, 1306, 1978, 275, 5458, 480, 6257, 8448, 536, 3586, 9124, 267, 1306, 1067, 275, 9470, 3252, 354, 356, 298, 7617, 5984, 267, 1306, 1978, 14, 3352, 8, 1100, 9, 267, 283, 6257, 6701, 11213, 267, 408, 267, 327, 9336, 12580, 365, 8439, 315, 1639, 14, 1160, 436, 3967, 267, 327, 5634, 17969, 365, 282, 4975, 6818, 642, 12580, 1021, 12, 267, 327, 2257, 8925, 787, 1415, 370, 5126, 492, 17222, 14, 267, 687, 1639, 14, 1160, 492, 28156, 267, 687, 1639, 14, 1160, 14, 7765, 14, 1176, 492, 5634, 17969, 267, 1639, 63, 30378, 275, 359, 3908, 367, 6869, 315, 28156, 14, 452, 342, 2079, 340, 1228, 8, 3908, 12, 5634, 17969, 1874, 267, 340, 822, 8, 1176, 63, 30378, 9, 508, 413, 26, 288, 327, 1910, 3823, 314, 12580, 1256, 6272, 5634, 17969, 288, 372, 1639, 63, 30378, 59, 16, 1055, 3908, 267, 916, 822, 8, 1176, 63, 30378, 9, 508, 378, 26, 288, 746, 11897, 8, 355, 298, 1944, 5634, 17969, 4865, 365, 7526, 2685, 267, 587, 26, 288, 746, 11897, 8, 355, 298, 1513, 422, 279, 5634, 17969, 14745, 787, 7526, 14, 298, 355, 298, 5556, 1471, 3504, 1373, 7662, 2685, 339, 768, 5245, 63, 1829, 272, 347, 1978, 63, 1100, 63, 10547, 8, 277, 304, 267, 1067, 63, 10547, 275, 485, 5351, 63, 1100, 63, 10547, 267, 1067, 63, 10547, 847, 2008, 8, 277, 14, 1100, 63, 10547, 9, 267, 372, 2008, 8, 646, 63, 875, 8, 515, 9, 367, 931, 315, 1067, 63, 10547, 9, 339, 768, 5245, 63, 1829, 272, 347, 1978, 63, 16370, 8, 277, 304, 267, 372, 291, 14, 362, 63, 1160, 63, 16370, 8, 277, 14, 16370, 9, 339, 347, 664, 63, 1160, 63, 16370, 8, 277, 12, 1978, 63, 16370, 304, 267, 25520, 275, 942, 267, 367, 1978, 63, 3422, 315, 1978, 63, 16370, 26, 288, 5077, 275, 291, 14, 1623, 63, 1160, 63, 3422, 8, 1160, 63, 3422, 9, 288, 340, 5077, 365, 440, 488, 26, 355, 25520, 14, 740, 8, 3422, 9, 267, 372, 25520, 339, 347, 2342, 63, 1160, 63, 3422, 8, 277, 12, 5077, 304, 267, 340, 1228, 8, 3422, 12, 334, 2960, 12, 769, 2298, 288, 1249, 275, 769, 8, 3422, 59, 17, 5728, 288, 5077, 275, 5077, 59, 16, 61, 267, 587, 26, 288, 1249, 275, 942, 398, 340, 1228, 8, 3422, 12, 3816, 14, 875, 63, 1313, 304, 288, 5077, 63, 533, 275, 492, 63, 875, 8, 3422, 9, 953, 340, 2519, 8, 3422, 63, 533, 12, 2513, 27692, 63, 3908, 63, 262, 63, 826, 297, 756, 304, 355, 1249, 14, 3176, 8, 16, 12, 291, 9, 288, 587, 26, 355, 3598, 14, 4050, 8, 490, 2071, 83, 21592, 687, 1639, 14, 1160, 14, 3422, 14, 1563, 5455, 298, 490, 298, 23145, 402, 1639, 14, 1160, 14, 16370, 14, 1095, 14, 5455, 14, 298, 450, 490, 5077, 12, 23687, 1165, 3849, 12, 13232, 29, 18, 9, 953, 372, 5077, 63, 533, 2031, 589, 9, 267, 587, 26, 288, 746, 11897, 8, 355, 298, 3364, 574, 315, 1978, 25520, 2897, 26, 450, 82, 2, 450, 5077, 9, 339, 347, 2342, 63, 1160, 8, 277, 12, 536, 12, 7606, 29, 403, 304, 267, 367, 5077, 315, 291, 14, 1160, 63, 16370, 26, 288, 862, 26, 355, 1350, 12, 2929, 63, 354, 275, 5077, 8, 354, 12, 7606, 9, 355, 6330, 275, 291 ]
[ 3598, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1208, 492, 634, 6558, 63, 1637, 12, 3816, 199, 504, 1639, 14, 1208, 14, 15383, 492, 23687, 1165, 3849, 199, 504, 1639, 14, 1208, 14, 15481, 492, 6328, 63, 1829, 199, 504, 1639, 14, 1208, 14, 578, 63, 8786, 492, 492, 63, 875, 199, 199, 504, 1275, 1095, 492, 9470, 12, 5458, 12, 27193, 199, 504, 1275, 1100, 492, 485, 5351, 63, 1100, 63, 10547, 199, 199, 63, 1100, 63, 842, 63, 10705, 275, 909, 342, 199, 63, 9086, 63, 10705, 275, 909, 342, 199, 63, 3220, 63, 10705, 275, 909, 342, 421, 199, 533, 12580, 8, 785, 304, 339, 347, 636, 826, 721, 277, 12, 7606, 29, 403, 12, 1145, 63, 3220, 29, 797, 12, 326, 4370, 63, 2613, 63, 12065, 29, 403, 12, 1067, 63, 10547, 29, 403, 12, 326, 3105, 29, 797, 12, 25520, 29, 403, 12, 1059, 63, 692, 63, 3197, 4581, 326, 570, 63, 6043, 534, 1624, 13, 24, 735, 267, 340, 7606, 365, 488, 26, 288, 7606, 275, 942, 267, 340, 4370, 63, 2613, 63, 12065, 365, 488, 26, 288, 4370, 63, 2613, 63, 12065, 275, 942, 267, 340, 1067, 63, 10547, 365, 488, 26, 288, 1067, 63, 10547, 275, 942, 267, 340, 25520, 365, 488, 26, 288, 25520, 275, 788, 1176, 14, 1160, 14, 16370, 14, 11381, 14, 5455, 418, 288, 340, 1145, 63, 3220, 26, 355, 25520, 847, 788, 1176, 14, 1160, 14, 16370, 14, 571, 63, 12629, 14, 5455, 418, 267, 587, 26, 288, 340, 1145, 63, 3220, 26, 355, 746, 11897, 8, 490, 298, 571, 63, 3220, 1471, 440, 506, 663, 1380, 25520, 365, 3247, 2685, 398, 340, 1228, 8, 6541, 63, 2613, 63, 12065, 12, 3816, 14, 875, 63, 1313, 304, 288, 746, 11897, 8, 355, 298, 6541, 63, 2613, 63, 12065, 1471, 506, 282, 2008, 12, 440, 282, 1059, 2685, 398, 291, 14, 3220, 275, 7606, 267, 291, 14, 571, 63, 3220, 275, 1145, 63, 3220, 267, 291, 14, 6541, 63, 2613, 63, 12065, 275, 4370, 63, 2613, 63, 12065, 267, 291, 14, 1100, 63, 10547, 275, 1067, 63, 10547, 267, 291, 14, 1757, 275, 3105, 267, 291, 14, 16370, 275, 25520, 267, 291, 14, 875, 63, 692, 63, 3197, 275, 1059, 63, 692, 63, 3197, 267, 291, 14, 493, 63, 6043, 275, 570, 63, 6043, 339, 768, 4639, 272, 768, 25003, 63, 1637, 14, 25003, 63, 1637, 342, 272, 347, 664, 63, 885, 837, 267, 408, 267, 3979, 1454, 1373, 5634, 17969, 4865, 365, 7526, 12, 2529, 652, 14, 398, 6218, 11897, 4257, 14, 398, 961, 365, 1415, 367, 876, 14717, 32530, 15913, 626, 19687, 641, 282, 267, 26662, 2808, 12, 19796, 7526, 6869, 4066, 465, 26, 398, 1306, 687, 1639, 14, 1160, 492, 9470, 12, 5458, 267, 1306, 1978, 275, 5458, 480, 6257, 8448, 536, 3586, 9124, 267, 1306, 1067, 275, 9470, 3252, 354, 356, 298, 7617, 5984, 267, 1306, 1978, 14, 3352, 8, 1100, 9, 267, 283, 6257, 6701, 11213, 267, 408, 267, 327, 9336, 12580, 365, 8439, 315, 1639, 14, 1160, 436, 3967, 267, 327, 5634, 17969, 365, 282, 4975, 6818, 642, 12580, 1021, 12, 267, 327, 2257, 8925, 787, 1415, 370, 5126, 492, 17222, 14, 267, 687, 1639, 14, 1160, 492, 28156, 267, 687, 1639, 14, 1160, 14, 7765, 14, 1176, 492, 5634, 17969, 267, 1639, 63, 30378, 275, 359, 3908, 367, 6869, 315, 28156, 14, 452, 342, 2079, 340, 1228, 8, 3908, 12, 5634, 17969, 1874, 267, 340, 822, 8, 1176, 63, 30378, 9, 508, 413, 26, 288, 327, 1910, 3823, 314, 12580, 1256, 6272, 5634, 17969, 288, 372, 1639, 63, 30378, 59, 16, 1055, 3908, 267, 916, 822, 8, 1176, 63, 30378, 9, 508, 378, 26, 288, 746, 11897, 8, 355, 298, 1944, 5634, 17969, 4865, 365, 7526, 2685, 267, 587, 26, 288, 746, 11897, 8, 355, 298, 1513, 422, 279, 5634, 17969, 14745, 787, 7526, 14, 298, 355, 298, 5556, 1471, 3504, 1373, 7662, 2685, 339, 768, 5245, 63, 1829, 272, 347, 1978, 63, 1100, 63, 10547, 8, 277, 304, 267, 1067, 63, 10547, 275, 485, 5351, 63, 1100, 63, 10547, 267, 1067, 63, 10547, 847, 2008, 8, 277, 14, 1100, 63, 10547, 9, 267, 372, 2008, 8, 646, 63, 875, 8, 515, 9, 367, 931, 315, 1067, 63, 10547, 9, 339, 768, 5245, 63, 1829, 272, 347, 1978, 63, 16370, 8, 277, 304, 267, 372, 291, 14, 362, 63, 1160, 63, 16370, 8, 277, 14, 16370, 9, 339, 347, 664, 63, 1160, 63, 16370, 8, 277, 12, 1978, 63, 16370, 304, 267, 25520, 275, 942, 267, 367, 1978, 63, 3422, 315, 1978, 63, 16370, 26, 288, 5077, 275, 291, 14, 1623, 63, 1160, 63, 3422, 8, 1160, 63, 3422, 9, 288, 340, 5077, 365, 440, 488, 26, 355, 25520, 14, 740, 8, 3422, 9, 267, 372, 25520, 339, 347, 2342, 63, 1160, 63, 3422, 8, 277, 12, 5077, 304, 267, 340, 1228, 8, 3422, 12, 334, 2960, 12, 769, 2298, 288, 1249, 275, 769, 8, 3422, 59, 17, 5728, 288, 5077, 275, 5077, 59, 16, 61, 267, 587, 26, 288, 1249, 275, 942, 398, 340, 1228, 8, 3422, 12, 3816, 14, 875, 63, 1313, 304, 288, 5077, 63, 533, 275, 492, 63, 875, 8, 3422, 9, 953, 340, 2519, 8, 3422, 63, 533, 12, 2513, 27692, 63, 3908, 63, 262, 63, 826, 297, 756, 304, 355, 1249, 14, 3176, 8, 16, 12, 291, 9, 288, 587, 26, 355, 3598, 14, 4050, 8, 490, 2071, 83, 21592, 687, 1639, 14, 1160, 14, 3422, 14, 1563, 5455, 298, 490, 298, 23145, 402, 1639, 14, 1160, 14, 16370, 14, 1095, 14, 5455, 14, 298, 450, 490, 5077, 12, 23687, 1165, 3849, 12, 13232, 29, 18, 9, 953, 372, 5077, 63, 533, 2031, 589, 9, 267, 587, 26, 288, 746, 11897, 8, 355, 298, 3364, 574, 315, 1978, 25520, 2897, 26, 450, 82, 2, 450, 5077, 9, 339, 347, 2342, 63, 1160, 8, 277, 12, 536, 12, 7606, 29, 403, 304, 267, 367, 5077, 315, 291, 14, 1160, 63, 16370, 26, 288, 862, 26, 355, 1350, 12, 2929, 63, 354, 275, 5077, 8, 354, 12, 7606, 9, 355,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 1, 1, 1, 1, 1, 1 ]
ncsulug/ncsulug-website
lug_people/migrations/0003_auto__add_accountrequest.py
1
6919
# -*- 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 model 'AccountRequest' db.create_table('lug_people_accountrequest', ( ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), ('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True)), ('request_date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), ('status', self.gf('django.db.models.fields.CharField')(default=u'pending', max_length=8)), ('comments', self.gf('django.db.models.fields.TextField')()), )) db.send_create_signal('lug_people', ['AccountRequest']) def backwards(self, orm): # Deleting model 'AccountRequest' db.delete_table('lug_people_accountrequest') models = { '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'}) }, 'lug_people.accountrequest': { 'Meta': {'object_name': 'AccountRequest'}, 'comments': ('django.db.models.fields.TextField', [], {}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'request_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'status': ('django.db.models.fields.CharField', [], {'default': "u'pending'", 'max_length': '8'}), 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'}) }, 'lug_people.bit': { 'Meta': {'ordering': "('bit_type__ordering', 'bit_type__caption')", 'object_name': 'Bit'}, 'bit_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lug_people.BitType']"}), 'data': ('django.db.models.fields.CharField', [], {'max_length': '240'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lug_people.MemberProfile']"}) }, 'lug_people.bittype': { 'Meta': {'ordering': "('ordering', 'caption')", 'object_name': 'BitType'}, 'caption': ('django.db.models.fields.CharField', [], {'max_length': '32'}), 'format': ('django.db.models.fields.CharField', [], {'default': "u'freetext'", 'max_length': '8'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'instructions': ('django.db.models.fields.CharField', [], {'max_length': '128'}), 'link_template': ('django.db.models.fields.CharField', [], {'max_length': '240', 'blank': 'True'}), 'ordering': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '16'}) }, 'lug_people.memberprofile': { 'Meta': {'object_name': 'MemberProfile'}, 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'nickname': ('django.db.models.fields.CharField', [], {'max_length': '32'}), 'preferred_name': ('django.db.models.fields.CharField', [], {'default': "u'nick'", 'max_length': '4'}), 'real_name': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}), 'role': ('django.db.models.fields.CharField', [], {'default': "u'visitor'", 'max_length': '8'}), 'title': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}), 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'}) } } complete_apps = ['lug_people']
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, 1402, 283, 6009, 2017, 7, 267, 1592, 14, 981, 63, 1224, 360, 32047, 63, 13562, 63, 2048, 1069, 297, 334, 288, 661, 344, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 7533, 3327, 63, 498, 29, 549, 1826, 288, 661, 751, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 14298, 7533, 475, 29, 1025, 459, 1178, 14, 1899, 995, 3747, 29, 549, 1826, 288, 661, 1069, 63, 602, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 2495, 63, 2131, 63, 525, 29, 549, 12, 4596, 29, 549, 1826, 288, 661, 1205, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 885, 29, 85, 7, 6455, 297, 1390, 63, 1267, 29, 24, 1826, 288, 661, 6223, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 358, 4000, 267, 5082, 267, 1592, 14, 2254, 63, 981, 63, 4653, 360, 32047, 63, 13562, 297, 788, 6009, 2017, 1105, 2378, 347, 8552, 8, 277, 12, 9813, 304, 267, 327, 15920, 1402, 283, 6009, 2017, 7, 267, 1592, 14, 1807, 63, 1224, 360, 32047, 63, 13562, 63, 2048, 1069, 358, 2378, 1709, 275, 469, 267, 283, 1178, 14, 923, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 2448, 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, 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, 1257, 1604, 288, 283, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 3071, 267, 1660, 267, 283, 1178, 14, 5693, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 1317, 63, 466, 363, 571, 63, 1302, 297, 283, 1317, 63, 466, 363, 1238, 297, 283, 11879, 18106, 283, 3235, 63, 6314, 356, 9510, 1317, 63, 466, 297, 283, 11879, 9878, 283, 785, 63, 354, 356, 283, 7980, 2267, 288, 283, 11879, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 1317, 63, 466, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 297, 990, 791, 475, 356, 298, 1025, 459, 10778, 14, 11282, 6097, 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, 988, 63, 1267, 356, 283, 1400, 3071, 267, 1660, 267, 283, 1178, 14, 751, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 1899, 2267, 288, 283, 602, 63, 11806, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2123, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 297, 990, 791, 988, 63, 1267, 356, 283, 2194, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2246, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2634, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 2448, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 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, 374, 63, 2682, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 549, 1604, 288, 283, 374, 63, 7018, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 374, 63, 11434, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 2019, 63, 2886, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2019, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 3933, 1604, 288, 283, 751, 63, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2473, 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, 1216, 3071, 267, 1660, 267, 283, 10778, 14, 20735, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 354, 21099, 283, 3235, 63, 6314, 356, 9510, 571, 63, 1302, 297, 283, 1238, 9878, 283, 785, 63, 354, 356, 283, 11282, 297, 283, 697, 63, 1224, 356, 3546, 1176, 63, 1317, 63, 466, 15208, 288, 283, 571, 63, 1302, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 344, 356, 661, 1176, 14, 697, 14, 992, 14 ]
[ 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, 1402, 283, 6009, 2017, 7, 267, 1592, 14, 981, 63, 1224, 360, 32047, 63, 13562, 63, 2048, 1069, 297, 334, 288, 661, 344, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 7533, 3327, 63, 498, 29, 549, 1826, 288, 661, 751, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 14298, 7533, 475, 29, 1025, 459, 1178, 14, 1899, 995, 3747, 29, 549, 1826, 288, 661, 1069, 63, 602, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 2495, 63, 2131, 63, 525, 29, 549, 12, 4596, 29, 549, 1826, 288, 661, 1205, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 7533, 885, 29, 85, 7, 6455, 297, 1390, 63, 1267, 29, 24, 1826, 288, 661, 6223, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 358, 4000, 267, 5082, 267, 1592, 14, 2254, 63, 981, 63, 4653, 360, 32047, 63, 13562, 297, 788, 6009, 2017, 1105, 2378, 347, 8552, 8, 277, 12, 9813, 304, 267, 327, 15920, 1402, 283, 6009, 2017, 7, 267, 1592, 14, 1807, 63, 1224, 360, 32047, 63, 13562, 63, 2048, 1069, 358, 2378, 1709, 275, 469, 267, 283, 1178, 14, 923, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 2448, 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, 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, 1257, 1604, 288, 283, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 3071, 267, 1660, 267, 283, 1178, 14, 5693, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 1317, 63, 466, 363, 571, 63, 1302, 297, 283, 1317, 63, 466, 363, 1238, 297, 283, 11879, 18106, 283, 3235, 63, 6314, 356, 9510, 1317, 63, 466, 297, 283, 11879, 9878, 283, 785, 63, 354, 356, 283, 7980, 2267, 288, 283, 11879, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 1317, 63, 466, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 297, 990, 791, 475, 356, 298, 1025, 459, 10778, 14, 11282, 6097, 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, 988, 63, 1267, 356, 283, 1400, 3071, 267, 1660, 267, 283, 1178, 14, 751, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 1899, 2267, 288, 283, 602, 63, 11806, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2123, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 297, 990, 791, 988, 63, 1267, 356, 283, 2194, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2246, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2634, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 2448, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 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, 374, 63, 2682, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 549, 1604, 288, 283, 374, 63, 7018, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 374, 63, 11434, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 2019, 63, 2886, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2019, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 3933, 1604, 288, 283, 751, 63, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2473, 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, 1216, 3071, 267, 1660, 267, 283, 10778, 14, 20735, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 354, 21099, 283, 3235, 63, 6314, 356, 9510, 571, 63, 1302, 297, 283, 1238, 9878, 283, 785, 63, 354, 356, 283, 11282, 297, 283, 697, 63, 1224, 356, 3546, 1176, 63, 1317, 63, 466, 15208, 288, 283, 571, 63, 1302, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 344, 356, 661, 1176, 14, 697, 14, 992, 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, 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 ]
Elizaveta239/PyDev.Debugger
tests_python/my_django_proj_17/my_django_proj_17/settings.py
48
2130
""" Django settings for my_django_proj_17 project. For more information on this file, see https://docs.djangoproject.com/en/1.7/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/1.7/ref/settings/ """ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '5_sue9bp&j=45#%_hcx3f34k!qnt$mxfd&7zq@7c7t@sn4_l)b' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True TEMPLATE_DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'my_app', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) ROOT_URLCONF = 'my_django_proj_17.urls' WSGI_APPLICATION = 'my_django_proj_17.wsgi.application' # Database # https://docs.djangoproject.com/en/1.7/ref/settings/#databases # No database for our test. # DATABASES = { # 'default': { # 'ENGINE': 'django.db.backends.sqlite3', # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), # } # } # Internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.7/howto/static-files/ STATIC_URL = '/static/'
epl-1.0
[ 624, 199, 9323, 2202, 367, 3002, 63, 1176, 63, 5468, 63, 1196, 2199, 14, 199, 199, 1858, 1655, 2556, 641, 642, 570, 12, 1937, 199, 2859, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 11299, 15, 1751, 15, 199, 199, 1858, 314, 2615, 769, 402, 2202, 436, 3932, 1338, 12, 1937, 199, 2859, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 1121, 15, 1751, 15, 199, 624, 199, 199, 3, 6516, 3792, 6272, 314, 2199, 2839, 642, 26, 747, 14, 515, 14, 904, 8, 5825, 63, 3022, 12, 19172, 199, 646, 747, 199, 5825, 63, 3022, 275, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 3475, 3460, 493, 8964, 421, 199, 3, 27534, 13, 928, 16367, 2202, 446, 625, 83, 10020, 367, 9920, 199, 3, 1666, 4178, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 21232, 15, 13605, 15, 1074, 513, 15, 199, 199, 3, 24143, 32712, 14750, 26, 4215, 314, 7565, 790, 1202, 315, 9920, 7565, 1, 199, 12961, 63, 3078, 275, 283, 21, 63, 3309, 25, 10913, 6, 74, 29, 2322, 25745, 63, 72, 11859, 19, 70, 1082, 75, 1, 81, 343, 4, 77, 11208, 6, 23, 90, 81, 32, 23, 67, 23, 84, 32, 5167, 20, 63, 76, 9, 66, 7, 199, 199, 3, 24143, 32712, 14750, 26, 2793, 1133, 1255, 543, 3105, 19136, 641, 315, 9920, 1, 199, 5287, 275, 715, 199, 199, 7433, 63, 5287, 275, 715, 199, 199, 17350, 63, 23775, 275, 942, 421, 199, 3, 13515, 5492, 199, 199, 15942, 63, 14219, 275, 334, 272, 283, 1176, 14, 2828, 14, 2113, 297, 272, 283, 1176, 14, 2828, 14, 1178, 297, 272, 283, 1176, 14, 2828, 14, 10778, 297, 272, 283, 1176, 14, 2828, 14, 11676, 297, 272, 283, 1176, 14, 2828, 14, 3431, 297, 272, 283, 1176, 14, 2828, 14, 18373, 297, 272, 283, 1662, 63, 571, 297, 199, 9, 199, 199, 19987, 63, 13748, 275, 334, 272, 283, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 297, 272, 283, 1176, 14, 5754, 14, 2330, 14, 7844, 6608, 297, 272, 283, 1176, 14, 5754, 14, 10088, 14, 13912, 25322, 297, 272, 283, 1176, 14, 2828, 14, 1178, 14, 5754, 14, 10348, 6608, 297, 272, 283, 1176, 14, 2828, 14, 1178, 14, 5754, 14, 4434, 10348, 6608, 297, 272, 283, 1176, 14, 2828, 14, 3431, 14, 5754, 14, 2209, 6608, 297, 272, 283, 1176, 14, 5754, 14, 4891, 19193, 316, 14, 56, 3160, 4558, 6608, 297, 199, 9, 199, 199, 5441, 63, 18125, 275, 283, 1662, 63, 1176, 63, 5468, 63, 1196, 14, 3603, 7, 199, 199, 16828, 63, 24051, 275, 283, 1662, 63, 1176, 63, 5468, 63, 1196, 14, 6508, 14, 3578, 7, 421, 199, 3, 8692, 199, 3, 4178, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 1121, 15, 1751, 12645, 17439, 199, 199, 3, 3091, 3050, 367, 4154, 511, 14, 199, 199, 3, 26931, 21983, 275, 469, 199, 3, 258, 283, 885, 356, 469, 199, 3, 260, 283, 15956, 356, 283, 1176, 14, 697, 14, 7765, 14, 10659, 19, 297, 199, 3, 260, 283, 2339, 356, 747, 14, 515, 14, 904, 8, 5825, 63, 3022, 12, 283, 697, 14, 10659, 19, 659, 199, 3, 258, 789, 199, 3, 789, 199, 199, 3, 28220, 2072, 199, 3, 4178, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 11299, 15, 73, 1085, 78, 15, 199, 199, 13947, 63, 6012, 275, 283, 287, 13, 527, 7, 199, 199, 4961, 63, 15353, 275, 283, 11288, 7, 199, 199, 4701, 63, 41, 1085, 46, 275, 715, 199, 199, 4701, 63, 44, 709, 46, 275, 715, 199, 199, 4701, 63, 14226, 275, 715, 421, 199, 3, 13599, 1584, 334, 14391, 12, 15250, 12, 32658, 9, 199, 3, 4178, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 21232, 15, 1986, 13, 1725, 15, 199, 199, 10449, 63, 2632, 275, 1994, 1986, 4805, 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 ]
[ 199, 9323, 2202, 367, 3002, 63, 1176, 63, 5468, 63, 1196, 2199, 14, 199, 199, 1858, 1655, 2556, 641, 642, 570, 12, 1937, 199, 2859, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 11299, 15, 1751, 15, 199, 199, 1858, 314, 2615, 769, 402, 2202, 436, 3932, 1338, 12, 1937, 199, 2859, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 1121, 15, 1751, 15, 199, 624, 199, 199, 3, 6516, 3792, 6272, 314, 2199, 2839, 642, 26, 747, 14, 515, 14, 904, 8, 5825, 63, 3022, 12, 19172, 199, 646, 747, 199, 5825, 63, 3022, 275, 747, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 3475, 3460, 493, 8964, 421, 199, 3, 27534, 13, 928, 16367, 2202, 446, 625, 83, 10020, 367, 9920, 199, 3, 1666, 4178, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 21232, 15, 13605, 15, 1074, 513, 15, 199, 199, 3, 24143, 32712, 14750, 26, 4215, 314, 7565, 790, 1202, 315, 9920, 7565, 1, 199, 12961, 63, 3078, 275, 283, 21, 63, 3309, 25, 10913, 6, 74, 29, 2322, 25745, 63, 72, 11859, 19, 70, 1082, 75, 1, 81, 343, 4, 77, 11208, 6, 23, 90, 81, 32, 23, 67, 23, 84, 32, 5167, 20, 63, 76, 9, 66, 7, 199, 199, 3, 24143, 32712, 14750, 26, 2793, 1133, 1255, 543, 3105, 19136, 641, 315, 9920, 1, 199, 5287, 275, 715, 199, 199, 7433, 63, 5287, 275, 715, 199, 199, 17350, 63, 23775, 275, 942, 421, 199, 3, 13515, 5492, 199, 199, 15942, 63, 14219, 275, 334, 272, 283, 1176, 14, 2828, 14, 2113, 297, 272, 283, 1176, 14, 2828, 14, 1178, 297, 272, 283, 1176, 14, 2828, 14, 10778, 297, 272, 283, 1176, 14, 2828, 14, 11676, 297, 272, 283, 1176, 14, 2828, 14, 3431, 297, 272, 283, 1176, 14, 2828, 14, 18373, 297, 272, 283, 1662, 63, 571, 297, 199, 9, 199, 199, 19987, 63, 13748, 275, 334, 272, 283, 1176, 14, 2828, 14, 11676, 14, 5754, 14, 4434, 6608, 297, 272, 283, 1176, 14, 5754, 14, 2330, 14, 7844, 6608, 297, 272, 283, 1176, 14, 5754, 14, 10088, 14, 13912, 25322, 297, 272, 283, 1176, 14, 2828, 14, 1178, 14, 5754, 14, 10348, 6608, 297, 272, 283, 1176, 14, 2828, 14, 1178, 14, 5754, 14, 4434, 10348, 6608, 297, 272, 283, 1176, 14, 2828, 14, 3431, 14, 5754, 14, 2209, 6608, 297, 272, 283, 1176, 14, 5754, 14, 4891, 19193, 316, 14, 56, 3160, 4558, 6608, 297, 199, 9, 199, 199, 5441, 63, 18125, 275, 283, 1662, 63, 1176, 63, 5468, 63, 1196, 14, 3603, 7, 199, 199, 16828, 63, 24051, 275, 283, 1662, 63, 1176, 63, 5468, 63, 1196, 14, 6508, 14, 3578, 7, 421, 199, 3, 8692, 199, 3, 4178, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 1121, 15, 1751, 12645, 17439, 199, 199, 3, 3091, 3050, 367, 4154, 511, 14, 199, 199, 3, 26931, 21983, 275, 469, 199, 3, 258, 283, 885, 356, 469, 199, 3, 260, 283, 15956, 356, 283, 1176, 14, 697, 14, 7765, 14, 10659, 19, 297, 199, 3, 260, 283, 2339, 356, 747, 14, 515, 14, 904, 8, 5825, 63, 3022, 12, 283, 697, 14, 10659, 19, 659, 199, 3, 258, 789, 199, 3, 789, 199, 199, 3, 28220, 2072, 199, 3, 4178, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 11299, 15, 73, 1085, 78, 15, 199, 199, 13947, 63, 6012, 275, 283, 287, 13, 527, 7, 199, 199, 4961, 63, 15353, 275, 283, 11288, 7, 199, 199, 4701, 63, 41, 1085, 46, 275, 715, 199, 199, 4701, 63, 44, 709, 46, 275, 715, 199, 199, 4701, 63, 14226, 275, 715, 421, 199, 3, 13599, 1584, 334, 14391, 12, 15250, 12, 32658, 9, 199, 3, 4178, 921, 4757, 14, 14013, 14, 957, 15, 287, 15, 17, 14, 23, 15, 21232, 15, 1986, 13, 1725, 15, 199, 199, 10449, 63, 2632, 275, 1994, 1986, 4805, 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, 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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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 ]
AndrewPeelMV/Blender2.78c
2.78/scripts/addons/add_mesh_extra_objects/mesh_discombobulator.py
2
27573
# GPL # Original Authors: Evan J. Rosky (syrux), Chichiri, Jace Priester # import bpy import random import math from bpy.types import ( Operator, Menu, ) from mathutils import ( Vector, Quaternion, ) # ################### Globals #################### # doprots = True # Datas in which we will build the new discombobulated mesh nPolygons = [] nVerts = [] Verts = [] Polygons = [] dVerts = [] dPolygons = [] i_prots = [] # index of the top polygons on which we'll generate the doodads i_dood_type = [] # type of doodad (given by index of the doodad obj) # ############### Utility Functions ############### # def randnum(a, b): return random.random() * (b - a) + a def randVertex(a, b, c, d, Verts): """Return a vector of a random vertex on a quad-polygon""" i = random.randint(1, 2) A, B, C, D = 0, 0, 0, 0 if(a == 1): A, B, C, D = a, b, c, d else: A, B, C, D = a, d, c, b i = randnum(0.1, 0.9) vecAB = Verts[B] - Verts[A] E = Verts[A] + vecAB * i vecDC = Verts[C] - Verts[D] F = Verts[D] + vecDC * i i = randnum(0.1, 0.9) vecEF = F - E O = E + vecEF * i return O # ################## Protusions #################### # def fill_older_datas(verts, polygon): """ Specifically coded to be called by the function addProtusionToPolygon, its sets up a tuple which contains the vertices from the base and the top of the protusions. """ temp_vertices = [] temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[3]].copy()) temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[3]].copy()) return temp_vertices def extrude_top(temp_vertices, normal, height): """ This function extrude the polygon composed of the four first members of the tuple temp_vertices along the normal multiplied by the height of the extrusion. """ j = 0 while j < 3: temp_vertices[0][j] += normal[j] * height temp_vertices[1][j] += normal[j] * height temp_vertices[2][j] += normal[j] * height temp_vertices[3][j] += normal[j] * height j += 1 def scale_top(temp_vertices, center, normal, height, scale_ratio): """ This function scale the polygon composed of the four first members of the tuple temp_vertices. """ vec1 = [0, 0, 0] vec2 = [0, 0, 0] vec3 = [0, 0, 0] vec4 = [0, 0, 0] j = 0 while j < 3: center[j] += normal[j] * height vec1[j] = temp_vertices[0][j] - center[j] vec2[j] = temp_vertices[1][j] - center[j] vec3[j] = temp_vertices[2][j] - center[j] vec4[j] = temp_vertices[3][j] - center[j] temp_vertices[0][j] = center[j] + vec1[j] * (1 - scale_ratio) temp_vertices[1][j] = center[j] + vec2[j] * (1 - scale_ratio) temp_vertices[2][j] = center[j] + vec3[j] * (1 - scale_ratio) temp_vertices[3][j] = center[j] + vec4[j] * (1 - scale_ratio) j += 1 def add_prot_polygons(temp_vertices): """ Specifically coded to be called by addProtusionToPolygon, this function put the data from the generated protusion at the end the tuples Verts and Polygons, which will later used to generate the final mesh. """ global Verts global Polygons global i_prots findex = len(Verts) Verts += temp_vertices polygontop = [findex + 0, findex + 1, findex + 2, findex + 3] polygon1 = [findex + 0, findex + 1, findex + 5, findex + 4] polygon2 = [findex + 1, findex + 2, findex + 6, findex + 5] polygon3 = [findex + 2, findex + 3, findex + 7, findex + 6] polygon4 = [findex + 3, findex + 0, findex + 4, findex + 7] Polygons.append(polygontop) i_prots.append(len(Polygons) - 1) Polygons.append(polygon1) Polygons.append(polygon2) Polygons.append(polygon3) Polygons.append(polygon4) def addProtusionToPolygon(obpolygon, verts, minHeight, maxHeight, minTaper, maxTaper): """Create a protusion from the polygon "obpolygon" of the original object and use several values sent by the user. It calls in this order the following functions: - fill_older_data; - extrude_top; - scale_top; - add_prot_polygons; """ # some useful variables polygon = obpolygon.vertices tVerts = list(fill_older_datas(verts, polygon)) # list of temp vertices height = randnum(minHeight, maxHeight) # height of generated protusion scale_ratio = randnum(minTaper, maxTaper) # extrude the top polygon extrude_top(tVerts, obpolygon.normal, height) # Now, we scale, the top polygon along its normal scale_top(tVerts, GetPolyCentroid(obpolygon, verts), obpolygon.normal, height, scale_ratio) # Finally, we add the protusions to the list of polygons add_prot_polygons(tVerts) # ################# Divide a polygon ############### # def divide_one(list_polygons, list_vertices, verts, polygon, findex): """ called by divide_polygon, to generate a polygon from one polygon, maybe I could simplify this process """ temp_vertices = [] temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[3]].copy()) list_vertices += temp_vertices list_polygons.append([findex + 0, findex + 1, findex + 2, findex + 3]) def divide_two(list_polygons, list_vertices, verts, polygon, findex): """ called by divide_polygon, to generate two polygons from one polygon and add them to the list of polygons and vertices which form the discombobulated mesh """ temp_vertices = [] temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[3]].copy()) temp_vertices.append((verts[polygon[0]] + verts[polygon[1]]) / 2) temp_vertices.append((verts[polygon[2]] + verts[polygon[3]]) / 2) list_vertices += temp_vertices list_polygons.append([findex + 0, findex + 4, findex + 5, findex + 3]) list_polygons.append([findex + 1, findex + 2, findex + 5, findex + 4]) def divide_three(list_polygons, list_vertices, verts, polygon, findex, center): """ called by divide_polygon, to generate three polygons from one polygon and add them to the list of polygons and vertices which form the discombobulated mesh """ temp_vertices = [] temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[3]].copy()) temp_vertices.append((verts[polygon[0]] + verts[polygon[1]]) / 2) temp_vertices.append((verts[polygon[2]] + verts[polygon[3]]) / 2) temp_vertices.append((verts[polygon[1]] + verts[polygon[2]]) / 2) temp_vertices.append(center.copy()) list_vertices += temp_vertices list_polygons.append([findex + 0, findex + 4, findex + 5, findex + 3]) list_polygons.append([findex + 1, findex + 6, findex + 7, findex + 4]) list_polygons.append([findex + 6, findex + 2, findex + 5, findex + 7]) def divide_four(list_polygons, list_vertices, verts, polygon, findex, center): """ called by divide_polygon, to generate four polygons from one polygon and add them to the list of polygons and vertices which form the discombobulated mesh """ temp_vertices = [] temp_vertices.append(verts[polygon[0]].copy()) temp_vertices.append(verts[polygon[1]].copy()) temp_vertices.append(verts[polygon[2]].copy()) temp_vertices.append(verts[polygon[3]].copy()) temp_vertices.append((verts[polygon[0]] + verts[polygon[1]]) / 2) temp_vertices.append((verts[polygon[2]] + verts[polygon[3]]) / 2) temp_vertices.append((verts[polygon[1]] + verts[polygon[2]]) / 2) temp_vertices.append(center.copy()) temp_vertices.append((verts[polygon[0]] + verts[polygon[3]]) / 2) temp_vertices.append(center.copy()) list_vertices += temp_vertices list_polygons.append([findex + 0, findex + 4, findex + 7, findex + 8]) list_polygons.append([findex + 1, findex + 6, findex + 7, findex + 4]) list_polygons.append([findex + 6, findex + 2, findex + 5, findex + 7]) list_polygons.append([findex + 8, findex + 7, findex + 5, findex + 3]) def dividepolygon(obpolygon, verts, number): """Divide the poly into the wanted number of polygons""" global nPolygons global nVerts poly = obpolygon.vertices if(number == 1): divide_one(nPolygons, nVerts, verts, poly, len(nVerts)) elif(number == 2): divide_two(nPolygons, nVerts, verts, poly, len(nVerts)) elif(number == 3): divide_three(nPolygons, nVerts, verts, poly, len(nVerts), GetPolyCentroid(obpolygon, verts)) elif(number == 4): divide_four(nPolygons, nVerts, verts, poly, len(nVerts), GetPolyCentroid(obpolygon, verts)) # ################## Discombobulate ################ # def GetPolyCentroid(obpolygon, allvertcoords): centroid = Vector((0, 0, 0)) for vindex in obpolygon.vertices: centroid += Vector(allvertcoords[vindex]) centroid /= len(obpolygon.vertices) return centroid def division(obpolygons, verts, sf1, sf2, sf3, sf4): """Function to divide each of the selected polygons""" divide = [] if (sf1): divide.append(1) if (sf2): divide.append(2) if (sf3): divide.append(3) if (sf4): divide.append(4) for poly in obpolygons: if(poly.select is True and len(poly.vertices) == 4): a = random.randint(0, len(divide) - 1) dividepolygon(poly, verts, divide[a]) def protusion(obverts, obpolygons, minHeight, maxHeight, minTaper, maxTaper): """function to generate the protusions""" verts = [] for vertex in obverts: verts.append(vertex.co) for polygon in obpolygons: if(polygon.select is True): if(len(polygon.vertices) == 4): addProtusionToPolygon(polygon, verts, minHeight, maxHeight, minTaper, maxTaper) def test_v2_near_v1(v1, v2): if (v1.x - 0.1 <= v2.x <= v1.x + 0.1 and v1.y - 0.1 <= v2.y <= v1.y + 0.1 and v1.z - 0.1 <= v2.z <= v1.z + 0.1): return True return False def angle_between_nor(nor_orig, nor_result): angle = math.acos(nor_orig.dot(nor_result)) axis = nor_orig.cross(nor_result).normalized() q = Quaternion() q.x = axis.x * math.sin(angle / 2) q.y = axis.y * math.sin(angle / 2) q.z = axis.z * math.sin(angle / 2) q.w = math.cos(angle / 2) return q def doodads(object1, mesh1, dmin, dmax): """function to generate the doodads""" global dVerts global dPolygons i = 0 # on parcoure cette boucle pour ajouter des doodads a toutes les polygons # english translation: this loops adds doodads to all polygons while(i < len(object1.data.polygons)): if object1.data.polygons[i].select is False: continue doods_nbr = random.randint(dmin, dmax) j = 0 while(j <= doods_nbr): origin_dood = randVertex(object1.data.polygons[i].vertices[0], object1.data.polygons[i].vertices[1], object1.data.polygons[i].vertices[2], object1.data.polygons[i].vertices[3], Verts) type_dood = random.randint(0, len(bpy.context.scene.discomb.DISC_doodads) - 1) polygons_add = [] verts_add = [] # First we have to apply scaling and rotation to the mesh bpy.ops.object.select_pattern(pattern=bpy.context.scene.discomb.DISC_doodads[type_dood], extend=False) bpy.context.scene.objects.active = bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]] bpy.ops.object.transform_apply(rotation=True, scale=True) for polygon in bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]].data.polygons: polygons_add.append(polygon.vertices) for vertex in bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]].data.vertices: verts_add.append(vertex.co.copy()) normal_original_polygon = object1.data.polygons[i].normal nor_def = Vector((0.0, 0.0, 1.0)) qr = nor_def.rotation_difference(normal_original_polygon.normalized()) if(test_v2_near_v1(nor_def, -normal_original_polygon)): qr = Quaternion((0.0, 0.0, 0.0, 0.0)) # qr = angle_between_nor(nor_def, normal_original_polygon) for vertex in verts_add: vertex.rotate(qr) vertex += origin_dood findex = len(dVerts) for polygon in polygons_add: dPolygons.append([polygon[0] + findex, polygon[1] + findex, polygon[2] + findex, polygon[3] + findex]) i_dood_type.append(bpy.data.objects[bpy.context.scene.discomb.DISC_doodads[type_dood]].name) for vertex in verts_add: dVerts.append(vertex) j += 1 i += 5 def protusions_repeat(object1, mesh1, r_prot): for j in i_prots: if j < len(object1.data.polygons): object1.data.polygons[j].select = True else: print("Warning: hit end of polygons in object1") # add material to discombobulated mesh def setMatProt(discObj, origObj, sideProtMat, topProtMat): # First we put the materials in their slots bpy.ops.object.select_pattern(pattern=discObj.name, extend=False) bpy.context.scene.objects.active = bpy.data.objects[discObj.name] try: origObj.material_slots[topProtMat] origObj.material_slots[sideProtMat] except: return bpy.ops.object.material_slot_add() bpy.ops.object.material_slot_add() discObj.material_slots[0].material = origObj.material_slots[topProtMat].material discObj.material_slots[1].material = origObj.material_slots[sideProtMat].material # Then we assign materials to protusions for polygon in discObj.data.polygons: if polygon.index in i_prots: polygon.material_index = 0 else: polygon.material_index = 1 def setMatDood(doodObj): # First we add the materials slots bpy.ops.object.select_pattern(pattern=doodObj.name, extend=False) bpy.context.scene.objects.active = doodObj for name in bpy.context.scene.discomb.DISC_doodads: try: bpy.ops.object.material_slot_add() doodObj.material_slots[-1].material = bpy.data.objects[name].material_slots[0].material for polygon in doodObj.data.polygons: if i_dood_type[polygon.index] == name: polygon.material_index = len(doodObj.material_slots) - 1 except: print() def clean_doodads(): current_doodads = list(bpy.context.scene.discomb.DISC_doodads) for name in current_doodads: if name not in bpy.data.objects: bpy.context.scene.discomb.DISC_doodads.remove(name) def discombobulate(minHeight, maxHeight, minTaper, maxTaper, sf1, sf2, sf3, sf4, dmin, dmax, r_prot, sideProtMat, topProtMat, isLast): global doprots global nVerts global nPolygons global Verts global Polygons global dVerts global dPolygons global i_prots bpy.ops.object.mode_set(mode="OBJECT") # start by cleaning up doodads that don't exist anymore clean_doodads() # Create the discombobulated mesh mesh = bpy.data.meshes.new("tmp") object = bpy.data.objects.new("tmp", mesh) bpy.context.scene.objects.link(object) # init final verts and polygons tuple nPolygons = [] nVerts = [] Polygons = [] Verts = [] dPolygons = [] dVerts = [] origObj = bpy.context.active_object # There we collect the rotation, translation and scaling datas from the original mesh to_translate = bpy.context.active_object.location to_scale = bpy.context.active_object.scale to_rotate = bpy.context.active_object.rotation_euler # First, we collect all the informations we will need from the previous mesh obverts = bpy.context.active_object.data.vertices obpolygons = bpy.context.active_object.data.polygons verts = [] for vertex in obverts: verts.append(vertex.co) division(obpolygons, verts, sf1, sf2, sf3, sf4) # Fill in the discombobulated mesh with the new polygons mesh.from_pydata(nVerts, [], nPolygons) mesh.update(calc_edges=True) # Reload the datas bpy.ops.object.select_all(action="DESELECT") bpy.ops.object.select_pattern(pattern=object.name, extend=False) bpy.context.scene.objects.active = bpy.data.objects[object.name] obverts = bpy.context.active_object.data.vertices obpolygons = bpy.context.active_object.data.polygons protusion(obverts, obpolygons, minHeight, maxHeight, minTaper, maxTaper) # Fill in the discombobulated mesh with the new polygons mesh1 = bpy.data.meshes.new("discombobulated_object") object1 = bpy.data.objects.new("discombobulated_mesh", mesh1) bpy.context.scene.objects.link(object1) mesh1.from_pydata(Verts, [], Polygons) mesh1.update(calc_edges=True) # Set the material's of discombobulated object setMatProt(object1, origObj, sideProtMat, topProtMat) bpy.ops.object.select_pattern(pattern=object1.name, extend=False) bpy.context.scene.objects.active = bpy.data.objects[object1.name] bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.normals_make_consistent(inside=False) bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.object.mode_set(mode='OBJECT') # if(bpy.context.scene.repeatprot): protusions_repeat(object1, mesh1, r_prot) if(len(bpy.context.scene.discomb.DISC_doodads) != 0 and bpy.context.scene.discomb.dodoodads and isLast): doodads(object1, mesh1, dmin, dmax) mesh2 = bpy.data.meshes.new("dood_mesh") object2 = bpy.data.objects.new("dood_obj", mesh2) bpy.context.scene.objects.link(object2) mesh2.from_pydata(dVerts, [], dPolygons) mesh2.update(calc_edges=True) setMatDood(object2) object2.location = to_translate object2.rotation_euler = to_rotate object2.scale = to_scale bpy.ops.object.select_pattern(pattern=object.name, extend=False) bpy.context.scene.objects.active = bpy.data.objects[object.name] bpy.ops.object.delete() bpy.ops.object.select_pattern(pattern=object1.name, extend=False) bpy.context.scene.objects.active = bpy.data.objects[object1.name] bpy.context.scene.update() # translate, scale and rotate discombobulated results object1.location = to_translate object1.rotation_euler = to_rotate object1.scale = to_scale # set all polys to selected. this allows recursive discombobulating. for poly in mesh1.polygons: poly.select = True # ### Operators for selecting and deselecting an object as a doodad ### # class chooseDoodad(Operator): bl_idname = "object.discombobulate_set_doodad" bl_label = "Discombobulate set doodad object" bl_description = ("Save the Active Object as Doodad \n" "Object has to be quads only") bl_options = {'REGISTER'} @classmethod def poll(cls, context): obj = bpy.context.active_object if (obj is not None and obj.type == "MESH"): mesh = obj.data for polygon in mesh.polygons: is_ok = len(polygon.vertices) if is_ok != 4: return False return True return False def execute(self, context): obj_name = bpy.context.active_object.name msg = "Object with this name already saved" if obj_name not in bpy.context.scene.discomb.DISC_doodads: bpy.context.scene.discomb.DISC_doodads.append(obj_name) msg = "Saved Doodad object: {}".format(obj_name) self.report({'INFO'}, message=msg) def invoke(self, context, event): self.execute(context) return {'FINISHED'} class unchooseDoodad(Operator): bl_idname = "object.discombobulate_unset_doodad" bl_label = "Discombobulate unset doodad object" bl_description = "Remove the saved Doodad Object(s)" bl_options = {'REGISTER'} remove_all = bpy.props.BoolProperty( name="Remove all Doodads", default=False, ) def execute(self, context): msg = ("No doodads to remove") doodadery = bpy.context.scene.discomb.DISC_doodads if len(doodadery) > 0: if not self.remove_all: name = bpy.context.active_object.name if name in doodadery: bpy.context.scene.discomb.DISC_doodads.remove(name) msg = ("Removed Doodad object: {}".format(name)) else: bpy.context.scene.discomb.DISC_doodads[:] = [] msg = "Removed all Doodads" else: msg = "No Doodads to Remove" self.report({'INFO'}, message=msg) def invoke(self, context, event): self.execute(context) return {'FINISHED'} # ################## Interpolygon ################## # class discombobulator(Operator): bl_idname = "object.discombobulate" bl_label = "Discombobulate" bl_description = "Apply" bl_options = {'REGISTER', 'UNDO'} def execute(self, context): scn = context.scene.discomb i = 0 while i < bpy.context.scene.discomb.repeatprot: isLast = False if i == scn.repeatprot - 1: isLast = True discombobulate(scn.minHeight, scn.maxHeight, scn.minTaper, scn.maxTaper, scn.subpolygon1, scn.subpolygon2, scn.subpolygon3, scn.subpolygon4, scn.mindoodads, scn.maxdoodads, scn.repeatprot, scn.sideProtMat, scn.topProtMat, isLast) i += 1 return {'FINISHED'} class discombobulator_dodads_list(Menu): bl_idname = "object.discombobulator_dodad_list" bl_label = "List of saved Doodads" bl_description = "List of the saved Doodad Object Names" bl_options = {'REGISTER'} def draw(self, context): layout = self.layout doodle = len(bpy.context.scene.discomb.DISC_doodads) layout.label("Saved doodads : {}".format(doodle)) layout.separator() if doodle > 0: for name in bpy.context.scene.discomb.DISC_doodads: layout.label(text=name) class discombob_help(Menu): bl_idname = "help.discombobulator" bl_label = "Usage Information" bl_description = "Help" bl_options = {'REGISTER'} def draw(self, context): layout = self.layout layout.label(text="Usage Information:", icon="INFO") layout.separator() layout.label(text="Quads only, not Triangles or Ngons", icon="ERROR") layout.label("Works only with Mesh object that have faces") layout.separator() layout.label("Select a face or faces") layout.label("Press Discombobulate to create greebles") layout.label("In object mode, still needs a selection in Edit Mode") layout.separator() layout.label("Doodads - additional objects layered on the mesh surface") layout.label("(Similar to dupliverts - but as one separate object)") layout.separator() layout.label(text="Limitations:", icon="MOD_EXPLODE") layout.label("Be careful with the repeat protusions setting") layout.label("(Runs reqursively)") layout.label("If possible, avoid using on a high polycount base mesh") layout.label("(It can run out of memory and take a long time to compute)") class VIEW3D_OT_tools_discombobulate(Operator): bl_idname = "discombobulate.ops" bl_label = "Discombobulator" bl_description = ("Easily add sci-fi details to a surface \n" "Needs an existing active Mesh with Faces") bl_options = {'REGISTER'} executing = False @classmethod def poll(cls, context): return (context.active_object is not None and context.active_object.type == "MESH") def draw(self, context): layout = self.layout row = layout.row() row.menu('help.discombobulator', icon='INFO') box = layout.box() box.label("Protusions settings") row = box.row() row.prop(context.scene.discomb, 'doprots') row = box.row() row.prop(context.scene.discomb, 'minHeight') row = box.row() row.prop(context.scene.discomb, 'maxHeight') row = box.row() row.prop(context.scene.discomb, 'minTaper') row = box.row() row.prop(context.scene.discomb, 'maxTaper') row = box.row() col1 = row.column(align=True) col1.prop(context.scene.discomb, "subpolygon1") col2 = row.column(align=True) col2.prop(context.scene.discomb, "subpolygon2") col3 = row.column(align=True) col3.prop(context.scene.discomb, "subpolygon3") col4 = row.column(align=True) col4.prop(context.scene.discomb, "subpolygon4") row = box.row() row.prop(context.scene.discomb, "repeatprot") box = layout.box() box.label("Doodads settings") row = box.row() is_doodad = context.scene.discomb.dodoodads row.prop(context.scene.discomb, 'dodoodads') row = box.row() row.enabled = is_doodad row.prop(context.scene.discomb, "mindoodads") row = box.row() row.enabled = is_doodad row.prop(context.scene.discomb, "maxdoodads") row = box.row() row.enabled = is_doodad row.operator("object.discombobulate_set_doodad", text="Pick doodad") row = box.row() splits = row.split(0.5) splits.enabled = is_doodad splits.operator("object.discombobulate_unset_doodad", text="Remove active doodad").remove_all = False splits.operator("object.discombobulate_unset_doodad", text="Remove all doodads").remove_all = True col = box.column(align=True) doodle = len(bpy.context.scene.discomb.DISC_doodads) col.enabled = (True if doodle > 0 else False) col.menu("object.discombobulator_dodad_list", text="List of saved Doodads ({})".format(doodle)) box = layout.box() box.label("Materials settings") row = box.row() row.prop(context.scene.discomb, 'topProtMat') row = box.row() row.prop(context.scene.discomb, "sideProtMat") def invoke(self, context, event): return context.window_manager.invoke_props_dialog(self, width=300) def check(self, context): return not self.executing def execute(self, context): self.executing = True bpy.ops.object.discombobulate('INVOKE_DEFAULT') return {'FINISHED'}
gpl-2.0
[ 3, 14629, 327, 12769, 6642, 26, 662, 20662, 1603, 14, 820, 736, 10562, 334, 1786, 82, 2521, 395, 2799, 1158, 19081, 12, 1603, 7984, 510, 1996, 351, 327, 199, 199, 646, 20575, 199, 646, 2196, 199, 646, 3473, 199, 504, 20575, 14, 1313, 492, 334, 355, 11013, 12, 355, 18281, 12, 355, 776, 199, 504, 3473, 1208, 492, 334, 355, 11388, 12, 355, 1413, 4767, 11641, 1636, 12, 355, 776, 199, 199, 3, 21905, 5680, 13641, 83, 21905, 381, 327, 199, 199, 68, 11340, 1086, 275, 715, 199, 199, 3, 577, 292, 305, 315, 1314, 781, 911, 1900, 314, 892, 2153, 957, 7913, 8097, 9364, 199, 78, 5858, 18067, 275, 942, 199, 78, 3673, 1086, 275, 942, 199, 3673, 1086, 275, 942, 199, 5858, 18067, 275, 942, 199, 68, 3673, 1086, 275, 942, 199, 68, 5858, 18067, 275, 942, 199, 73, 63, 496, 1086, 275, 942, 263, 327, 1478, 402, 314, 2746, 30658, 641, 1314, 781, 7171, 3550, 314, 886, 364, 9402, 199, 73, 63, 1117, 364, 63, 466, 275, 942, 259, 327, 730, 402, 886, 364, 350, 334, 11809, 701, 1478, 402, 314, 886, 364, 350, 1559, 9, 421, 199, 3, 21937, 14776, 20511, 17471, 21937, 14776, 327, 199, 199, 318, 10261, 1507, 8, 65, 12, 330, 304, 272, 372, 2196, 14, 2355, 342, 627, 334, 66, 446, 282, 9, 435, 282, 421, 199, 318, 10261, 9787, 8, 65, 12, 330, 12, 286, 12, 366, 12, 5444, 1086, 304, 272, 408, 1767, 282, 5477, 402, 282, 2196, 12759, 641, 282, 16744, 13, 16295, 624, 272, 284, 275, 2196, 14, 8393, 8, 17, 12, 499, 9, 272, 437, 12, 699, 12, 445, 12, 577, 275, 378, 12, 378, 12, 378, 12, 378, 272, 340, 8, 65, 508, 413, 304, 267, 437, 12, 699, 12, 445, 12, 577, 275, 282, 12, 330, 12, 286, 12, 366, 272, 587, 26, 267, 437, 12, 699, 12, 445, 12, 577, 275, 282, 12, 366, 12, 286, 12, 330, 339, 284, 275, 10261, 1507, 8, 16, 14, 17, 12, 378, 14, 25, 9, 339, 10782, 1217, 275, 5444, 1086, 59, 34, 61, 446, 5444, 1086, 59, 33, 61, 272, 662, 275, 5444, 1086, 59, 33, 61, 435, 10782, 1217, 627, 284, 339, 10782, 5196, 275, 5444, 1086, 59, 35, 61, 446, 5444, 1086, 59, 36, 61, 272, 481, 275, 5444, 1086, 59, 36, 61, 435, 10782, 5196, 627, 284, 339, 284, 275, 10261, 1507, 8, 16, 14, 17, 12, 378, 14, 25, 9, 272, 10782, 14153, 275, 481, 446, 662, 339, 593, 275, 662, 435, 10782, 14153, 627, 284, 272, 372, 593, 421, 199, 3, 21905, 309, 2165, 10963, 1356, 21905, 381, 327, 199, 199, 318, 5554, 63, 2149, 63, 11563, 8, 21505, 12, 17248, 304, 272, 408, 30836, 1233, 68, 370, 506, 2797, 701, 314, 805, 1050, 919, 10963, 438, 1378, 12367, 12, 267, 2399, 5951, 1536, 282, 2008, 1314, 3509, 314, 14971, 687, 314, 1300, 436, 314, 2746, 402, 314, 557, 10963, 1356, 14, 272, 408, 272, 2388, 63, 12637, 275, 942, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 16, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 17, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 18, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 19, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 16, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 17, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 18, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 19, 20230, 1574, 1012, 272, 372, 2388, 63, 12637, 421, 199, 318, 1599, 82, 3786, 63, 2119, 8, 808, 63, 12637, 12, 3293, 12, 4569, 304, 272, 408, 961, 805, 1599, 82, 3786, 314, 17248, 26356, 402, 314, 11648, 1642, 7556, 402, 314, 2008, 267, 2388, 63, 12637, 3180, 314, 3293, 29597, 701, 314, 4569, 402, 314, 1599, 6558, 438, 14, 272, 408, 272, 1335, 275, 378, 272, 1830, 1335, 665, 650, 26, 267, 2388, 63, 12637, 59, 16, 1527, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 2388, 63, 12637, 59, 17, 1527, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 2388, 63, 12637, 59, 18, 1527, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 2388, 63, 12637, 59, 19, 1527, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 1335, 847, 413, 421, 199, 318, 4666, 63, 2119, 8, 808, 63, 12637, 12, 8126, 12, 3293, 12, 4569, 12, 4666, 63, 6884, 304, 272, 408, 961, 805, 4666, 314, 17248, 26356, 402, 314, 11648, 1642, 7556, 402, 314, 2008, 2388, 63, 12637, 14, 408, 272, 10782, 17, 275, 359, 16, 12, 378, 12, 378, 61, 272, 10782, 18, 275, 359, 16, 12, 378, 12, 378, 61, 272, 10782, 19, 275, 359, 16, 12, 378, 12, 378, 61, 272, 10782, 20, 275, 359, 16, 12, 378, 12, 378, 61, 339, 1335, 275, 378, 272, 1830, 1335, 665, 650, 26, 267, 8126, 59, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 10782, 17, 59, 74, 61, 275, 2388, 63, 12637, 59, 16, 1527, 74, 61, 446, 8126, 59, 74, 61, 267, 10782, 18, 59, 74, 61, 275, 2388, 63, 12637, 59, 17, 1527, 74, 61, 446, 8126, 59, 74, 61, 267, 10782, 19, 59, 74, 61, 275, 2388, 63, 12637, 59, 18, 1527, 74, 61, 446, 8126, 59, 74, 61, 267, 10782, 20, 59, 74, 61, 275, 2388, 63, 12637, 59, 19, 1527, 74, 61, 446, 8126, 59, 74, 61, 267, 2388, 63, 12637, 59, 16, 1527, 74, 61, 275, 8126, 59, 74, 61, 435, 10782, 17, 59, 74, 61, 627, 334, 17, 446, 4666, 63, 6884, 9, 267, 2388, 63, 12637, 59, 17, 1527, 74, 61, 275, 8126, 59, 74, 61, 435, 10782, 18, 59, 74, 61, 627, 334, 17, 446, 4666, 63, 6884, 9, 267, 2388, 63, 12637, 59, 18, 1527, 74, 61, 275, 8126, 59, 74, 61, 435, 10782, 19, 59, 74, 61, 627, 334, 17, 446 ]
[ 14629, 327, 12769, 6642, 26, 662, 20662, 1603, 14, 820, 736, 10562, 334, 1786, 82, 2521, 395, 2799, 1158, 19081, 12, 1603, 7984, 510, 1996, 351, 327, 199, 199, 646, 20575, 199, 646, 2196, 199, 646, 3473, 199, 504, 20575, 14, 1313, 492, 334, 355, 11013, 12, 355, 18281, 12, 355, 776, 199, 504, 3473, 1208, 492, 334, 355, 11388, 12, 355, 1413, 4767, 11641, 1636, 12, 355, 776, 199, 199, 3, 21905, 5680, 13641, 83, 21905, 381, 327, 199, 199, 68, 11340, 1086, 275, 715, 199, 199, 3, 577, 292, 305, 315, 1314, 781, 911, 1900, 314, 892, 2153, 957, 7913, 8097, 9364, 199, 78, 5858, 18067, 275, 942, 199, 78, 3673, 1086, 275, 942, 199, 3673, 1086, 275, 942, 199, 5858, 18067, 275, 942, 199, 68, 3673, 1086, 275, 942, 199, 68, 5858, 18067, 275, 942, 199, 73, 63, 496, 1086, 275, 942, 263, 327, 1478, 402, 314, 2746, 30658, 641, 1314, 781, 7171, 3550, 314, 886, 364, 9402, 199, 73, 63, 1117, 364, 63, 466, 275, 942, 259, 327, 730, 402, 886, 364, 350, 334, 11809, 701, 1478, 402, 314, 886, 364, 350, 1559, 9, 421, 199, 3, 21937, 14776, 20511, 17471, 21937, 14776, 327, 199, 199, 318, 10261, 1507, 8, 65, 12, 330, 304, 272, 372, 2196, 14, 2355, 342, 627, 334, 66, 446, 282, 9, 435, 282, 421, 199, 318, 10261, 9787, 8, 65, 12, 330, 12, 286, 12, 366, 12, 5444, 1086, 304, 272, 408, 1767, 282, 5477, 402, 282, 2196, 12759, 641, 282, 16744, 13, 16295, 624, 272, 284, 275, 2196, 14, 8393, 8, 17, 12, 499, 9, 272, 437, 12, 699, 12, 445, 12, 577, 275, 378, 12, 378, 12, 378, 12, 378, 272, 340, 8, 65, 508, 413, 304, 267, 437, 12, 699, 12, 445, 12, 577, 275, 282, 12, 330, 12, 286, 12, 366, 272, 587, 26, 267, 437, 12, 699, 12, 445, 12, 577, 275, 282, 12, 366, 12, 286, 12, 330, 339, 284, 275, 10261, 1507, 8, 16, 14, 17, 12, 378, 14, 25, 9, 339, 10782, 1217, 275, 5444, 1086, 59, 34, 61, 446, 5444, 1086, 59, 33, 61, 272, 662, 275, 5444, 1086, 59, 33, 61, 435, 10782, 1217, 627, 284, 339, 10782, 5196, 275, 5444, 1086, 59, 35, 61, 446, 5444, 1086, 59, 36, 61, 272, 481, 275, 5444, 1086, 59, 36, 61, 435, 10782, 5196, 627, 284, 339, 284, 275, 10261, 1507, 8, 16, 14, 17, 12, 378, 14, 25, 9, 272, 10782, 14153, 275, 481, 446, 662, 339, 593, 275, 662, 435, 10782, 14153, 627, 284, 272, 372, 593, 421, 199, 3, 21905, 309, 2165, 10963, 1356, 21905, 381, 327, 199, 199, 318, 5554, 63, 2149, 63, 11563, 8, 21505, 12, 17248, 304, 272, 408, 30836, 1233, 68, 370, 506, 2797, 701, 314, 805, 1050, 919, 10963, 438, 1378, 12367, 12, 267, 2399, 5951, 1536, 282, 2008, 1314, 3509, 314, 14971, 687, 314, 1300, 436, 314, 2746, 402, 314, 557, 10963, 1356, 14, 272, 408, 272, 2388, 63, 12637, 275, 942, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 16, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 17, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 18, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 19, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 16, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 17, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 18, 20230, 1574, 1012, 272, 2388, 63, 12637, 14, 740, 8, 21505, 59, 16295, 59, 19, 20230, 1574, 1012, 272, 372, 2388, 63, 12637, 421, 199, 318, 1599, 82, 3786, 63, 2119, 8, 808, 63, 12637, 12, 3293, 12, 4569, 304, 272, 408, 961, 805, 1599, 82, 3786, 314, 17248, 26356, 402, 314, 11648, 1642, 7556, 402, 314, 2008, 267, 2388, 63, 12637, 3180, 314, 3293, 29597, 701, 314, 4569, 402, 314, 1599, 6558, 438, 14, 272, 408, 272, 1335, 275, 378, 272, 1830, 1335, 665, 650, 26, 267, 2388, 63, 12637, 59, 16, 1527, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 2388, 63, 12637, 59, 17, 1527, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 2388, 63, 12637, 59, 18, 1527, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 2388, 63, 12637, 59, 19, 1527, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 1335, 847, 413, 421, 199, 318, 4666, 63, 2119, 8, 808, 63, 12637, 12, 8126, 12, 3293, 12, 4569, 12, 4666, 63, 6884, 304, 272, 408, 961, 805, 4666, 314, 17248, 26356, 402, 314, 11648, 1642, 7556, 402, 314, 2008, 2388, 63, 12637, 14, 408, 272, 10782, 17, 275, 359, 16, 12, 378, 12, 378, 61, 272, 10782, 18, 275, 359, 16, 12, 378, 12, 378, 61, 272, 10782, 19, 275, 359, 16, 12, 378, 12, 378, 61, 272, 10782, 20, 275, 359, 16, 12, 378, 12, 378, 61, 339, 1335, 275, 378, 272, 1830, 1335, 665, 650, 26, 267, 8126, 59, 74, 61, 847, 3293, 59, 74, 61, 627, 4569, 267, 10782, 17, 59, 74, 61, 275, 2388, 63, 12637, 59, 16, 1527, 74, 61, 446, 8126, 59, 74, 61, 267, 10782, 18, 59, 74, 61, 275, 2388, 63, 12637, 59, 17, 1527, 74, 61, 446, 8126, 59, 74, 61, 267, 10782, 19, 59, 74, 61, 275, 2388, 63, 12637, 59, 18, 1527, 74, 61, 446, 8126, 59, 74, 61, 267, 10782, 20, 59, 74, 61, 275, 2388, 63, 12637, 59, 19, 1527, 74, 61, 446, 8126, 59, 74, 61, 267, 2388, 63, 12637, 59, 16, 1527, 74, 61, 275, 8126, 59, 74, 61, 435, 10782, 17, 59, 74, 61, 627, 334, 17, 446, 4666, 63, 6884, 9, 267, 2388, 63, 12637, 59, 17, 1527, 74, 61, 275, 8126, 59, 74, 61, 435, 10782, 18, 59, 74, 61, 627, 334, 17, 446, 4666, 63, 6884, 9, 267, 2388, 63, 12637, 59, 18, 1527, 74, 61, 275, 8126, 59, 74, 61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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
scrapinghub/dateparser
tests/test_hijri.py
1
2000
import sys import unittest from datetime import datetime from parameterized import parameterized, param from tests import BaseTestCase is_python_supported = sys.version_info >= (3, 6) try: from dateparser.calendars.hijri import HijriCalendar except ImportError: if is_python_supported: raise @unittest.skipUnless(is_python_supported, "hijri-converter doesn't support Python<3.6") class TestHijriParser(BaseTestCase): def setUp(self): super().setUp() self.result = NotImplemented self.date_string = NotImplemented self.parser = NotImplemented self.translated = NotImplemented def when_date_is_given(self, dt_string, date_formats, languages): self.date_string = dt_string self.parser = HijriCalendar(dt_string) self.result = self.parser.get_date() def then_parsed_datetime_is(self, dt): self.assertEqual(dt, self.result['date_obj']) @parameterized.expand([ param(dt_string="14-09-1432 هـ, 09:40 صباحاً", dt_obj=datetime(2011, 8, 14, 9, 40)), param(dt_string="20-02-1430 هـ, 07:21 صباحاً", dt_obj=datetime(2009, 2, 15, 7, 21)), param(dt_string="11-08-1434 هـ, 09:38 صباحاً", dt_obj=datetime(2013, 6, 20, 9, 38)), param(dt_string=" 17-01-1437 هـ 08:30 مساءً", dt_obj=datetime(2015, 10, 30, 20, 30)), param(dt_string="29-02-1433 هـ, 06:22 صباحاً", dt_obj=datetime(2012, 1, 23, 6, 22)), param(dt_string="30-02-1433", dt_obj=datetime(2012, 1, 24)), param(dt_string="04-03-1433 هـ, 10:08 مساءً", dt_obj=datetime(2012, 1, 27, 22, 8)), ]) def test_datetime_parsing(self, dt_string, dt_obj, date_formats=None, languages=None): from dateparser.conf import settings settings.DATE_ORDER = 'DMY' self.when_date_is_given(dt_string, date_formats, languages) self.then_parsed_datetime_is(dt_obj) settings.DATE_ORDER = 'MDY'
bsd-3-clause
[ 646, 984, 199, 646, 2882, 199, 504, 2197, 492, 2197, 199, 199, 504, 29526, 492, 29526, 12, 1215, 199, 199, 504, 2295, 492, 3523, 1746, 199, 199, 374, 63, 1548, 63, 4946, 275, 984, 14, 1023, 63, 815, 2356, 334, 19, 12, 1227, 9, 199, 199, 893, 26, 272, 687, 1434, 2087, 14, 696, 31276, 14, 5812, 74, 322, 492, 869, 7879, 322, 18688, 199, 2590, 3545, 26, 272, 340, 365, 63, 1548, 63, 4946, 26, 267, 746, 421, 199, 32, 2796, 14, 11278, 8, 374, 63, 1548, 63, 4946, 12, 298, 5812, 74, 322, 13, 11256, 3181, 1133, 2291, 2018, 28, 19, 14, 22, 531, 199, 533, 1379, 40, 7879, 322, 2842, 8, 20760, 304, 339, 347, 3613, 8, 277, 304, 267, 1613, 1252, 5996, 342, 267, 291, 14, 1099, 275, 3784, 267, 291, 14, 602, 63, 875, 275, 3784, 267, 291, 14, 2087, 275, 3784, 267, 291, 14, 18065, 275, 3784, 339, 347, 1380, 63, 602, 63, 374, 63, 11809, 8, 277, 12, 4487, 63, 875, 12, 1434, 63, 6321, 12, 10815, 304, 267, 291, 14, 602, 63, 875, 275, 4487, 63, 875, 267, 291, 14, 2087, 275, 869, 7879, 322, 18688, 8, 3583, 63, 875, 9, 267, 291, 14, 1099, 275, 291, 14, 2087, 14, 362, 63, 602, 342, 339, 347, 2066, 63, 6751, 63, 2083, 63, 374, 8, 277, 12, 4487, 304, 267, 291, 14, 629, 8, 3583, 12, 291, 14, 1099, 459, 602, 63, 1113, 1105, 339, 768, 25000, 14, 4441, 779, 267, 1215, 8, 3583, 63, 875, 628, 1079, 13, 1643, 13, 1079, 708, 221, 10687, 150, 223, 12, 21798, 26, 2167, 8702, 114, 25044, 11321, 256, 6494, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 8128, 12, 1695, 12, 4329, 12, 1749, 12, 6335, 1826, 267, 1215, 8, 3583, 63, 875, 628, 1165, 13, 996, 13, 1079, 1216, 221, 10687, 150, 223, 12, 24937, 26, 2025, 8702, 114, 25044, 11321, 256, 6494, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 8664, 12, 499, 12, 4114, 12, 1520, 12, 7829, 1826, 267, 1215, 8, 3583, 63, 875, 628, 845, 13, 2036, 13, 1079, 1082, 221, 10687, 150, 223, 12, 21798, 26, 1703, 8702, 114, 25044, 11321, 256, 6494, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 6965, 12, 1227, 12, 3388, 12, 1749, 12, 10448, 1826, 267, 1215, 8, 3583, 63, 875, 628, 5557, 13, 614, 13, 1079, 1401, 221, 10687, 150, 223, 19363, 26, 1216, 21216, 18438, 11321, 95, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 7806, 12, 1616, 12, 4233, 12, 3388, 12, 4233, 1826, 267, 1215, 8, 3583, 63, 875, 628, 1398, 13, 996, 13, 1079, 1153, 221, 10687, 150, 223, 12, 24293, 26, 1081, 8702, 114, 25044, 11321, 256, 6494, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 7409, 12, 413, 12, 6546, 12, 1227, 12, 6928, 1826, 267, 1215, 8, 3583, 63, 875, 628, 1216, 13, 996, 13, 1079, 1153, 401, 4487, 63, 1113, 29, 2083, 8, 7409, 12, 413, 12, 5504, 1826, 267, 1215, 8, 3583, 63, 875, 628, 966, 13, 1644, 13, 1079, 1153, 221, 10687, 150, 223, 12, 1616, 26, 2036, 21216, 18438, 11321, 95, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 7409, 12, 413, 12, 8087, 12, 6928, 12, 1695, 1826, 272, 4794, 272, 347, 511, 63, 2083, 63, 11059, 8, 277, 12, 4487, 63, 875, 12, 4487, 63, 1113, 12, 2892, 1434, 63, 6321, 29, 403, 12, 10815, 29, 403, 304, 267, 687, 1434, 2087, 14, 2190, 492, 2202, 267, 2202, 14, 5390, 63, 12125, 275, 283, 36, 12339, 7, 267, 291, 14, 6526, 63, 602, 63, 374, 63, 11809, 8, 3583, 63, 875, 12, 1434, 63, 6321, 12, 10815, 9, 267, 291, 14, 12726, 63, 6751, 63, 2083, 63, 374, 8, 3583, 63, 1113, 9, 267, 2202, 14, 5390, 63, 12125, 275, 283, 5127, 57, 7, 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 ]
[ 984, 199, 646, 2882, 199, 504, 2197, 492, 2197, 199, 199, 504, 29526, 492, 29526, 12, 1215, 199, 199, 504, 2295, 492, 3523, 1746, 199, 199, 374, 63, 1548, 63, 4946, 275, 984, 14, 1023, 63, 815, 2356, 334, 19, 12, 1227, 9, 199, 199, 893, 26, 272, 687, 1434, 2087, 14, 696, 31276, 14, 5812, 74, 322, 492, 869, 7879, 322, 18688, 199, 2590, 3545, 26, 272, 340, 365, 63, 1548, 63, 4946, 26, 267, 746, 421, 199, 32, 2796, 14, 11278, 8, 374, 63, 1548, 63, 4946, 12, 298, 5812, 74, 322, 13, 11256, 3181, 1133, 2291, 2018, 28, 19, 14, 22, 531, 199, 533, 1379, 40, 7879, 322, 2842, 8, 20760, 304, 339, 347, 3613, 8, 277, 304, 267, 1613, 1252, 5996, 342, 267, 291, 14, 1099, 275, 3784, 267, 291, 14, 602, 63, 875, 275, 3784, 267, 291, 14, 2087, 275, 3784, 267, 291, 14, 18065, 275, 3784, 339, 347, 1380, 63, 602, 63, 374, 63, 11809, 8, 277, 12, 4487, 63, 875, 12, 1434, 63, 6321, 12, 10815, 304, 267, 291, 14, 602, 63, 875, 275, 4487, 63, 875, 267, 291, 14, 2087, 275, 869, 7879, 322, 18688, 8, 3583, 63, 875, 9, 267, 291, 14, 1099, 275, 291, 14, 2087, 14, 362, 63, 602, 342, 339, 347, 2066, 63, 6751, 63, 2083, 63, 374, 8, 277, 12, 4487, 304, 267, 291, 14, 629, 8, 3583, 12, 291, 14, 1099, 459, 602, 63, 1113, 1105, 339, 768, 25000, 14, 4441, 779, 267, 1215, 8, 3583, 63, 875, 628, 1079, 13, 1643, 13, 1079, 708, 221, 10687, 150, 223, 12, 21798, 26, 2167, 8702, 114, 25044, 11321, 256, 6494, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 8128, 12, 1695, 12, 4329, 12, 1749, 12, 6335, 1826, 267, 1215, 8, 3583, 63, 875, 628, 1165, 13, 996, 13, 1079, 1216, 221, 10687, 150, 223, 12, 24937, 26, 2025, 8702, 114, 25044, 11321, 256, 6494, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 8664, 12, 499, 12, 4114, 12, 1520, 12, 7829, 1826, 267, 1215, 8, 3583, 63, 875, 628, 845, 13, 2036, 13, 1079, 1082, 221, 10687, 150, 223, 12, 21798, 26, 1703, 8702, 114, 25044, 11321, 256, 6494, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 6965, 12, 1227, 12, 3388, 12, 1749, 12, 10448, 1826, 267, 1215, 8, 3583, 63, 875, 628, 5557, 13, 614, 13, 1079, 1401, 221, 10687, 150, 223, 19363, 26, 1216, 21216, 18438, 11321, 95, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 7806, 12, 1616, 12, 4233, 12, 3388, 12, 4233, 1826, 267, 1215, 8, 3583, 63, 875, 628, 1398, 13, 996, 13, 1079, 1153, 221, 10687, 150, 223, 12, 24293, 26, 1081, 8702, 114, 25044, 11321, 256, 6494, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 7409, 12, 413, 12, 6546, 12, 1227, 12, 6928, 1826, 267, 1215, 8, 3583, 63, 875, 628, 1216, 13, 996, 13, 1079, 1153, 401, 4487, 63, 1113, 29, 2083, 8, 7409, 12, 413, 12, 5504, 1826, 267, 1215, 8, 3583, 63, 875, 628, 966, 13, 1644, 13, 1079, 1153, 221, 10687, 150, 223, 12, 1616, 26, 2036, 21216, 18438, 11321, 95, 150, 234, 401, 4487, 63, 1113, 29, 2083, 8, 7409, 12, 413, 12, 8087, 12, 6928, 12, 1695, 1826, 272, 4794, 272, 347, 511, 63, 2083, 63, 11059, 8, 277, 12, 4487, 63, 875, 12, 4487, 63, 1113, 12, 2892, 1434, 63, 6321, 29, 403, 12, 10815, 29, 403, 304, 267, 687, 1434, 2087, 14, 2190, 492, 2202, 267, 2202, 14, 5390, 63, 12125, 275, 283, 36, 12339, 7, 267, 291, 14, 6526, 63, 602, 63, 374, 63, 11809, 8, 3583, 63, 875, 12, 1434, 63, 6321, 12, 10815, 9, 267, 291, 14, 12726, 63, 6751, 63, 2083, 63, 374, 8, 3583, 63, 1113, 9, 267, 2202, 14, 5390, 63, 12125, 275, 283, 5127, 57, 7, 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, 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 ]
trankmichael/scipy
scipy/io/tests/test_mmio.py
2
12652
#!/usr/bin/env python from __future__ import division, print_function, absolute_import from tempfile import mkdtemp, mktemp import os import shutil from numpy import array,transpose, pi from numpy.testing import (TestCase, run_module_suite, assert_equal, assert_array_equal, assert_array_almost_equal, rand) import scipy.sparse from scipy.io.mmio import mminfo,mmread,mmwrite class TestMMIOArray(TestCase): def setUp(self): self.tmpdir = mkdtemp() self.fn = os.path.join(self.tmpdir, 'testfile.mtx') def tearDown(self): shutil.rmtree(self.tmpdir) def test_simple(self): a = [[1,2],[3,4]] fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(2,2,4,'array','integer','general')) b = mmread(fn) assert_array_almost_equal(a,b) def test_simple_rectangular(self): a = [[1,2,3],[4,5,6]] fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(2,3,6,'array','integer','general')) b = mmread(fn) assert_array_almost_equal(a,b) def test_simple_rectangular_real(self): a = [[1,2],[3.5,4],[5,6]] fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(3,2,6,'array','real','general')) b = mmread(fn) assert_array_almost_equal(a,b) def test_simple_real(self): a = [[1,2],[3,4.0]] fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(2,2,4,'array','real','general')) b = mmread(fn) assert_array_almost_equal(a,b) def test_simple_complex(self): a = [[1,2],[3,4j]] fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(2,2,4,'array','complex','general')) b = mmread(fn) assert_array_almost_equal(a,b) def test_simple_symmetric(self): a = [[1,2],[2,4]] fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(2,2,4,'array','integer','symmetric')) b = mmread(fn) assert_array_almost_equal(a,b) def test_simple_skew_symmetric(self): a = [[1,2],[-2,4]] fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(2,2,4,'array','integer','skew-symmetric')) b = mmread(fn) assert_array_almost_equal(a,b) def test_simple_skew_symmetric_float(self): a = array([[1,2],[-2.0,4]],'f') fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(2,2,4,'array','real','skew-symmetric')) b = mmread(fn) assert_array_almost_equal(a,b) def test_simple_hermitian(self): a = [[1,2+3j],[2-3j,4]] fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(2,2,4,'array','complex','hermitian')) b = mmread(fn) assert_array_almost_equal(a,b) def test_random_symmetric_real(self): sz = (20,20) a = rand(*sz) a = a + transpose(a) fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(20,20,400,'array','real','symmetric')) b = mmread(fn) assert_array_almost_equal(a,b) def test_random_rect_real(self): sz = (20,15) a = rand(*sz) fn = self.fn mmwrite(fn,a) assert_equal(mminfo(fn),(20,15,300,'array','real','general')) b = mmread(fn) assert_array_almost_equal(a,b) _general_example = '''\ %%MatrixMarket matrix coordinate real general %================================================================================= % % This ASCII file represents a sparse MxN matrix with L % nonzeros in the following Matrix Market format: % % +----------------------------------------------+ % |%%MatrixMarket matrix coordinate real general | <--- header line % |% | <--+ % |% comments | |-- 0 or more comment lines % |% | <--+ % | M N L | <--- rows, columns, entries % | I1 J1 A(I1, J1) | <--+ % | I2 J2 A(I2, J2) | | % | I3 J3 A(I3, J3) | |-- L lines % | . . . | | % | IL JL A(IL, JL) | <--+ % +----------------------------------------------+ % % Indices are 1-based, i.e. A(1,1) is the first element. % %================================================================================= 5 5 8 1 1 1.000e+00 2 2 1.050e+01 3 3 1.500e-02 1 4 6.000e+00 4 2 2.505e+02 4 4 -2.800e+02 4 5 3.332e+01 5 5 1.200e+01 ''' _hermitian_example = '''\ %%MatrixMarket matrix coordinate complex hermitian 5 5 7 1 1 1.0 0 2 2 10.5 0 4 2 250.5 22.22 3 3 1.5e-2 0 4 4 -2.8e2 0 5 5 12. 0 5 4 0 33.32 ''' _skew_example = '''\ %%MatrixMarket matrix coordinate real skew-symmetric 5 5 7 1 1 1.0 2 2 10.5 4 2 250.5 3 3 1.5e-2 4 4 -2.8e2 5 5 12. 5 4 0 ''' _symmetric_example = '''\ %%MatrixMarket matrix coordinate real symmetric 5 5 7 1 1 1.0 2 2 10.5 4 2 250.5 3 3 1.5e-2 4 4 -2.8e2 5 5 12. 5 4 8 ''' _symmetric_pattern_example = '''\ %%MatrixMarket matrix coordinate pattern symmetric 5 5 7 1 1 2 2 4 2 3 3 4 4 5 5 5 4 ''' class TestMMIOCoordinate(TestCase): def setUp(self): self.tmpdir = mkdtemp() self.fn = os.path.join(self.tmpdir, 'testfile.mtx') def tearDown(self): shutil.rmtree(self.tmpdir) def test_read_general(self): fn = self.fn f = open(fn,'w') f.write(_general_example) f.close() assert_equal(mminfo(fn),(5,5,8,'coordinate','real','general')) a = [[1, 0, 0, 6, 0], [0, 10.5, 0, 0, 0], [0, 0, .015, 0, 0], [0, 250.5, 0, -280, 33.32], [0, 0, 0, 0, 12]] b = mmread(fn).todense() assert_array_almost_equal(a,b) def test_read_hermitian(self): fn = self.fn f = open(fn,'w') f.write(_hermitian_example) f.close() assert_equal(mminfo(fn),(5,5,7,'coordinate','complex','hermitian')) a = [[1, 0, 0, 0, 0], [0, 10.5, 0, 250.5 - 22.22j, 0], [0, 0, .015, 0, 0], [0, 250.5 + 22.22j, 0, -280, -33.32j], [0, 0, 0, 33.32j, 12]] b = mmread(fn).todense() assert_array_almost_equal(a,b) def test_read_skew(self): fn = self.fn f = open(fn,'w') f.write(_skew_example) f.close() assert_equal(mminfo(fn),(5,5,7,'coordinate','real','skew-symmetric')) a = [[1, 0, 0, 0, 0], [0, 10.5, 0, -250.5, 0], [0, 0, .015, 0, 0], [0, 250.5, 0, -280, 0], [0, 0, 0, 0, 12]] b = mmread(fn).todense() assert_array_almost_equal(a,b) def test_read_symmetric(self): fn = self.fn f = open(fn,'w') f.write(_symmetric_example) f.close() assert_equal(mminfo(fn),(5,5,7,'coordinate','real','symmetric')) a = [[1, 0, 0, 0, 0], [0, 10.5, 0, 250.5, 0], [0, 0, .015, 0, 0], [0, 250.5, 0, -280, 8], [0, 0, 0, 8, 12]] b = mmread(fn).todense() assert_array_almost_equal(a,b) def test_read_symmetric_pattern(self): fn = self.fn f = open(fn,'w') f.write(_symmetric_pattern_example) f.close() assert_equal(mminfo(fn),(5,5,7,'coordinate','pattern','symmetric')) a = [[1, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 1], [0, 0, 0, 1, 1]] b = mmread(fn).todense() assert_array_almost_equal(a,b) def test_empty_write_read(self): #http://projects.scipy.org/scipy/ticket/883 b = scipy.sparse.coo_matrix((10,10)) fn = self.fn mmwrite(fn,b) assert_equal(mminfo(fn),(10,10,0,'coordinate','real','general')) a = b.todense() b = mmread(fn).todense() assert_array_almost_equal(a,b) def test_bzip2_py3(self): # test if fix for #2152 works try: # bz2 module isn't always built when building Python. import bz2 except: return I = array([0, 0, 1, 2, 3, 3, 3, 4]) J = array([0, 3, 1, 2, 1, 3, 4, 4]) V = array([1.0, 6.0, 10.5, 0.015, 250.5, -280.0, 33.32, 12.0]) b = scipy.sparse.coo_matrix((V,(I,J)),shape=(5,5)) fn = self.fn mmwrite(fn, b) fn_bzip2 = "%s.bz2" % fn with open(fn, 'rb') as f_in: f_out = bz2.BZ2File(fn_bzip2, 'wb') f_out.write(f_in.read()) f_out.close() a = mmread(fn_bzip2).todense() assert_array_almost_equal(a, b.todense()) def test_gzip_py3(self): # test if fix for #2152 works try: # gzip module can be missing from Python installation import gzip except: return I = array([0, 0, 1, 2, 3, 3, 3, 4]) J = array([0, 3, 1, 2, 1, 3, 4, 4]) V = array([1.0, 6.0, 10.5, 0.015, 250.5, -280.0, 33.32, 12.0]) b = scipy.sparse.coo_matrix((V,(I,J)),shape=(5,5)) fn = self.fn mmwrite(fn, b) fn_gzip = "%s.gz" % fn with open(fn, 'rb') as f_in: f_out = gzip.open(fn_gzip, 'wb') f_out.write(f_in.read()) f_out.close() a = mmread(fn_gzip).todense() assert_array_almost_equal(a, b.todense()) def test_real_write_read(self): I = array([0, 0, 1, 2, 3, 3, 3, 4]) J = array([0, 3, 1, 2, 1, 3, 4, 4]) V = array([1.0, 6.0, 10.5, 0.015, 250.5, -280.0, 33.32, 12.0]) b = scipy.sparse.coo_matrix((V,(I,J)),shape=(5,5)) fn = self.fn mmwrite(fn,b) assert_equal(mminfo(fn),(5,5,8,'coordinate','real','general')) a = b.todense() b = mmread(fn).todense() assert_array_almost_equal(a,b) def test_complex_write_read(self): I = array([0, 0, 1, 2, 3, 3, 3, 4]) J = array([0, 3, 1, 2, 1, 3, 4, 4]) V = array([1.0 + 3j, 6.0 + 2j, 10.50 + 0.9j, 0.015 + -4.4j, 250.5 + 0j, -280.0 + 5j, 33.32 + 6.4j, 12.00 + 0.8j]) b = scipy.sparse.coo_matrix((V,(I,J)),shape=(5,5)) fn = self.fn mmwrite(fn,b) assert_equal(mminfo(fn),(5,5,8,'coordinate','complex','general')) a = b.todense() b = mmread(fn).todense() assert_array_almost_equal(a,b) def test_sparse_formats(self): mats = [] I = array([0, 0, 1, 2, 3, 3, 3, 4]) J = array([0, 3, 1, 2, 1, 3, 4, 4]) V = array([1.0, 6.0, 10.5, 0.015, 250.5, -280.0, 33.32, 12.0]) mats.append(scipy.sparse.coo_matrix((V,(I,J)),shape=(5,5))) V = array([1.0 + 3j, 6.0 + 2j, 10.50 + 0.9j, 0.015 + -4.4j, 250.5 + 0j, -280.0 + 5j, 33.32 + 6.4j, 12.00 + 0.8j]) mats.append(scipy.sparse.coo_matrix((V,(I,J)),shape=(5,5))) for mat in mats: expected = mat.todense() for fmt in ['csr','csc','coo']: fn = mktemp(dir=self.tmpdir) # safe, we own tmpdir mmwrite(fn, mat.asformat(fmt)) result = mmread(fn).todense() assert_array_almost_equal(result, expected) def test_precision(self): test_values = [pi] + [10**(i) for i in range(0, -10, -1)] test_precisions = range(1, 10) for value in test_values: for precision in test_precisions: # construct sparse matrix with test value at last main diagonal n = 10**precision + 1 A = scipy.sparse.dok_matrix((n, n)) A[n-1, n-1] = value # write matrix with test precision and read again mmwrite(self.fn, A, precision=precision) A = scipy.io.mmread(self.fn) # check for right entries in matrix assert_array_equal(A.row, [n-1]) assert_array_equal(A.col, [n-1]) assert_array_almost_equal(A.data, [float('%%.%dg' % precision % value)]) if __name__ == "__main__": run_module_suite()
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 504, 636, 2443, 363, 492, 4629, 12, 870, 63, 1593, 12, 3679, 63, 646, 199, 199, 504, 5549, 492, 31781, 12, 9199, 808, 199, 646, 747, 199, 646, 5145, 199, 504, 2680, 492, 1625, 12, 10483, 12, 6682, 199, 504, 2680, 14, 4776, 492, 334, 1746, 12, 1255, 63, 578, 63, 5768, 12, 702, 63, 1452, 12, 272, 702, 63, 1144, 63, 1452, 12, 702, 63, 1144, 63, 4398, 63, 1452, 12, 10261, 9, 199, 199, 646, 7026, 14, 4421, 199, 504, 7026, 14, 2308, 14, 596, 2308, 492, 8562, 815, 12, 596, 739, 12, 596, 952, 421, 199, 533, 1379, 3218, 2090, 3836, 8, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 8616, 275, 31781, 342, 267, 291, 14, 2324, 275, 747, 14, 515, 14, 904, 8, 277, 14, 8616, 12, 283, 21091, 14, 26029, 358, 339, 347, 6766, 8, 277, 304, 267, 5145, 14, 9242, 8, 277, 14, 8616, 9, 339, 347, 511, 63, 4129, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 19, 12, 20, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 4115, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 1201, 11572, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 12, 19, 6922, 20, 12, 21, 12, 22, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 19, 12, 22, 2584, 1144, 1673, 4115, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 1201, 11572, 63, 3093, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 19, 14, 21, 12, 20, 6922, 21, 12, 22, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 19, 12, 18, 12, 22, 2584, 1144, 1673, 3093, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 3093, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 19, 12, 20, 14, 16, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 3093, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 5254, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 19, 12, 20, 74, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 5254, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 18422, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 18, 12, 20, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 4115, 1673, 18422, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 27424, 63, 18422, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 467, 1988, 18, 12, 20, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 4115, 1673, 27424, 13, 18422, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 27424, 63, 18422, 63, 1609, 8, 277, 304, 267, 282, 275, 1625, 4038, 17, 12, 18, 467, 1988, 18, 14, 16, 12, 20, 2365, 7, 70, 358, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 3093, 1673, 27424, 13, 18422, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 2523, 26649, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 11, 19, 74, 6922, 18, 13, 19, 74, 12, 20, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 5254, 1673, 2523, 26649, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 2355, 63, 18422, 63, 3093, 8, 277, 304, 267, 17176, 275, 334, 1165, 12, 1165, 9, 267, 282, 275, 10261, 2031, 11803, 9, 267, 282, 275, 282, 435, 16992, 8, 65, 9, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 1165, 12, 1165, 12, 5303, 2584, 1144, 1673, 3093, 1673, 18422, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 2355, 63, 1201, 63, 3093, 8, 277, 304, 267, 17176, 275, 334 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 504, 636, 2443, 363, 492, 4629, 12, 870, 63, 1593, 12, 3679, 63, 646, 199, 199, 504, 5549, 492, 31781, 12, 9199, 808, 199, 646, 747, 199, 646, 5145, 199, 504, 2680, 492, 1625, 12, 10483, 12, 6682, 199, 504, 2680, 14, 4776, 492, 334, 1746, 12, 1255, 63, 578, 63, 5768, 12, 702, 63, 1452, 12, 272, 702, 63, 1144, 63, 1452, 12, 702, 63, 1144, 63, 4398, 63, 1452, 12, 10261, 9, 199, 199, 646, 7026, 14, 4421, 199, 504, 7026, 14, 2308, 14, 596, 2308, 492, 8562, 815, 12, 596, 739, 12, 596, 952, 421, 199, 533, 1379, 3218, 2090, 3836, 8, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 8616, 275, 31781, 342, 267, 291, 14, 2324, 275, 747, 14, 515, 14, 904, 8, 277, 14, 8616, 12, 283, 21091, 14, 26029, 358, 339, 347, 6766, 8, 277, 304, 267, 5145, 14, 9242, 8, 277, 14, 8616, 9, 339, 347, 511, 63, 4129, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 19, 12, 20, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 4115, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 1201, 11572, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 12, 19, 6922, 20, 12, 21, 12, 22, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 19, 12, 22, 2584, 1144, 1673, 4115, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 1201, 11572, 63, 3093, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 19, 14, 21, 12, 20, 6922, 21, 12, 22, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 19, 12, 18, 12, 22, 2584, 1144, 1673, 3093, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 3093, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 19, 12, 20, 14, 16, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 3093, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 5254, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 19, 12, 20, 74, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 5254, 1673, 10706, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 18422, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 6922, 18, 12, 20, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 4115, 1673, 18422, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 27424, 63, 18422, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 467, 1988, 18, 12, 20, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 4115, 1673, 27424, 13, 18422, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 27424, 63, 18422, 63, 1609, 8, 277, 304, 267, 282, 275, 1625, 4038, 17, 12, 18, 467, 1988, 18, 14, 16, 12, 20, 2365, 7, 70, 358, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 3093, 1673, 27424, 13, 18422, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 4129, 63, 2523, 26649, 8, 277, 304, 267, 282, 275, 3474, 17, 12, 18, 11, 19, 74, 6922, 18, 13, 19, 74, 12, 20, 2677, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 18, 12, 18, 12, 20, 2584, 1144, 1673, 5254, 1673, 2523, 26649, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 2355, 63, 18422, 63, 3093, 8, 277, 304, 267, 17176, 275, 334, 1165, 12, 1165, 9, 267, 282, 275, 10261, 2031, 11803, 9, 267, 282, 275, 282, 435, 16992, 8, 65, 9, 267, 4325, 275, 291, 14, 2324, 267, 8562, 952, 8, 2324, 12, 65, 9, 267, 702, 63, 1452, 8, 596, 815, 8, 2324, 11865, 1165, 12, 1165, 12, 5303, 2584, 1144, 1673, 3093, 1673, 18422, 1333, 267, 330, 275, 8562, 739, 8, 2324, 9, 267, 702, 63, 1144, 63, 4398, 63, 1452, 8, 65, 12, 66, 9, 339, 347, 511, 63, 2355, 63, 1201, 63, 3093, 8, 277, 304, 267, 17176, 275, 334, 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 ]
stefanv/aandete
app/lib/pygments/lexer.py
27
31054
# -*- coding: utf-8 -*- """ pygments.lexer ~~~~~~~~~~~~~~ Base lexer classes. :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ from __future__ import print_function import re import sys import time from pygments.filter import apply_filters, Filter from pygments.filters import get_filter_by_name from pygments.token import Error, Text, Other, _TokenType from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \ make_analysator, text_type, add_metaclass, iteritems, Future, guess_decode from pygments.regexopt import regex_opt __all__ = ['Lexer', 'RegexLexer', 'ExtendedRegexLexer', 'DelegatingLexer', 'LexerContext', 'include', 'inherit', 'bygroups', 'using', 'this', 'default', 'words'] _encoding_map = [(b'\xef\xbb\xbf', 'utf-8'), (b'\xff\xfe\0\0', 'utf-32'), (b'\0\0\xfe\xff', 'utf-32be'), (b'\xff\xfe', 'utf-16'), (b'\xfe\xff', 'utf-16be')] _default_analyse = staticmethod(lambda x: 0.0) class LexerMeta(type): """ This metaclass automagically converts ``analyse_text`` methods into static methods which always return float values. """ def __new__(mcs, name, bases, d): if 'analyse_text' in d: d['analyse_text'] = make_analysator(d['analyse_text']) return type.__new__(mcs, name, bases, d) @add_metaclass(LexerMeta) class Lexer(object): """ Lexer for a specific language. Basic options recognized: ``stripnl`` Strip leading and trailing newlines from the input (default: True). ``stripall`` Strip all leading and trailing whitespace from the input (default: False). ``ensurenl`` Make sure that the input ends with a newline (default: True). This is required for some lexers that consume input linewise. .. versionadded:: 1.3 ``tabsize`` If given and greater than 0, expand tabs in the input (default: 0). ``encoding`` If given, must be an encoding name. This encoding will be used to convert the input string to Unicode, if it is not already a Unicode string (default: ``'guess'``, which uses a simple UTF-8 / Locale / Latin1 detection. Can also be ``'chardet'`` to use the chardet library, if it is installed. ``inencoding`` Overrides the ``encoding`` if given. """ #: Name of the lexer name = None #: Shortcuts for the lexer aliases = [] #: File name globs filenames = [] #: Secondary file name globs alias_filenames = [] #: MIME types mimetypes = [] #: Priority, should multiple lexers match and no content is provided priority = 0 def __init__(self, **options): self.options = options self.stripnl = get_bool_opt(options, 'stripnl', True) self.stripall = get_bool_opt(options, 'stripall', False) self.ensurenl = get_bool_opt(options, 'ensurenl', True) self.tabsize = get_int_opt(options, 'tabsize', 0) self.encoding = options.get('encoding', 'guess') self.encoding = options.get('inencoding') or self.encoding self.filters = [] for filter_ in get_list_opt(options, 'filters', ()): self.add_filter(filter_) def __repr__(self): if self.options: return '<pygments.lexers.%s with %r>' % (self.__class__.__name__, self.options) else: return '<pygments.lexers.%s>' % self.__class__.__name__ def add_filter(self, filter_, **options): """ Add a new stream filter to this lexer. """ if not isinstance(filter_, Filter): filter_ = get_filter_by_name(filter_, **options) self.filters.append(filter_) def analyse_text(text): """ Has to return a float between ``0`` and ``1`` that indicates if a lexer wants to highlight this text. Used by ``guess_lexer``. If this method returns ``0`` it won't highlight it in any case, if it returns ``1`` highlighting with this lexer is guaranteed. The `LexerMeta` metaclass automatically wraps this function so that it works like a static method (no ``self`` or ``cls`` parameter) and the return value is automatically converted to `float`. If the return value is an object that is boolean `False` it's the same as if the return values was ``0.0``. """ def get_tokens(self, text, unfiltered=False): """ Return an iterable of (tokentype, value) pairs generated from `text`. If `unfiltered` is set to `True`, the filtering mechanism is bypassed even if filters are defined. Also preprocess the text, i.e. expand tabs and strip it if wanted and applies registered filters. """ if not isinstance(text, text_type): if self.encoding == 'guess': text, _ = guess_decode(text) elif self.encoding == 'chardet': try: import chardet except ImportError: raise ImportError('To enable chardet encoding guessing, ' 'please install the chardet library ' 'from http://chardet.feedparser.org/') # check for BOM first decoded = None for bom, encoding in _encoding_map: if text.startswith(bom): decoded = text[len(bom):].decode(encoding, 'replace') break # no BOM found, so use chardet if decoded is None: enc = chardet.detect(text[:1024]) # Guess using first 1KB decoded = text.decode(enc.get('encoding') or 'utf-8', 'replace') text = decoded else: text = text.decode(self.encoding) if text.startswith(u'\ufeff'): text = text[len(u'\ufeff'):] else: if text.startswith(u'\ufeff'): text = text[len(u'\ufeff'):] # text now *is* a unicode string text = text.replace('\r\n', '\n') text = text.replace('\r', '\n') if self.stripall: text = text.strip() elif self.stripnl: text = text.strip('\n') if self.tabsize > 0: text = text.expandtabs(self.tabsize) if self.ensurenl and not text.endswith('\n'): text += '\n' def streamer(): for _, t, v in self.get_tokens_unprocessed(text): yield t, v stream = streamer() if not unfiltered: stream = apply_filters(stream, self.filters, self) return stream def get_tokens_unprocessed(self, text): """ Return an iterable of (index, tokentype, value) pairs where "index" is the starting position of the token within the input text. In subclasses, implement this method as a generator to maximize effectiveness. """ raise NotImplementedError class DelegatingLexer(Lexer): """ This lexer takes two lexer as arguments. A root lexer and a language lexer. First everything is scanned using the language lexer, afterwards all ``Other`` tokens are lexed using the root lexer. The lexers from the ``template`` lexer package use this base lexer. """ def __init__(self, _root_lexer, _language_lexer, _needle=Other, **options): self.root_lexer = _root_lexer(**options) self.language_lexer = _language_lexer(**options) self.needle = _needle Lexer.__init__(self, **options) def get_tokens_unprocessed(self, text): buffered = '' insertions = [] lng_buffer = [] for i, t, v in self.language_lexer.get_tokens_unprocessed(text): if t is self.needle: if lng_buffer: insertions.append((len(buffered), lng_buffer)) lng_buffer = [] buffered += v else: lng_buffer.append((i, t, v)) if lng_buffer: insertions.append((len(buffered), lng_buffer)) return do_insertions(insertions, self.root_lexer.get_tokens_unprocessed(buffered)) # ------------------------------------------------------------------------------ # RegexLexer and ExtendedRegexLexer # class include(str): # pylint: disable=invalid-name """ Indicates that a state should include rules from another state. """ pass class _inherit(object): """ Indicates the a state should inherit from its superclass. """ def __repr__(self): return 'inherit' inherit = _inherit() # pylint: disable=invalid-name class combined(tuple): # pylint: disable=invalid-name """ Indicates a state combined from multiple states. """ def __new__(cls, *args): return tuple.__new__(cls, args) def __init__(self, *args): # tuple.__init__ doesn't do anything pass class _PseudoMatch(object): """ A pseudo match object constructed from a string. """ def __init__(self, start, text): self._text = text self._start = start def start(self, arg=None): return self._start def end(self, arg=None): return self._start + len(self._text) def group(self, arg=None): if arg: raise IndexError('No such group') return self._text def groups(self): return (self._text,) def groupdict(self): return {} def bygroups(*args): """ Callback that yields multiple actions for each group in the match. """ def callback(lexer, match, ctx=None): for i, action in enumerate(args): if action is None: continue elif type(action) is _TokenType: data = match.group(i + 1) if data: yield match.start(i + 1), action, data else: data = match.group(i + 1) if data is not None: if ctx: ctx.pos = match.start(i + 1) for item in action(lexer, _PseudoMatch(match.start(i + 1), data), ctx): if item: yield item if ctx: ctx.pos = match.end() return callback class _This(object): """ Special singleton used for indicating the caller class. Used by ``using``. """ this = _This() def using(_other, **kwargs): """ Callback that processes the match with a different lexer. The keyword arguments are forwarded to the lexer, except `state` which is handled separately. `state` specifies the state that the new lexer will start in, and can be an enumerable such as ('root', 'inline', 'string') or a simple string which is assumed to be on top of the root state. Note: For that to work, `_other` must not be an `ExtendedRegexLexer`. """ gt_kwargs = {} if 'state' in kwargs: s = kwargs.pop('state') if isinstance(s, (list, tuple)): gt_kwargs['stack'] = s else: gt_kwargs['stack'] = ('root', s) if _other is this: def callback(lexer, match, ctx=None): # if keyword arguments are given the callback # function has to create a new lexer instance if kwargs: # XXX: cache that somehow kwargs.update(lexer.options) lx = lexer.__class__(**kwargs) else: lx = lexer s = match.start() for i, t, v in lx.get_tokens_unprocessed(match.group(), **gt_kwargs): yield i + s, t, v if ctx: ctx.pos = match.end() else: def callback(lexer, match, ctx=None): # XXX: cache that somehow kwargs.update(lexer.options) lx = _other(**kwargs) s = match.start() for i, t, v in lx.get_tokens_unprocessed(match.group(), **gt_kwargs): yield i + s, t, v if ctx: ctx.pos = match.end() return callback class default: """ Indicates a state or state action (e.g. #pop) to apply. For example default('#pop') is equivalent to ('', Token, '#pop') Note that state tuples may be used as well. .. versionadded:: 2.0 """ def __init__(self, state): self.state = state class words(Future): """ Indicates a list of literal words that is transformed into an optimized regex that matches any of the words. .. versionadded:: 2.0 """ def __init__(self, words, prefix='', suffix=''): self.words = words self.prefix = prefix self.suffix = suffix def get(self): return regex_opt(self.words, prefix=self.prefix, suffix=self.suffix) class RegexLexerMeta(LexerMeta): """ Metaclass for RegexLexer, creates the self._tokens attribute from self.tokens on the first instantiation. """ def _process_regex(cls, regex, rflags, state): """Preprocess the regular expression component of a token definition.""" if isinstance(regex, Future): regex = regex.get() return re.compile(regex, rflags).match def _process_token(cls, token): """Preprocess the token component of a token definition.""" assert type(token) is _TokenType or callable(token), \ 'token type must be simple type or callable, not %r' % (token,) return token def _process_new_state(cls, new_state, unprocessed, processed): """Preprocess the state transition action of a token definition.""" if isinstance(new_state, str): # an existing state if new_state == '#pop': return -1 elif new_state in unprocessed: return (new_state,) elif new_state == '#push': return new_state elif new_state[:5] == '#pop:': return -int(new_state[5:]) else: assert False, 'unknown new state %r' % new_state elif isinstance(new_state, combined): # combine a new state from existing ones tmp_state = '_tmp_%d' % cls._tmpname cls._tmpname += 1 itokens = [] for istate in new_state: assert istate != new_state, 'circular state ref %r' % istate itokens.extend(cls._process_state(unprocessed, processed, istate)) processed[tmp_state] = itokens return (tmp_state,) elif isinstance(new_state, tuple): # push more than one state for istate in new_state: assert (istate in unprocessed or istate in ('#pop', '#push')), \ 'unknown new state ' + istate return new_state else: assert False, 'unknown new state def %r' % new_state def _process_state(cls, unprocessed, processed, state): """Preprocess a single state definition.""" assert type(state) is str, "wrong state name %r" % state assert state[0] != '#', "invalid state name %r" % state if state in processed: return processed[state] tokens = processed[state] = [] rflags = cls.flags for tdef in unprocessed[state]: if isinstance(tdef, include): # it's a state reference assert tdef != state, "circular state reference %r" % state tokens.extend(cls._process_state(unprocessed, processed, str(tdef))) continue if isinstance(tdef, _inherit): # should be processed already, but may not in the case of: # 1. the state has no counterpart in any parent # 2. the state includes more than one 'inherit' continue if isinstance(tdef, default): new_state = cls._process_new_state(tdef.state, unprocessed, processed) tokens.append((re.compile('').match, None, new_state)) continue assert type(tdef) is tuple, "wrong rule def %r" % tdef try: rex = cls._process_regex(tdef[0], rflags, state) except Exception as err: raise ValueError("uncompilable regex %r in state %r of %r: %s" % (tdef[0], state, cls, err)) token = cls._process_token(tdef[1]) if len(tdef) == 2: new_state = None else: new_state = cls._process_new_state(tdef[2], unprocessed, processed) tokens.append((rex, token, new_state)) return tokens def process_tokendef(cls, name, tokendefs=None): """Preprocess a dictionary of token definitions.""" processed = cls._all_tokens[name] = {} tokendefs = tokendefs or cls.tokens[name] for state in list(tokendefs): cls._process_state(tokendefs, processed, state) return processed def get_tokendefs(cls): """ Merge tokens from superclasses in MRO order, returning a single tokendef dictionary. Any state that is not defined by a subclass will be inherited automatically. States that *are* defined by subclasses will, by default, override that state in the superclass. If a subclass wishes to inherit definitions from a superclass, it can use the special value "inherit", which will cause the superclass' state definition to be included at that point in the state. """ tokens = {} inheritable = {} for c in cls.__mro__: toks = c.__dict__.get('tokens', {}) for state, items in iteritems(toks): curitems = tokens.get(state) if curitems is None: # N.b. because this is assigned by reference, sufficiently # deep hierarchies are processed incrementally (e.g. for # A(B), B(C), C(RegexLexer), B will be premodified so X(B) # will not see any inherits in B). tokens[state] = items try: inherit_ndx = items.index(inherit) except ValueError: continue inheritable[state] = inherit_ndx continue inherit_ndx = inheritable.pop(state, None) if inherit_ndx is None: continue # Replace the "inherit" value with the items curitems[inherit_ndx:inherit_ndx+1] = items try: # N.b. this is the index in items (that is, the superclass # copy), so offset required when storing below. new_inh_ndx = items.index(inherit) except ValueError: pass else: inheritable[state] = inherit_ndx + new_inh_ndx return tokens def __call__(cls, *args, **kwds): """Instantiate cls after preprocessing its token definitions.""" if '_tokens' not in cls.__dict__: cls._all_tokens = {} cls._tmpname = 0 if hasattr(cls, 'token_variants') and cls.token_variants: # don't process yet pass else: cls._tokens = cls.process_tokendef('', cls.get_tokendefs()) return type.__call__(cls, *args, **kwds) @add_metaclass(RegexLexerMeta) class RegexLexer(Lexer): """ Base for simple stateful regular expression-based lexers. Simplifies the lexing process so that you need only provide a list of states and regular expressions. """ #: Flags for compiling the regular expressions. #: Defaults to MULTILINE. flags = re.MULTILINE #: Dict of ``{'state': [(regex, tokentype, new_state), ...], ...}`` #: #: The initial state is 'root'. #: ``new_state`` can be omitted to signify no state transition. #: If it is a string, the state is pushed on the stack and changed. #: If it is a tuple of strings, all states are pushed on the stack and #: the current state will be the topmost. #: It can also be ``combined('state1', 'state2', ...)`` #: to signify a new, anonymous state combined from the rules of two #: or more existing ones. #: Furthermore, it can be '#pop' to signify going back one step in #: the state stack, or '#push' to push the current state on the stack #: again. #: #: The tuple can also be replaced with ``include('state')``, in which #: case the rules from the state named by the string are included in the #: current one. tokens = {} def get_tokens_unprocessed(self, text, stack=('root',)): """ Split ``text`` into (tokentype, text) pairs. ``stack`` is the inital stack (default: ``['root']``) """ pos = 0 tokendefs = self._tokens statestack = list(stack) statetokens = tokendefs[statestack[-1]] while 1: for rexmatch, action, new_state in statetokens: m = rexmatch(text, pos) if m: if action is not None: if type(action) is _TokenType: yield pos, action, m.group() else: for item in action(self, m): yield item pos = m.end() if new_state is not None: # state transition if isinstance(new_state, tuple): for state in new_state: if state == '#pop': statestack.pop() elif state == '#push': statestack.append(statestack[-1]) else: statestack.append(state) elif isinstance(new_state, int): # pop del statestack[new_state:] elif new_state == '#push': statestack.append(statestack[-1]) else: assert False, "wrong state def: %r" % new_state statetokens = tokendefs[statestack[-1]] break else: # We are here only if all state tokens have been considered # and there was not a match on any of them. try: if text[pos] == '\n': # at EOL, reset state to "root" statestack = ['root'] statetokens = tokendefs['root'] yield pos, Text, u'\n' pos += 1 continue yield pos, Error, text[pos] pos += 1 except IndexError: break class LexerContext(object): """ A helper object that holds lexer position data. """ def __init__(self, text, pos, stack=None, end=None): self.text = text self.pos = pos self.end = end or len(text) # end=0 not supported ;-) self.stack = stack or ['root'] def __repr__(self): return 'LexerContext(%r, %r, %r)' % ( self.text, self.pos, self.stack) class ExtendedRegexLexer(RegexLexer): """ A RegexLexer that uses a context object to store its state. """ def get_tokens_unprocessed(self, text=None, context=None): """ Split ``text`` into (tokentype, text) pairs. If ``context`` is given, use this lexer context instead. """ tokendefs = self._tokens if not context: ctx = LexerContext(text, 0) statetokens = tokendefs['root'] else: ctx = context statetokens = tokendefs[ctx.stack[-1]] text = ctx.text while 1: for rexmatch, action, new_state in statetokens: m = rexmatch(text, ctx.pos, ctx.end) if m: if action is not None: if type(action) is _TokenType: yield ctx.pos, action, m.group() ctx.pos = m.end() else: for item in action(self, m, ctx): yield item if not new_state: # altered the state stack? statetokens = tokendefs[ctx.stack[-1]] # CAUTION: callback must set ctx.pos! if new_state is not None: # state transition if isinstance(new_state, tuple): for state in new_state: if state == '#pop': ctx.stack.pop() elif state == '#push': ctx.stack.append(ctx.stack[-1]) else: ctx.stack.append(state) elif isinstance(new_state, int): # pop del ctx.stack[new_state:] elif new_state == '#push': ctx.stack.append(ctx.stack[-1]) else: assert False, "wrong state def: %r" % new_state statetokens = tokendefs[ctx.stack[-1]] break else: try: if ctx.pos >= ctx.end: break if text[ctx.pos] == '\n': # at EOL, reset state to "root" ctx.stack = ['root'] statetokens = tokendefs['root'] yield ctx.pos, Text, u'\n' ctx.pos += 1 continue yield ctx.pos, Error, text[ctx.pos] ctx.pos += 1 except IndexError: break def do_insertions(insertions, tokens): """ Helper for lexers which must combine the results of several sublexers. ``insertions`` is a list of ``(index, itokens)`` pairs. Each ``itokens`` iterable should be inserted at position ``index`` into the token stream given by the ``tokens`` argument. The result is a combined token stream. TODO: clean up the code here. """ insertions = iter(insertions) try: index, itokens = next(insertions) except StopIteration: # no insertions for item in tokens: yield item return realpos = None insleft = True # iterate over the token stream where we want to insert # the tokens from the insertion list. for i, t, v in tokens: # first iteration. store the postition of first item if realpos is None: realpos = i oldi = 0 while insleft and i + len(v) >= index: tmpval = v[oldi:index - i] yield realpos, t, tmpval realpos += len(tmpval) for it_index, it_token, it_value in itokens: yield realpos, it_token, it_value realpos += len(it_value) oldi = index - i try: index, itokens = next(insertions) except StopIteration: insleft = False break # not strictly necessary yield realpos, t, v[oldi:] realpos += len(v) - oldi # leftover tokens while insleft: # no normal tokens, set realpos to zero realpos = realpos or 0 for p, t, v in itokens: yield realpos, t, v realpos += len(v) try: index, itokens = next(insertions) except StopIteration: insleft = False break # not strictly necessary class ProfilingRegexLexerMeta(RegexLexerMeta): """Metaclass for ProfilingRegexLexer, collects regex timing info.""" def _process_regex(cls, regex, rflags, state): if isinstance(regex, words): rex = regex_opt(regex.words, prefix=regex.prefix, suffix=regex.suffix) else: rex = regex compiled = re.compile(rex, rflags) def match_func(text, pos, endpos=sys.maxsize): info = cls._prof_data[-1].setdefault((state, rex), [0, 0.0]) t0 = time.time() res = compiled.match(text, pos, endpos) t1 = time.time() info[0] += 1 info[1] += t1 - t0 return res return match_func @add_metaclass(ProfilingRegexLexerMeta) class ProfilingRegexLexer(RegexLexer): """Drop-in replacement for RegexLexer that does profiling of its regexes.""" _prof_data = [] _prof_sort_index = 4 # defaults to time per call def get_tokens_unprocessed(self, text, stack=('root',)): # this needs to be a stack, since using(this) will produce nested calls self.__class__._prof_data.append({}) for tok in RegexLexer.get_tokens_unprocessed(self, text, stack): yield tok rawdata = self.__class__._prof_data.pop() data = sorted(((s, repr(r).strip('u\'').replace('\\\\', '\\')[:65], n, 1000 * t, 1000 * t / n) for ((s, r), (n, t)) in rawdata.items()), key=lambda x: x[self._prof_sort_index], reverse=True) sum_total = sum(x[3] for x in data) print() print('Profiling result for %s lexing %d chars in %.3f ms' % (self.__class__.__name__, len(text), sum_total)) print('=' * 110) print('%-20s %-64s ncalls tottime percall' % ('state', 'regex')) print('-' * 110) for d in data: print('%-20s %-65s %5d %8.4f %8.4f' % d) print('=' * 110)
bsd-3-clause
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 13277, 14, 11729, 272, 32202, 1714, 339, 3523, 10426, 3992, 14, 339, 520, 7307, 26, 1898, 8315, 13, 10680, 701, 314, 14493, 8099, 12, 1937, 10610, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 2436, 14, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 295, 199, 646, 984, 199, 646, 900, 199, 199, 504, 13277, 14, 1541, 492, 4838, 63, 4273, 12, 9388, 199, 504, 13277, 14, 4273, 492, 664, 63, 1541, 63, 991, 63, 354, 199, 504, 13277, 14, 1418, 492, 4520, 12, 4516, 12, 5439, 12, 485, 3264, 804, 199, 504, 13277, 14, 1974, 492, 664, 63, 2245, 63, 2992, 12, 664, 63, 442, 63, 2992, 12, 664, 63, 513, 63, 2992, 12, 971, 272, 1852, 63, 290, 279, 588, 707, 12, 1318, 63, 466, 12, 1050, 63, 6577, 12, 10849, 12, 20799, 12, 9519, 63, 2708, 199, 504, 13277, 14, 3821, 2992, 492, 5163, 63, 2992, 199, 199, 363, 452, 363, 275, 788, 5838, 297, 283, 19856, 297, 283, 14107, 19856, 297, 283, 3896, 71, 1958, 5838, 297, 1779, 283, 5838, 2998, 297, 283, 2613, 297, 283, 6486, 297, 283, 991, 2634, 297, 283, 4941, 297, 283, 3749, 297, 1779, 283, 885, 297, 283, 3148, 418, 421, 199, 63, 2991, 63, 1130, 275, 3842, 66, 1154, 9532, 60, 9932, 60, 9566, 297, 283, 1624, 13, 24, 659, 326, 334, 66, 1154, 3581, 60, 8371, 60, 16, 60, 16, 297, 283, 1624, 13, 708, 659, 326, 334, 66, 1154, 16, 60, 16, 60, 8371, 60, 3581, 297, 283, 1624, 13, 708, 1235, 659, 326, 334, 66, 1154, 3581, 60, 8371, 297, 283, 1624, 13, 975, 659, 326, 334, 66, 1154, 8371, 60, 3581, 297, 283, 1624, 13, 975, 1235, 5440, 199, 199, 63, 885, 63, 26943, 275, 12822, 8, 2734, 671, 26, 378, 14, 16, 9, 421, 199, 533, 21125, 3396, 8, 466, 304, 272, 408, 272, 961, 17074, 2599, 5615, 7288, 15373, 1124, 26943, 63, 505, 1040, 3102, 1901, 272, 2955, 3102, 1314, 3544, 372, 2069, 1338, 14, 272, 408, 339, 347, 636, 1222, 721, 77, 1259, 12, 536, 12, 9768, 12, 366, 304, 267, 340, 283, 26943, 63, 505, 7, 315, 366, 26, 288, 366, 459, 26943, 63, 505, 418, 275, 1852, 63, 290, 279, 588, 707, 8, 68, 459, 26943, 63, 505, 1105, 267, 372, 730, 855, 1222, 721, 77, 1259, 12, 536, 12, 9768, 12, 366, 9, 421, 199, 32, 525, 63, 6577, 8, 5838, 3396, 9, 199, 533, 21125, 8, 785, 304, 272, 408, 272, 21125, 367, 282, 2488, 2637, 14, 339, 10082, 1511, 18054, 26, 272, 1124, 1913, 7530, 1040, 267, 19828, 9186, 436, 8520, 14930, 687, 314, 1324, 334, 885, 26, 715, 680, 272, 1124, 1913, 452, 1040, 267, 19828, 1006, 9186, 436, 8520, 8139, 687, 314, 1324, 267, 334, 885, 26, 756, 680, 272, 1124, 7505, 7530, 1040, 267, 4155, 3238, 626, 314, 1324, 11187, 543, 282, 8057, 334, 885, 26, 715, 680, 221, 961, 267, 365, 1415, 367, 2005, 7103, 1192, 626, 9451, 1324, 7403, 546, 572, 14, 398, 2508, 7445, 447, 413, 14, 19, 339, 1124, 2902, 890, 1040, 267, 982, 1627, 436, 8932, 2419, 378, 12, 6544, 12187, 315, 314, 1324, 334, 885, 26, 378, 680, 272, 1124, 2991, 1040, 267, 982, 1627, 12, 1471, 506, 376, 2644, 536, 14, 961, 2644, 911, 506, 1202, 370, 267, 3957, 314, 1324, 1059, 370, 6140, 12, 340, 652, 365, 440, 2575, 282, 6140, 267, 1059, 334, 885, 26, 12692, 11636, 31638, 1314, 4440, 282, 3486, 9094, 13, 24, 1182, 28298, 1182, 267, 23864, 17, 15212, 14, 221, 6855, 2597, 506, 12692, 1560, 9886, 14700, 370, 675, 314, 28470, 267, 3555, 12, 340, 652, 365, 4903, 14, 272, 1124, 262, 2991, 1040, 267, 31144, 314, 1124, 2991, 1040, 340, 1627, 14, 272, 408, 339, 6079, 2812, 402, 314, 10426, 272, 536, 275, 488, 339, 6079, 20124, 12946, 367, 314, 10426, 272, 5481, 275, 942, 339, 6079, 3814, 536, 13977, 272, 6203, 275, 942, 339, 6079, 16707, 695, 570, 536, 13977, 272, 5162, 63, 10309, 275, 942, 339, 6079, 14735, 2943, 272, 13290, 275, 942, 339, 6079, 8538, 3822, 12, 1077, 3663, 7103, 1192, 1336, 436, 949, 1564, 365, 2741, 272, 7464, 275, 378, 339, 347, 636, 826, 721, 277, 12, 1011, 1419, 304, 267, 291, 14, 1419, 275, 1511, 267, 291, 14, 1913, 7530, 275, 664, 63, 2245, 63, 2992, 8, 1419, 12, 283, 1913, 7530, 297, 715, 9, 267, 291, 14, 1913, 452, 275, 664, 63, 2245, 63, 2992, 8, 1419, 12, 283, 1913, 452, 297, 756, 9, 267, 291, 14, 7505, 7530, 275, 664, 63, 2245, 63, 2992, 8, 1419, 12, 283, 7505, 7530, 297, 715, 9, 267, 291, 14, 2902, 890, 275, 664, 63, 442, 63, 2992, 8, 1419, 12, 283, 2902, 890, 297, 378, 9, 267, 291, 14, 2991, 275, 1511, 14, 362, 360, 2991, 297, 283, 11636, 358, 267, 291, 14, 2991, 275, 1511, 14, 362, 360, 262, 2991, 358, 503, 291, 14, 2991, 267, 291, 14, 4273, 275, 942, 267, 367, 2457, 63, 315, 664, 63, 513, 63, 2992, 8, 1419, 12, 283, 4273, 297, 334, 2298, 288, 291, 14, 525, 63, 1541, 8, 1541, 4602, 339, 347, 636, 2722, 721, 277, 304, 267, 340, 291, 14, 1419, 26, 288, 372, 2650, 12173, 14, 12245, 4111, 83, 543, 450, 82, 3524, 450, 334, 277, 855, 533, 4914, 354, 3108, 9349, 291, 14, 1419, 9, 267, 587, 26, 288, 372, 2650, 12173, 14, 12245, 4111, 83, 3524, 450, 291, 855, 533, 4914, 354, 363, 339, 347, 1050, 63, 1541, 8, 277, 12, 2457, 3131, 1011, 1419, 304, 267, 408, 267, 2654, 282, 892, 2547, 2457, 370, 642, 10426, 14, 267, 408, 267, 340, 440, 1228, 8, 1541, 3131, 9388, 304, 288, 2457, 63, 275, 664, 63, 1541, 63, 991, 63, 354, 8, 1541, 3131, 1011, 1419, 9, 267, 291, 14, 4273, 14, 740, 8, 1541, 4602, 339, 347, 21297, 63, 505, 8, 505, 304, 267, 408, 267, 13481, 370, 372, 282, 2069, 3382, 1124, 16, 1040, 436, 1124, 17, 1040, 626, 9126, 267, 340, 282, 10426, 15061, 370, 11850 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 13277, 14, 11729, 272, 32202, 1714, 339, 3523, 10426, 3992, 14, 339, 520, 7307, 26, 1898, 8315, 13, 10680, 701, 314, 14493, 8099, 12, 1937, 10610, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 2436, 14, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 295, 199, 646, 984, 199, 646, 900, 199, 199, 504, 13277, 14, 1541, 492, 4838, 63, 4273, 12, 9388, 199, 504, 13277, 14, 4273, 492, 664, 63, 1541, 63, 991, 63, 354, 199, 504, 13277, 14, 1418, 492, 4520, 12, 4516, 12, 5439, 12, 485, 3264, 804, 199, 504, 13277, 14, 1974, 492, 664, 63, 2245, 63, 2992, 12, 664, 63, 442, 63, 2992, 12, 664, 63, 513, 63, 2992, 12, 971, 272, 1852, 63, 290, 279, 588, 707, 12, 1318, 63, 466, 12, 1050, 63, 6577, 12, 10849, 12, 20799, 12, 9519, 63, 2708, 199, 504, 13277, 14, 3821, 2992, 492, 5163, 63, 2992, 199, 199, 363, 452, 363, 275, 788, 5838, 297, 283, 19856, 297, 283, 14107, 19856, 297, 283, 3896, 71, 1958, 5838, 297, 1779, 283, 5838, 2998, 297, 283, 2613, 297, 283, 6486, 297, 283, 991, 2634, 297, 283, 4941, 297, 283, 3749, 297, 1779, 283, 885, 297, 283, 3148, 418, 421, 199, 63, 2991, 63, 1130, 275, 3842, 66, 1154, 9532, 60, 9932, 60, 9566, 297, 283, 1624, 13, 24, 659, 326, 334, 66, 1154, 3581, 60, 8371, 60, 16, 60, 16, 297, 283, 1624, 13, 708, 659, 326, 334, 66, 1154, 16, 60, 16, 60, 8371, 60, 3581, 297, 283, 1624, 13, 708, 1235, 659, 326, 334, 66, 1154, 3581, 60, 8371, 297, 283, 1624, 13, 975, 659, 326, 334, 66, 1154, 8371, 60, 3581, 297, 283, 1624, 13, 975, 1235, 5440, 199, 199, 63, 885, 63, 26943, 275, 12822, 8, 2734, 671, 26, 378, 14, 16, 9, 421, 199, 533, 21125, 3396, 8, 466, 304, 272, 408, 272, 961, 17074, 2599, 5615, 7288, 15373, 1124, 26943, 63, 505, 1040, 3102, 1901, 272, 2955, 3102, 1314, 3544, 372, 2069, 1338, 14, 272, 408, 339, 347, 636, 1222, 721, 77, 1259, 12, 536, 12, 9768, 12, 366, 304, 267, 340, 283, 26943, 63, 505, 7, 315, 366, 26, 288, 366, 459, 26943, 63, 505, 418, 275, 1852, 63, 290, 279, 588, 707, 8, 68, 459, 26943, 63, 505, 1105, 267, 372, 730, 855, 1222, 721, 77, 1259, 12, 536, 12, 9768, 12, 366, 9, 421, 199, 32, 525, 63, 6577, 8, 5838, 3396, 9, 199, 533, 21125, 8, 785, 304, 272, 408, 272, 21125, 367, 282, 2488, 2637, 14, 339, 10082, 1511, 18054, 26, 272, 1124, 1913, 7530, 1040, 267, 19828, 9186, 436, 8520, 14930, 687, 314, 1324, 334, 885, 26, 715, 680, 272, 1124, 1913, 452, 1040, 267, 19828, 1006, 9186, 436, 8520, 8139, 687, 314, 1324, 267, 334, 885, 26, 756, 680, 272, 1124, 7505, 7530, 1040, 267, 4155, 3238, 626, 314, 1324, 11187, 543, 282, 8057, 334, 885, 26, 715, 680, 221, 961, 267, 365, 1415, 367, 2005, 7103, 1192, 626, 9451, 1324, 7403, 546, 572, 14, 398, 2508, 7445, 447, 413, 14, 19, 339, 1124, 2902, 890, 1040, 267, 982, 1627, 436, 8932, 2419, 378, 12, 6544, 12187, 315, 314, 1324, 334, 885, 26, 378, 680, 272, 1124, 2991, 1040, 267, 982, 1627, 12, 1471, 506, 376, 2644, 536, 14, 961, 2644, 911, 506, 1202, 370, 267, 3957, 314, 1324, 1059, 370, 6140, 12, 340, 652, 365, 440, 2575, 282, 6140, 267, 1059, 334, 885, 26, 12692, 11636, 31638, 1314, 4440, 282, 3486, 9094, 13, 24, 1182, 28298, 1182, 267, 23864, 17, 15212, 14, 221, 6855, 2597, 506, 12692, 1560, 9886, 14700, 370, 675, 314, 28470, 267, 3555, 12, 340, 652, 365, 4903, 14, 272, 1124, 262, 2991, 1040, 267, 31144, 314, 1124, 2991, 1040, 340, 1627, 14, 272, 408, 339, 6079, 2812, 402, 314, 10426, 272, 536, 275, 488, 339, 6079, 20124, 12946, 367, 314, 10426, 272, 5481, 275, 942, 339, 6079, 3814, 536, 13977, 272, 6203, 275, 942, 339, 6079, 16707, 695, 570, 536, 13977, 272, 5162, 63, 10309, 275, 942, 339, 6079, 14735, 2943, 272, 13290, 275, 942, 339, 6079, 8538, 3822, 12, 1077, 3663, 7103, 1192, 1336, 436, 949, 1564, 365, 2741, 272, 7464, 275, 378, 339, 347, 636, 826, 721, 277, 12, 1011, 1419, 304, 267, 291, 14, 1419, 275, 1511, 267, 291, 14, 1913, 7530, 275, 664, 63, 2245, 63, 2992, 8, 1419, 12, 283, 1913, 7530, 297, 715, 9, 267, 291, 14, 1913, 452, 275, 664, 63, 2245, 63, 2992, 8, 1419, 12, 283, 1913, 452, 297, 756, 9, 267, 291, 14, 7505, 7530, 275, 664, 63, 2245, 63, 2992, 8, 1419, 12, 283, 7505, 7530, 297, 715, 9, 267, 291, 14, 2902, 890, 275, 664, 63, 442, 63, 2992, 8, 1419, 12, 283, 2902, 890, 297, 378, 9, 267, 291, 14, 2991, 275, 1511, 14, 362, 360, 2991, 297, 283, 11636, 358, 267, 291, 14, 2991, 275, 1511, 14, 362, 360, 262, 2991, 358, 503, 291, 14, 2991, 267, 291, 14, 4273, 275, 942, 267, 367, 2457, 63, 315, 664, 63, 513, 63, 2992, 8, 1419, 12, 283, 4273, 297, 334, 2298, 288, 291, 14, 525, 63, 1541, 8, 1541, 4602, 339, 347, 636, 2722, 721, 277, 304, 267, 340, 291, 14, 1419, 26, 288, 372, 2650, 12173, 14, 12245, 4111, 83, 543, 450, 82, 3524, 450, 334, 277, 855, 533, 4914, 354, 3108, 9349, 291, 14, 1419, 9, 267, 587, 26, 288, 372, 2650, 12173, 14, 12245, 4111, 83, 3524, 450, 291, 855, 533, 4914, 354, 363, 339, 347, 1050, 63, 1541, 8, 277, 12, 2457, 3131, 1011, 1419, 304, 267, 408, 267, 2654, 282, 892, 2547, 2457, 370, 642, 10426, 14, 267, 408, 267, 340, 440, 1228, 8, 1541, 3131, 9388, 304, 288, 2457, 63, 275, 664, 63, 1541, 63, 991, 63, 354, 8, 1541, 3131, 1011, 1419, 9, 267, 291, 14, 4273, 14, 740, 8, 1541, 4602, 339, 347, 21297, 63, 505, 8, 505, 304, 267, 408, 267, 13481, 370, 372, 282, 2069, 3382, 1124, 16, 1040, 436, 1124, 17, 1040, 626, 9126, 267, 340, 282, 10426, 15061, 370, 11850, 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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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
jiaphuan/models
samples/outreach/blogs/blog_estimators_dataset.py
6
6245
# 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. # ============================================================================== # This is the complete code for the following blogpost: # https://developers.googleblog.com/2017/09/introducing-tensorflow-datasets.html # (https://goo.gl/Ujm2Ep) import os import six.moves.urllib.request as request import tensorflow as tf # Check that we have correct TensorFlow version installed tf_version = tf.__version__ print("TensorFlow version: {}".format(tf_version)) assert "1.4" <= tf_version, "TensorFlow r1.4 or later is needed" # Windows users: You only need to change PATH, rest is platform independent PATH = "/tmp/tf_dataset_and_estimator_apis" # Fetch and store Training and Test dataset files PATH_DATASET = PATH + os.sep + "dataset" FILE_TRAIN = PATH_DATASET + os.sep + "iris_training.csv" FILE_TEST = PATH_DATASET + os.sep + "iris_test.csv" URL_TRAIN = "http://download.tensorflow.org/data/iris_training.csv" URL_TEST = "http://download.tensorflow.org/data/iris_test.csv" def download_dataset(url, file): if not os.path.exists(PATH_DATASET): os.makedirs(PATH_DATASET) if not os.path.exists(file): data = request.urlopen(url).read() with open(file, "wb") as f: f.write(data) f.close() download_dataset(URL_TRAIN, FILE_TRAIN) download_dataset(URL_TEST, FILE_TEST) tf.logging.set_verbosity(tf.logging.INFO) # The CSV features in our training & test data feature_names = [ 'SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'] # Create an input function reading a file using the Dataset API # Then provide the results to the Estimator API def my_input_fn(file_path, perform_shuffle=False, repeat_count=1): def decode_csv(line): parsed_line = tf.decode_csv(line, [[0.], [0.], [0.], [0.], [0]]) label = parsed_line[-1] # Last element is the label del parsed_line[-1] # Delete last element features = parsed_line # Everything but last elements are the features d = dict(zip(feature_names, features)), label return d dataset = (tf.data.TextLineDataset(file_path) # Read text file .skip(1) # Skip header row .map(decode_csv)) # Transform each elem by applying decode_csv fn if perform_shuffle: # Randomizes input using a window of 256 elements (read into memory) dataset = dataset.shuffle(buffer_size=256) dataset = dataset.repeat(repeat_count) # Repeats dataset this # times dataset = dataset.batch(32) # Batch size to use iterator = dataset.make_one_shot_iterator() batch_features, batch_labels = iterator.get_next() return batch_features, batch_labels next_batch = my_input_fn(FILE_TRAIN, True) # Will return 32 random elements # Create the feature_columns, which specifies the input to our model # All our input features are numeric, so use numeric_column for each one feature_columns = [tf.feature_column.numeric_column(k) for k in feature_names] # Create a deep neural network regression classifier # Use the DNNClassifier pre-made estimator classifier = tf.estimator.DNNClassifier( feature_columns=feature_columns, # The input features to our model hidden_units=[10, 10], # Two layers, each with 10 neurons n_classes=3, model_dir=PATH) # Path to where checkpoints etc are stored # Train our model, use the previously defined function my_input_fn # Input to training is a file with training example # Stop training after 8 iterations of train data (epochs) classifier.train( input_fn=lambda: my_input_fn(FILE_TRAIN, True, 8)) # Evaluate our model using the examples contained in FILE_TEST # Return value will contain evaluation_metrics such as: loss & average_loss evaluate_result = classifier.evaluate( input_fn=lambda: my_input_fn(FILE_TEST, False, 4)) print("Evaluation results") for key in evaluate_result: print(" {}, was: {}".format(key, evaluate_result[key])) # Predict the type of some Iris flowers. # Let's predict the examples in FILE_TEST, repeat only once. predict_results = classifier.predict( input_fn=lambda: my_input_fn(FILE_TEST, False, 1)) print("Predictions on test file") for prediction in predict_results: # Will print the predicted class, i.e: 0, 1, or 2 if the prediction # is Iris Sentosa, Vericolor, Virginica, respectively. print(prediction["class_ids"][0]) # Let create a dataset for prediction # We've taken the first 3 examples in FILE_TEST prediction_input = [[5.9, 3.0, 4.2, 1.5], # -> 1, Iris Versicolor [6.9, 3.1, 5.4, 2.1], # -> 2, Iris Virginica [5.1, 3.3, 1.7, 0.5]] # -> 0, Iris Sentosa def new_input_fn(): def decode(x): x = tf.split(x, 4) # Need to split into our 4 features return dict(zip(feature_names, x)) # To build a dict of them dataset = tf.data.Dataset.from_tensor_slices(prediction_input) dataset = dataset.map(decode) iterator = dataset.make_one_shot_iterator() next_feature_batch = iterator.get_next() return next_feature_batch, None # In prediction, we have no labels # Predict all our prediction_input predict_results = classifier.predict(input_fn=new_input_fn) # Print results print("Predictions:") for idx, prediction in enumerate(predict_results): type = prediction["class_ids"][0] # Get the predicted class (index) if type == 0: print(" I think: {}, is Iris Sentosa".format(prediction_input[idx])) elif type == 1: print(" I think: {}, is Iris Versicolor".format(prediction_input[idx])) else: print(" I think: {}, is Iris Virginica".format(prediction_input[idx]))
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, 199, 3, 961, 365, 314, 4890, 1233, 367, 314, 2569, 19936, 1932, 26, 199, 3, 4178, 921, 23826, 14, 3098, 11486, 14, 957, 15, 10680, 15, 1643, 15, 18206, 14713, 13, 16008, 13, 12281, 14, 1360, 199, 3, 257, 334, 2859, 921, 29546, 14, 3528, 15, 53, 74, 77, 18, 14057, 9, 199, 199, 646, 747, 199, 199, 646, 3816, 14, 4912, 14, 4078, 14, 1069, 465, 1056, 199, 646, 3228, 465, 2833, 199, 199, 3, 2670, 626, 781, 1172, 3211, 9134, 1015, 4903, 199, 3249, 63, 1023, 275, 2833, 855, 1023, 363, 199, 1361, 480, 26998, 1015, 26, 8352, 908, 8, 3249, 63, 1023, 430, 199, 479, 298, 17, 14, 20, 2, 2695, 2833, 63, 1023, 12, 298, 26998, 519, 17, 14, 20, 503, 2945, 365, 4346, 2, 199, 199, 3, 5417, 4390, 26, 2047, 1454, 1929, 370, 1570, 15097, 12, 4618, 365, 4298, 12717, 199, 3243, 275, 3286, 2791, 15, 3249, 63, 5214, 63, 460, 63, 8627, 63, 12662, 2, 199, 199, 3, 16347, 436, 3877, 22859, 436, 1379, 4789, 1584, 199, 3243, 63, 28231, 775, 275, 15097, 435, 747, 14, 4127, 435, 298, 5214, 2, 199, 3817, 63, 18473, 275, 15097, 63, 28231, 775, 435, 747, 14, 4127, 435, 298, 11885, 63, 7588, 14, 4737, 2, 199, 3817, 63, 2864, 275, 15097, 63, 28231, 775, 435, 747, 14, 4127, 435, 298, 11885, 63, 396, 14, 4737, 2, 199, 2632, 63, 18473, 275, 298, 1014, 921, 4249, 14, 16008, 14, 1308, 15, 576, 15, 11885, 63, 7588, 14, 4737, 2, 199, 2632, 63, 2864, 275, 298, 1014, 921, 4249, 14, 16008, 14, 1308, 15, 576, 15, 11885, 63, 396, 14, 4737, 2, 421, 199, 318, 5235, 63, 5214, 8, 633, 12, 570, 304, 272, 340, 440, 747, 14, 515, 14, 2444, 8, 3243, 63, 28231, 775, 304, 267, 747, 14, 8347, 8, 3243, 63, 28231, 775, 9, 272, 340, 440, 747, 14, 515, 14, 2444, 8, 493, 304, 267, 666, 275, 1056, 14, 10890, 8, 633, 680, 739, 342, 267, 543, 1551, 8, 493, 12, 298, 6603, 531, 465, 289, 26, 288, 289, 14, 952, 8, 576, 9, 288, 289, 14, 1600, 342, 199, 4249, 63, 5214, 8, 2632, 63, 18473, 12, 13024, 63, 18473, 9, 199, 4249, 63, 5214, 8, 2632, 63, 2864, 12, 13024, 63, 2864, 9, 199, 199, 3249, 14, 4806, 14, 409, 63, 9833, 8, 3249, 14, 4806, 14, 4531, 9, 199, 199, 3, 710, 14689, 4534, 315, 4154, 6093, 1253, 511, 666, 199, 4445, 63, 1247, 275, 359, 272, 283, 1513, 21516, 4625, 297, 272, 283, 1513, 21516, 6216, 297, 272, 283, 48, 386, 279, 4625, 297, 272, 283, 48, 386, 279, 6216, 418, 199, 199, 3, 2790, 376, 1324, 805, 7664, 282, 570, 1808, 314, 20284, 3261, 199, 3, 9442, 5647, 314, 2058, 370, 314, 28992, 3261, 421, 199, 318, 3002, 63, 1210, 63, 2324, 8, 493, 63, 515, 12, 5147, 63, 11777, 29, 797, 12, 11982, 63, 835, 29, 17, 304, 272, 347, 4849, 63, 4737, 8, 604, 304, 267, 4565, 63, 604, 275, 2833, 14, 2708, 63, 4737, 8, 604, 12, 3474, 16, 8333, 359, 16, 8333, 359, 16, 8333, 359, 16, 8333, 359, 16, 3934, 267, 1768, 275, 4565, 63, 604, 1988, 17, 61, 221, 327, 15237, 1819, 365, 314, 1768, 267, 2150, 4565, 63, 604, 1988, 17, 61, 221, 327, 8496, 2061, 1819, 267, 4534, 275, 4565, 63, 604, 221, 327, 18414, 2127, 1325, 2061, 4008, 787, 314, 4534, 267, 366, 275, 1211, 8, 3065, 8, 4445, 63, 1247, 12, 4534, 1826, 1768, 267, 372, 366, 339, 4789, 275, 334, 3249, 14, 576, 14, 1872, 3049, 9271, 8, 493, 63, 515, 9, 221, 327, 5574, 1318, 570, 2049, 1275, 2759, 8, 17, 9, 221, 327, 8232, 1406, 1962, 2049, 1275, 1130, 8, 2708, 63, 4737, 430, 221, 327, 19463, 1924, 6193, 701, 18876, 4849, 63, 4737, 4325, 272, 340, 5147, 63, 11777, 26, 267, 327, 9571, 6491, 1324, 1808, 282, 4353, 402, 7633, 4008, 334, 739, 1901, 4402, 9, 267, 4789, 275, 4789, 14, 11777, 8, 2738, 63, 890, 29, 3912, 9, 272, 4789, 275, 4789, 14, 8755, 8, 8755, 63, 835, 9, 221, 327, 21973, 1956, 4789, 642, 327, 5431, 272, 4789, 275, 4789, 14, 2912, 8, 708, 9, 221, 327, 17206, 1568, 370, 675, 272, 6122, 275, 4789, 14, 1875, 63, 368, 63, 2782, 63, 5778, 342, 272, 3522, 63, 3179, 12, 3522, 63, 3512, 275, 6122, 14, 362, 63, 2184, 342, 272, 372, 3522, 63, 3179, 12, 3522, 63, 3512, 199, 199, 2184, 63, 2912, 275, 3002, 63, 1210, 63, 2324, 8, 3817, 63, 18473, 12, 715, 9, 221, 327, 12823, 372, 4337, 2196, 4008, 199, 199, 3, 2790, 314, 3878, 63, 3406, 12, 1314, 9314, 314, 1324, 370, 4154, 1402, 199, 3, 2900, 4154, 1324, 4534, 787, 8950, 12, 880, 675, 8950, 63, 2301, 367, 1924, 1373, 199, 4445, 63, 3406, 275, 359, 3249, 14, 4445, 63, 2301, 14, 6677, 63, 2301, 8, 75, 9, 367, 1022, 315, 3878, 63, 1247, 61, 199, 199, 3, 2790, 282, 13217, 1279, 4889, 2784, 10864, 12429, 199, 3, 3645, 314, 577, 7178, 8508, 876, 13, 29519, 8943, 199, 14720, 275, 2833, 14, 8627, 14, 36, 7178, 8508, 8, 272, 3878, 63, 3406, 29, 4445, 63, 3406, 12, 221, 327, 710, 1324, 4534, 370, 4154, 1402 ]
[ 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, 199, 3, 961, 365, 314, 4890, 1233, 367, 314, 2569, 19936, 1932, 26, 199, 3, 4178, 921, 23826, 14, 3098, 11486, 14, 957, 15, 10680, 15, 1643, 15, 18206, 14713, 13, 16008, 13, 12281, 14, 1360, 199, 3, 257, 334, 2859, 921, 29546, 14, 3528, 15, 53, 74, 77, 18, 14057, 9, 199, 199, 646, 747, 199, 199, 646, 3816, 14, 4912, 14, 4078, 14, 1069, 465, 1056, 199, 646, 3228, 465, 2833, 199, 199, 3, 2670, 626, 781, 1172, 3211, 9134, 1015, 4903, 199, 3249, 63, 1023, 275, 2833, 855, 1023, 363, 199, 1361, 480, 26998, 1015, 26, 8352, 908, 8, 3249, 63, 1023, 430, 199, 479, 298, 17, 14, 20, 2, 2695, 2833, 63, 1023, 12, 298, 26998, 519, 17, 14, 20, 503, 2945, 365, 4346, 2, 199, 199, 3, 5417, 4390, 26, 2047, 1454, 1929, 370, 1570, 15097, 12, 4618, 365, 4298, 12717, 199, 3243, 275, 3286, 2791, 15, 3249, 63, 5214, 63, 460, 63, 8627, 63, 12662, 2, 199, 199, 3, 16347, 436, 3877, 22859, 436, 1379, 4789, 1584, 199, 3243, 63, 28231, 775, 275, 15097, 435, 747, 14, 4127, 435, 298, 5214, 2, 199, 3817, 63, 18473, 275, 15097, 63, 28231, 775, 435, 747, 14, 4127, 435, 298, 11885, 63, 7588, 14, 4737, 2, 199, 3817, 63, 2864, 275, 15097, 63, 28231, 775, 435, 747, 14, 4127, 435, 298, 11885, 63, 396, 14, 4737, 2, 199, 2632, 63, 18473, 275, 298, 1014, 921, 4249, 14, 16008, 14, 1308, 15, 576, 15, 11885, 63, 7588, 14, 4737, 2, 199, 2632, 63, 2864, 275, 298, 1014, 921, 4249, 14, 16008, 14, 1308, 15, 576, 15, 11885, 63, 396, 14, 4737, 2, 421, 199, 318, 5235, 63, 5214, 8, 633, 12, 570, 304, 272, 340, 440, 747, 14, 515, 14, 2444, 8, 3243, 63, 28231, 775, 304, 267, 747, 14, 8347, 8, 3243, 63, 28231, 775, 9, 272, 340, 440, 747, 14, 515, 14, 2444, 8, 493, 304, 267, 666, 275, 1056, 14, 10890, 8, 633, 680, 739, 342, 267, 543, 1551, 8, 493, 12, 298, 6603, 531, 465, 289, 26, 288, 289, 14, 952, 8, 576, 9, 288, 289, 14, 1600, 342, 199, 4249, 63, 5214, 8, 2632, 63, 18473, 12, 13024, 63, 18473, 9, 199, 4249, 63, 5214, 8, 2632, 63, 2864, 12, 13024, 63, 2864, 9, 199, 199, 3249, 14, 4806, 14, 409, 63, 9833, 8, 3249, 14, 4806, 14, 4531, 9, 199, 199, 3, 710, 14689, 4534, 315, 4154, 6093, 1253, 511, 666, 199, 4445, 63, 1247, 275, 359, 272, 283, 1513, 21516, 4625, 297, 272, 283, 1513, 21516, 6216, 297, 272, 283, 48, 386, 279, 4625, 297, 272, 283, 48, 386, 279, 6216, 418, 199, 199, 3, 2790, 376, 1324, 805, 7664, 282, 570, 1808, 314, 20284, 3261, 199, 3, 9442, 5647, 314, 2058, 370, 314, 28992, 3261, 421, 199, 318, 3002, 63, 1210, 63, 2324, 8, 493, 63, 515, 12, 5147, 63, 11777, 29, 797, 12, 11982, 63, 835, 29, 17, 304, 272, 347, 4849, 63, 4737, 8, 604, 304, 267, 4565, 63, 604, 275, 2833, 14, 2708, 63, 4737, 8, 604, 12, 3474, 16, 8333, 359, 16, 8333, 359, 16, 8333, 359, 16, 8333, 359, 16, 3934, 267, 1768, 275, 4565, 63, 604, 1988, 17, 61, 221, 327, 15237, 1819, 365, 314, 1768, 267, 2150, 4565, 63, 604, 1988, 17, 61, 221, 327, 8496, 2061, 1819, 267, 4534, 275, 4565, 63, 604, 221, 327, 18414, 2127, 1325, 2061, 4008, 787, 314, 4534, 267, 366, 275, 1211, 8, 3065, 8, 4445, 63, 1247, 12, 4534, 1826, 1768, 267, 372, 366, 339, 4789, 275, 334, 3249, 14, 576, 14, 1872, 3049, 9271, 8, 493, 63, 515, 9, 221, 327, 5574, 1318, 570, 2049, 1275, 2759, 8, 17, 9, 221, 327, 8232, 1406, 1962, 2049, 1275, 1130, 8, 2708, 63, 4737, 430, 221, 327, 19463, 1924, 6193, 701, 18876, 4849, 63, 4737, 4325, 272, 340, 5147, 63, 11777, 26, 267, 327, 9571, 6491, 1324, 1808, 282, 4353, 402, 7633, 4008, 334, 739, 1901, 4402, 9, 267, 4789, 275, 4789, 14, 11777, 8, 2738, 63, 890, 29, 3912, 9, 272, 4789, 275, 4789, 14, 8755, 8, 8755, 63, 835, 9, 221, 327, 21973, 1956, 4789, 642, 327, 5431, 272, 4789, 275, 4789, 14, 2912, 8, 708, 9, 221, 327, 17206, 1568, 370, 675, 272, 6122, 275, 4789, 14, 1875, 63, 368, 63, 2782, 63, 5778, 342, 272, 3522, 63, 3179, 12, 3522, 63, 3512, 275, 6122, 14, 362, 63, 2184, 342, 272, 372, 3522, 63, 3179, 12, 3522, 63, 3512, 199, 199, 2184, 63, 2912, 275, 3002, 63, 1210, 63, 2324, 8, 3817, 63, 18473, 12, 715, 9, 221, 327, 12823, 372, 4337, 2196, 4008, 199, 199, 3, 2790, 314, 3878, 63, 3406, 12, 1314, 9314, 314, 1324, 370, 4154, 1402, 199, 3, 2900, 4154, 1324, 4534, 787, 8950, 12, 880, 675, 8950, 63, 2301, 367, 1924, 1373, 199, 4445, 63, 3406, 275, 359, 3249, 14, 4445, 63, 2301, 14, 6677, 63, 2301, 8, 75, 9, 367, 1022, 315, 3878, 63, 1247, 61, 199, 199, 3, 2790, 282, 13217, 1279, 4889, 2784, 10864, 12429, 199, 3, 3645, 314, 577, 7178, 8508, 876, 13, 29519, 8943, 199, 14720, 275, 2833, 14, 8627, 14, 36, 7178, 8508, 8, 272, 3878, 63, 3406, 29, 4445, 63, 3406, 12, 221, 327, 710, 1324, 4534, 370, 4154, 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,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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 ]
Microsoft/PTVS
Python/Product/Miniconda/Miniconda3-x64/Lib/site-packages/pythonwin/pywin/mfc/docview.py
7
3568
# document and view classes for MFC. import win32ui import win32con from . import object from . import window class View(window.Wnd): def __init__(self, initobj): window.Wnd.__init__(self, initobj) def OnInitialUpdate(self): pass # Simple control based views. class CtrlView(View): def __init__(self, doc, wndclass, style=0): View.__init__(self, win32ui.CreateCtrlView(doc, wndclass, style)) class EditView(CtrlView): def __init__(self, doc): View.__init__(self, win32ui.CreateEditView(doc)) class RichEditView(CtrlView): def __init__(self, doc): View.__init__(self, win32ui.CreateRichEditView(doc)) class ListView(CtrlView): def __init__(self, doc): View.__init__(self, win32ui.CreateListView(doc)) class TreeView(CtrlView): def __init__(self, doc): View.__init__(self, win32ui.CreateTreeView(doc)) # Other more advanced views. class ScrollView(View): def __init__(self, doc): View.__init__(self, win32ui.CreateView(doc)) class FormView(View): def __init__(self, doc, id): View.__init__(self, win32ui.CreateFormView(doc, id)) class Document(object.CmdTarget): def __init__(self, template, docobj=None): if docobj is None: docobj = template.DoCreateDoc() object.CmdTarget.__init__(self, docobj) class RichEditDoc(object.CmdTarget): def __init__(self, template): object.CmdTarget.__init__(self, template.DoCreateRichEditDoc()) class CreateContext: "A transient base class used as a CreateContext" def __init__(self, template, doc = None): self.template = template self.doc = doc def __del__(self): self.close() def close(self): self.doc = None self.template = None class DocTemplate(object.CmdTarget): def __init__(self, resourceId=None, MakeDocument=None, MakeFrame=None, MakeView=None): if resourceId is None: resourceId = win32ui.IDR_PYTHONTYPE object.CmdTarget.__init__(self, self._CreateDocTemplate(resourceId)) self.MakeDocument=MakeDocument self.MakeFrame=MakeFrame self.MakeView=MakeView self._SetupSharedMenu_() def _SetupSharedMenu_(self): pass # to be overridden by each "app" def _CreateDocTemplate(self, resourceId): return win32ui.CreateDocTemplate(resourceId) def __del__(self): object.CmdTarget.__del__(self) def CreateCreateContext(self, doc=None): return CreateContext(self, doc) def CreateNewFrame(self, doc): makeFrame = self.MakeFrame if makeFrame is None: makeFrame = window.MDIChildWnd wnd = makeFrame() context = self.CreateCreateContext(doc) wnd.LoadFrame(self.GetResourceID(), -1, None, context) # triggers OnCreateClient... return wnd def CreateNewDocument(self): makeDocument = self.MakeDocument if makeDocument is None: makeDocument = Document return makeDocument(self) def CreateView(self, frame, context): makeView = self.MakeView if makeView is None: makeView = EditView view = makeView(context.doc) view.CreateWindow(frame) class RichEditDocTemplate(DocTemplate): def __init__(self, resourceId=None, MakeDocument=None, MakeFrame=None, MakeView=None): if MakeView is None: MakeView = RichEditView if MakeDocument is None: MakeDocument = RichEditDoc DocTemplate.__init__(self, resourceId, MakeDocument, MakeFrame, MakeView) def _CreateDocTemplate(self, resourceId): return win32ui.CreateRichEditDocTemplate(resourceId) def t(): class FormTemplate(DocTemplate): def CreateView(self, frame, context): makeView = self.MakeView # view = FormView(context.doc, win32ui.IDD_PROPDEMO1) view = ListView(context.doc) view.CreateWindow(frame) t=FormTemplate() return t.OpenDocumentFile(None)
apache-2.0
[ 3, 2213, 436, 2455, 3992, 367, 603, 4161, 14, 199, 646, 4747, 708, 1907, 199, 646, 4747, 708, 388, 199, 504, 1275, 492, 909, 199, 504, 1275, 492, 4353, 199, 199, 533, 10935, 8, 3806, 14, 32261, 304, 199, 198, 318, 636, 826, 721, 277, 12, 4205, 1113, 304, 507, 198, 3806, 14, 32261, 855, 826, 721, 277, 12, 4205, 1113, 9, 199, 198, 318, 4068, 5733, 4152, 8, 277, 304, 507, 198, 1529, 199, 199, 3, 5870, 3304, 4079, 6858, 14, 199, 533, 445, 7245, 2768, 8, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1382, 12, 336, 977, 533, 12, 3449, 29, 16, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 9778, 2768, 8, 1301, 12, 336, 977, 533, 12, 3449, 430, 199, 199, 533, 16407, 2768, 8, 9778, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 4685, 2768, 8, 1301, 430, 199, 199, 533, 30846, 4685, 2768, 8, 9778, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 50, 1158, 4685, 2768, 8, 1301, 430, 199, 199, 533, 3820, 2768, 8, 9778, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 23239, 8, 1301, 430, 199, 199, 533, 12178, 2768, 8, 9778, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 32656, 8, 1301, 430, 199, 199, 3, 5439, 1655, 19472, 6858, 14, 199, 533, 13916, 2827, 2768, 8, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 2768, 8, 1301, 430, 199, 199, 533, 8204, 2768, 8, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 12, 1305, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 2821, 2768, 8, 1301, 12, 1305, 430, 199, 199, 533, 7543, 8, 785, 14, 7874, 4277, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1978, 12, 886, 331, 468, 29, 403, 304, 507, 198, 692, 886, 331, 468, 365, 488, 26, 686, 198, 1117, 331, 468, 275, 1978, 14, 2585, 2499, 3768, 342, 507, 198, 785, 14, 7874, 4277, 855, 826, 721, 277, 12, 886, 331, 468, 9, 199, 199, 533, 30846, 4685, 3768, 8, 785, 14, 7874, 4277, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1978, 304, 507, 198, 785, 14, 7874, 4277, 855, 826, 721, 277, 12, 1978, 14, 2585, 2499, 50, 1158, 4685, 3768, 1012, 199, 199, 533, 2790, 2998, 26, 199, 198, 2, 33, 7115, 14928, 1300, 1021, 1202, 465, 282, 2790, 2998, 2, 199, 198, 318, 636, 826, 721, 277, 12, 1978, 12, 1382, 275, 488, 304, 507, 198, 277, 14, 1160, 275, 1978, 507, 198, 277, 14, 1301, 275, 1382, 199, 198, 318, 636, 2264, 721, 277, 304, 507, 198, 277, 14, 1600, 342, 199, 198, 318, 4002, 8, 277, 304, 507, 198, 277, 14, 1301, 275, 488, 507, 198, 277, 14, 1160, 275, 488, 199, 199, 533, 5454, 4231, 8, 785, 14, 7874, 4277, 304, 199, 198, 318, 636, 826, 721, 277, 12, 2073, 1304, 29, 403, 12, 4155, 5564, 29, 403, 12, 4155, 3160, 29, 403, 12, 4155, 2768, 29, 403, 304, 507, 198, 692, 2073, 1304, 365, 488, 26, 2073, 1304, 275, 4747, 708, 1907, 14, 22052, 63, 11720, 2711, 507, 198, 785, 14, 7874, 4277, 855, 826, 721, 277, 12, 291, 423, 2499, 3768, 4231, 8, 1927, 1304, 430, 507, 198, 277, 14, 5483, 5564, 29, 5483, 5564, 507, 198, 277, 14, 5483, 3160, 29, 5483, 3160, 507, 198, 277, 14, 5483, 2768, 29, 5483, 2768, 507, 198, 277, 423, 8555, 12197, 5977, 12798, 199, 198, 318, 485, 8555, 12197, 5977, 2531, 277, 304, 507, 198, 1529, 327, 370, 506, 10087, 701, 1924, 298, 571, 2, 199, 198, 318, 485, 2499, 3768, 4231, 8, 277, 12, 2073, 1304, 304, 507, 198, 1107, 4747, 708, 1907, 14, 2499, 3768, 4231, 8, 1927, 1304, 9, 199, 198, 318, 636, 2264, 721, 277, 304, 507, 198, 785, 14, 7874, 4277, 855, 2264, 721, 277, 9, 199, 198, 318, 2790, 2499, 2998, 8, 277, 12, 1382, 29, 403, 304, 507, 198, 1107, 2790, 2998, 8, 277, 12, 1382, 9, 199, 198, 318, 2790, 4665, 3160, 8, 277, 12, 1382, 304, 507, 198, 1875, 3160, 275, 291, 14, 5483, 3160, 507, 198, 692, 1852, 3160, 365, 488, 26, 1852, 3160, 275, 4353, 14, 5127, 948, 72, 668, 32261, 507, 198, 87, 977, 275, 1852, 3160, 342, 507, 198, 1100, 275, 291, 14, 2499, 2499, 2998, 8, 1301, 9, 507, 198, 87, 977, 14, 6200, 3160, 8, 277, 14, 1002, 4031, 998, 1062, 446, 17, 12, 488, 12, 1067, 9, 198, 3, 18899, 4068, 2499, 3041, 1396, 507, 198, 1107, 336, 977, 199, 198, 318, 2790, 4665, 5564, 8, 277, 304, 507, 198, 1875, 5564, 275, 291, 14, 5483, 5564, 507, 198, 692, 1852, 5564, 365, 488, 26, 686, 198, 1875, 5564, 275, 7543, 507, 198, 1107, 1852, 5564, 8, 277, 9, 199, 198, 318, 2790, 2768, 8, 277, 12, 2787, 12, 1067, 304, 507, 198, 1875, 2768, 275, 291, 14, 5483, 2768, 507, 198, 692, 1852, 2768, 365, 488, 26, 1852, 2768, 275, 16407, 2768, 507, 198, 1345, 275, 1852, 2768, 8, 1100, 14, 1301, 9, 507, 198, 1345, 14, 2499, 4301, 8, 1943, 9, 199, 199, 533, 30846, 4685, 3768, 4231, 8, 3768, 4231, 304, 199, 198, 318, 636, 826, 721, 277, 12, 2073, 1304, 29, 403, 12, 4155, 5564, 29, 403, 12, 4155, 3160, 29, 403, 12, 4155, 2768, 29, 403, 304, 507, 198, 692, 4155, 2768, 365, 488, 26, 4155, 2768, 275, 30846, 4685, 2768, 507, 198, 692, 4155, 5564, 365, 488, 26, 4155, 5564, 275, 30846, 4685, 3768, 507, 198, 3768, 4231, 855, 826, 721, 277, 12, 2073, 1304 ]
[ 2213, 436, 2455, 3992, 367, 603, 4161, 14, 199, 646, 4747, 708, 1907, 199, 646, 4747, 708, 388, 199, 504, 1275, 492, 909, 199, 504, 1275, 492, 4353, 199, 199, 533, 10935, 8, 3806, 14, 32261, 304, 199, 198, 318, 636, 826, 721, 277, 12, 4205, 1113, 304, 507, 198, 3806, 14, 32261, 855, 826, 721, 277, 12, 4205, 1113, 9, 199, 198, 318, 4068, 5733, 4152, 8, 277, 304, 507, 198, 1529, 199, 199, 3, 5870, 3304, 4079, 6858, 14, 199, 533, 445, 7245, 2768, 8, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1382, 12, 336, 977, 533, 12, 3449, 29, 16, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 9778, 2768, 8, 1301, 12, 336, 977, 533, 12, 3449, 430, 199, 199, 533, 16407, 2768, 8, 9778, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 4685, 2768, 8, 1301, 430, 199, 199, 533, 30846, 4685, 2768, 8, 9778, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 50, 1158, 4685, 2768, 8, 1301, 430, 199, 199, 533, 3820, 2768, 8, 9778, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 23239, 8, 1301, 430, 199, 199, 533, 12178, 2768, 8, 9778, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 32656, 8, 1301, 430, 199, 199, 3, 5439, 1655, 19472, 6858, 14, 199, 533, 13916, 2827, 2768, 8, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 2768, 8, 1301, 430, 199, 199, 533, 8204, 2768, 8, 2768, 304, 199, 198, 318, 636, 826, 721, 277, 12, 221, 1382, 12, 1305, 304, 507, 198, 2768, 855, 826, 721, 277, 12, 4747, 708, 1907, 14, 2499, 2821, 2768, 8, 1301, 12, 1305, 430, 199, 199, 533, 7543, 8, 785, 14, 7874, 4277, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1978, 12, 886, 331, 468, 29, 403, 304, 507, 198, 692, 886, 331, 468, 365, 488, 26, 686, 198, 1117, 331, 468, 275, 1978, 14, 2585, 2499, 3768, 342, 507, 198, 785, 14, 7874, 4277, 855, 826, 721, 277, 12, 886, 331, 468, 9, 199, 199, 533, 30846, 4685, 3768, 8, 785, 14, 7874, 4277, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1978, 304, 507, 198, 785, 14, 7874, 4277, 855, 826, 721, 277, 12, 1978, 14, 2585, 2499, 50, 1158, 4685, 3768, 1012, 199, 199, 533, 2790, 2998, 26, 199, 198, 2, 33, 7115, 14928, 1300, 1021, 1202, 465, 282, 2790, 2998, 2, 199, 198, 318, 636, 826, 721, 277, 12, 1978, 12, 1382, 275, 488, 304, 507, 198, 277, 14, 1160, 275, 1978, 507, 198, 277, 14, 1301, 275, 1382, 199, 198, 318, 636, 2264, 721, 277, 304, 507, 198, 277, 14, 1600, 342, 199, 198, 318, 4002, 8, 277, 304, 507, 198, 277, 14, 1301, 275, 488, 507, 198, 277, 14, 1160, 275, 488, 199, 199, 533, 5454, 4231, 8, 785, 14, 7874, 4277, 304, 199, 198, 318, 636, 826, 721, 277, 12, 2073, 1304, 29, 403, 12, 4155, 5564, 29, 403, 12, 4155, 3160, 29, 403, 12, 4155, 2768, 29, 403, 304, 507, 198, 692, 2073, 1304, 365, 488, 26, 2073, 1304, 275, 4747, 708, 1907, 14, 22052, 63, 11720, 2711, 507, 198, 785, 14, 7874, 4277, 855, 826, 721, 277, 12, 291, 423, 2499, 3768, 4231, 8, 1927, 1304, 430, 507, 198, 277, 14, 5483, 5564, 29, 5483, 5564, 507, 198, 277, 14, 5483, 3160, 29, 5483, 3160, 507, 198, 277, 14, 5483, 2768, 29, 5483, 2768, 507, 198, 277, 423, 8555, 12197, 5977, 12798, 199, 198, 318, 485, 8555, 12197, 5977, 2531, 277, 304, 507, 198, 1529, 327, 370, 506, 10087, 701, 1924, 298, 571, 2, 199, 198, 318, 485, 2499, 3768, 4231, 8, 277, 12, 2073, 1304, 304, 507, 198, 1107, 4747, 708, 1907, 14, 2499, 3768, 4231, 8, 1927, 1304, 9, 199, 198, 318, 636, 2264, 721, 277, 304, 507, 198, 785, 14, 7874, 4277, 855, 2264, 721, 277, 9, 199, 198, 318, 2790, 2499, 2998, 8, 277, 12, 1382, 29, 403, 304, 507, 198, 1107, 2790, 2998, 8, 277, 12, 1382, 9, 199, 198, 318, 2790, 4665, 3160, 8, 277, 12, 1382, 304, 507, 198, 1875, 3160, 275, 291, 14, 5483, 3160, 507, 198, 692, 1852, 3160, 365, 488, 26, 1852, 3160, 275, 4353, 14, 5127, 948, 72, 668, 32261, 507, 198, 87, 977, 275, 1852, 3160, 342, 507, 198, 1100, 275, 291, 14, 2499, 2499, 2998, 8, 1301, 9, 507, 198, 87, 977, 14, 6200, 3160, 8, 277, 14, 1002, 4031, 998, 1062, 446, 17, 12, 488, 12, 1067, 9, 198, 3, 18899, 4068, 2499, 3041, 1396, 507, 198, 1107, 336, 977, 199, 198, 318, 2790, 4665, 5564, 8, 277, 304, 507, 198, 1875, 5564, 275, 291, 14, 5483, 5564, 507, 198, 692, 1852, 5564, 365, 488, 26, 686, 198, 1875, 5564, 275, 7543, 507, 198, 1107, 1852, 5564, 8, 277, 9, 199, 198, 318, 2790, 2768, 8, 277, 12, 2787, 12, 1067, 304, 507, 198, 1875, 2768, 275, 291, 14, 5483, 2768, 507, 198, 692, 1852, 2768, 365, 488, 26, 1852, 2768, 275, 16407, 2768, 507, 198, 1345, 275, 1852, 2768, 8, 1100, 14, 1301, 9, 507, 198, 1345, 14, 2499, 4301, 8, 1943, 9, 199, 199, 533, 30846, 4685, 3768, 4231, 8, 3768, 4231, 304, 199, 198, 318, 636, 826, 721, 277, 12, 2073, 1304, 29, 403, 12, 4155, 5564, 29, 403, 12, 4155, 3160, 29, 403, 12, 4155, 2768, 29, 403, 304, 507, 198, 692, 4155, 2768, 365, 488, 26, 4155, 2768, 275, 30846, 4685, 2768, 507, 198, 692, 4155, 5564, 365, 488, 26, 4155, 5564, 275, 30846, 4685, 3768, 507, 198, 3768, 4231, 855, 826, 721, 277, 12, 2073, 1304, 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,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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 ]
pando85/django-registration
registration/models.py
3
23708
from __future__ import unicode_literals import datetime import hashlib import re import string from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ObjectDoesNotExist from django.core.mail import EmailMultiAlternatives from django.db import models, transaction from django.template import TemplateDoesNotExist from django.template.loader import render_to_string from django.utils.crypto import get_random_string from django.utils.encoding import python_2_unicode_compatible from django.utils.timezone import now as datetime_now from django.utils.translation import ugettext_lazy as _ from .users import UserModel, UserModelString SHA1_RE = re.compile('^[a-f0-9]{40}$') def send_email(addresses_to, ctx_dict, subject_template, body_template, body_html_template): """ Function that sends an email """ subject = ( getattr(settings, 'REGISTRATION_EMAIL_SUBJECT_PREFIX', '') + render_to_string( subject_template, ctx_dict) ) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) from_email = getattr(settings, 'REGISTRATION_DEFAULT_FROM_EMAIL', settings.DEFAULT_FROM_EMAIL) message_txt = render_to_string(body_template, ctx_dict) email_message = EmailMultiAlternatives(subject, message_txt, from_email, addresses_to) if getattr(settings, 'REGISTRATION_EMAIL_HTML', True): try: message_html = render_to_string( body_html_template, ctx_dict) except TemplateDoesNotExist: pass else: email_message.attach_alternative(message_html, 'text/html') email_message.send() class RegistrationManager(models.Manager): """ Custom manager for the ``RegistrationProfile`` model. The methods defined here provide shortcuts for account creation and activation (including generation and emailing of activation keys), and for cleaning out expired inactive accounts. """ def _activate(self, profile, site, get_profile): """ Activate the ``RegistrationProfile`` given as argument. User is able to login, as ``is_active`` is set to ``True`` """ user = profile.user user.is_active = True profile.activated = True with transaction.atomic(): user.save() profile.save() if get_profile: return profile else: return user def activate_user(self, activation_key, site, get_profile=False): """ Validate an activation key and activate the corresponding ``User`` if valid. If the key is valid and has not expired, return the ``User`` after activating. If the key is not valid or has expired, return ``False``. If the key is valid but the ``User`` is already active, return ``User``. If the key is valid but the ``User`` is inactive, return ``False``. To prevent reactivation of an account which has been deactivated by site administrators, ``RegistrationProfile.activated`` is set to ``True`` after successful activation. """ # Make sure the key we're trying conforms to the pattern of a # SHA1 hash; if it doesn't, no point trying to look it up in # the database. if SHA1_RE.search(activation_key): try: profile = self.get(activation_key=activation_key) except self.model.DoesNotExist: # This is an actual activation failure as the activation # key does not exist. It is *not* the scenario where an # already activated User reuses an activation key. return False if profile.activated: # The User has already activated and is trying to activate # again. If the User is active, return the User. Else, # return False as the User has been deactivated by a site # administrator. if profile.user.is_active: return profile.user else: return False if not profile.activation_key_expired(): return self._activate(profile, site, get_profile) return False def create_inactive_user(self, site, new_user=None, send_email=True, request=None, profile_info={}, **user_info): """ Create a new, inactive ``User``, generate a ``RegistrationProfile`` and email its activation key to the ``User``, returning the new ``User``. By default, an activation email will be sent to the new user. To disable this, pass ``send_email=False``. Additionally, if email is sent and ``request`` is supplied, it will be passed to the email template. """ if new_user is None: password = user_info.pop('password') new_user = UserModel()(**user_info) new_user.set_password(password) new_user.is_active = False # Since we calculate the RegistrationProfile expiration from this date, # we want to ensure that it is current new_user.date_joined = datetime_now() with transaction.atomic(): new_user.save() registration_profile = self.create_profile( new_user, **profile_info) if send_email: registration_profile.send_activation_email(site, request) return new_user def create_profile(self, user, **profile_info): """ Create a ``RegistrationProfile`` for a given ``User``, and return the ``RegistrationProfile``. The activation key for the ``RegistrationProfile`` will be a SHA1 hash, generated from a secure random string. """ profile = self.model(user=user, **profile_info) if 'activation_key' not in profile_info: profile.create_new_activation_key(save=False) profile.save() return profile def resend_activation_mail(self, email, site, request=None): """ Resets activation key for the user and resends activation email. """ try: profile = self.get(user__email__iexact=email) except ObjectDoesNotExist: return False # TODO: Catch multiple objects returned exception? if profile.activated or profile.activation_key_expired(): return False profile.create_new_activation_key() profile.send_activation_email(site, request) return True def delete_expired_users(self): """ Remove expired instances of ``RegistrationProfile`` and their associated ``User``s. Accounts to be deleted are identified by searching for instances of ``RegistrationProfile`` with expired activation keys, and then checking to see if their associated ``User`` instances have the field ``is_active`` set to ``False``; any ``User`` who is both inactive and has an expired activation key will be deleted. It is recommended that this method be executed regularly as part of your routine site maintenance; this application provides a custom management command which will call this method, accessible as ``manage.py cleanupregistration``. Regularly clearing out accounts which have never been activated serves two useful purposes: 1. It alleviates the ocasional need to reset a ``RegistrationProfile`` and/or re-send an activation email when a user does not receive or does not act upon the initial activation email; since the account will be deleted, the user will be able to simply re-register and receive a new activation key. 2. It prevents the possibility of a malicious user registering one or more accounts and never activating them (thus denying the use of those usernames to anyone else); since those accounts will be deleted, the usernames will become available for use again. If you have a troublesome ``User`` and wish to disable their account while keeping it in the database, simply delete the associated ``RegistrationProfile``; an inactive ``User`` which does not have an associated ``RegistrationProfile`` will not be deleted. """ for profile in self.all(): try: if profile.activation_key_expired(): user = profile.user if not user.is_active: profile.delete() user.delete() except UserModel().DoesNotExist: profile.delete() @python_2_unicode_compatible class RegistrationProfile(models.Model): """ A simple profile which stores an activation key for use during user account registration. Generally, you will not want to interact directly with instances of this model; the provided manager includes methods for creating and activating new accounts, as well as for cleaning out accounts which have never been activated. While it is possible to use this model as the value of the ``AUTH_PROFILE_MODULE`` setting, it's not recommended that you do so. This model's sole purpose is to store data temporarily during account registration and activation. """ user = models.OneToOneField( UserModelString(), on_delete=models.CASCADE, verbose_name=_('user'), ) activation_key = models.CharField(_('activation key'), max_length=40) activated = models.BooleanField(default=False) objects = RegistrationManager() class Meta: verbose_name = _('registration profile') verbose_name_plural = _('registration profiles') def __str__(self): return "Registration information for %s" % self.user def create_new_activation_key(self, save=True): """ Create a new activation key for the user """ random_string = get_random_string(length=32, allowed_chars=string.printable) self.activation_key = hashlib.sha1(random_string.encode('utf-8')).hexdigest() if save: self.save() return self.activation_key def activation_key_expired(self): """ Determine whether this ``RegistrationProfile``'s activation key has expired, returning a boolean -- ``True`` if the key has expired. Key expiration is determined by a two-step process: 1. If the user has already activated, ``self.activated`` will be ``True``. Re-activating is not permitted, and so this method returns ``True`` in this case. 2. Otherwise, the date the user signed up is incremented by the number of days specified in the setting ``ACCOUNT_ACTIVATION_DAYS`` (which should be the number of days after signup during which a user is allowed to activate their account); if the result is less than or equal to the current date, the key has expired and this method returns ``True``. """ expiration_date = datetime.timedelta( days=settings.ACCOUNT_ACTIVATION_DAYS) return (self.activated or (self.user.date_joined + expiration_date <= datetime_now())) activation_key_expired.boolean = True def send_activation_email(self, site, request=None): """ Send an activation email to the user associated with this ``RegistrationProfile``. The activation email will use the following templates, which can be overriden by setting ACTIVATION_EMAIL_SUBJECT, ACTIVATION_EMAIL_BODY, and ACTIVATION_EMAIL_HTML appropriately: ``registration/activation_email_subject.txt`` This template will be used for the subject line of the email. Because it is used as the subject line of an email, this template's output **must** be only a single line of text; output longer than one line will be forcibly joined into only a single line. ``registration/activation_email.txt`` This template will be used for the text body of the email. ``registration/activation_email.html`` This template will be used for the html body of the email. These templates will each receive the following context variables: ``user`` The new user account ``activation_key`` The activation key for the new account. ``expiration_days`` The number of days remaining during which the account may be activated. ``site`` An object representing the site on which the user registered; depending on whether ``django.contrib.sites`` is installed, this may be an instance of either ``django.contrib.sites.models.Site`` (if the sites application is installed) or ``django.contrib.sites.requests.RequestSite`` (if not). Consult the documentation for the Django sites framework for details regarding these objects' interfaces. ``request`` Optional Django's ``HttpRequest`` object from view. If supplied will be passed to the template for better flexibility via ``RequestContext``. """ activation_email_subject = getattr(settings, 'ACTIVATION_EMAIL_SUBJECT', 'registration/activation_email_subject.txt') activation_email_body = getattr(settings, 'ACTIVATION_EMAIL_BODY', 'registration/activation_email.txt') activation_email_html = getattr(settings, 'ACTIVATION_EMAIL_HTML', 'registration/activation_email.html') ctx_dict = { 'user': self.user, 'activation_key': self.activation_key, 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS, 'site': site, } subject = (getattr(settings, 'REGISTRATION_EMAIL_SUBJECT_PREFIX', '') + render_to_string( activation_email_subject, ctx_dict, request=request)) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) from_email = getattr(settings, 'REGISTRATION_DEFAULT_FROM_EMAIL', settings.DEFAULT_FROM_EMAIL) message_txt = render_to_string(activation_email_body, ctx_dict, request=request) email_message = EmailMultiAlternatives(subject, message_txt, from_email, [self.user.email]) if getattr(settings, 'REGISTRATION_EMAIL_HTML', True): try: message_html = render_to_string( activation_email_html, ctx_dict, request=request) except TemplateDoesNotExist: pass else: email_message.attach_alternative(message_html, 'text/html') email_message.send() class SupervisedRegistrationManager(RegistrationManager): def _activate(self, profile, site, get_profile): """ Activate the ``SupervisedRegistrationProfile`` given as argument. Send an email to the site administrators to approve the user. User is not able to login yet, as ``is_active`` is not yet ``True`` """ if not profile.user.is_active and not profile.activated: self.send_admin_approve_email(profile.user, site) # do not set ``User.is_active`` as True. This will be set # when a site administrator approves this account. profile.activated = True profile.save() if get_profile: return profile else: return profile.user def admin_approve_user(self, profile_id, site, get_profile=False, request=None): """ Approve the ``SupervisedRegistrationProfile`` object with the given ``profile_id``. If the id is valid, return the ``User`` after approving. If the id is not valid, return ``False``. If the id is valid but the ``User`` is already active, return ``User``. If the id is valid but the ``SupervisedRegistrationProfile`` object is not activated, return ``False``. """ try: profile = SupervisedRegistrationProfile.objects.get(id=profile_id) if profile.activated: if profile.user.is_active: return profile.user # If the user has not activated their profile the admin should # not be able to approve his account (at least not following # this process) if profile.activated: profile.user.is_active = True else: return False profile.user.save() profile.send_admin_approve_complete_email(site, request) if get_profile: return profile else: return profile.user except self.model.DoesNotExist: return False def send_admin_approve_email(self, user, site, request=None): """ Send an approval email to the site administrators to approve this user. The approval email will use the following templates, which can be overriden by setting APPROVAL_EMAIL_SUBJECT, APPROVAL_EMAIL_BODY, and APPROVAL_EMAIL_HTML appropriately: ``registration/admin_approve_email_subject.txt`` This template will be used for the subject line of the email. Because it is used as the subject line of an email, this template's output **must** be only a single line of text; output longer than one line will be forcibly joined into only a single line. ``registration/admin_approve_email.txt`` This template will be used for the text body of the email. ``registration/admin_approve_email.html`` This template will be used for the html body of the email. These templates will each receive the following context variables: ``user`` The new user account ``profile_id`` The id of the associated``SupervisedRegistrationProfile`` object. ``site`` An object representing the site on which the user registered; depending on whether ``django.contrib.sites`` is installed, this may be an instance of either ``django.contrib.sites.models.Site`` (if the sites application is installed) or ``django.contrib.sites.requests.RequestSite`` (if not). Consult the documentation for the Django sites framework for details regarding these objects' interfaces. ``request`` Optional Django's ``HttpRequest`` object from view. If supplied will be passed to the template for better flexibility via ``RequestContext``. """ admin_approve_email_subject = getattr( settings, 'ADMIN_APPROVAL_EMAIL_SUBJECT', 'registration/admin_approve_email_subject.txt' ) admin_approve_email_body = getattr( settings, 'ADMIN_APPROVAL_EMAIL_BODY', 'registration/admin_approve_email.txt' ) admin_approve_email_html = getattr( settings, 'ADMIN_APPROVAL_EMAIL_HTML', 'registration/admin_approve_email.html' ) ctx_dict = { 'user': user, 'profile_id': user.registrationprofile.id, 'site': site, } admins = getattr(settings, 'ADMINS', None) if not admins: raise ImproperlyConfigured( 'Using the admin_approval registration backend' ' requires at least one admin in settings.ADMINS') admins = [admin[1] for admin in admins] send_email( admins, ctx_dict, admin_approve_email_subject, admin_approve_email_body, admin_approve_email_html ) class SupervisedRegistrationProfile(RegistrationProfile): # Same model as ``RegistrationProfile``, just a different # Manager to implement the extra functionality required # in admin approval objects = SupervisedRegistrationManager() def send_admin_approve_complete_email(self, site, request=None): """ Send an "approval is complete" email to the user associated with this ``SupervisedRegistrationProfile``. The email will use the following templates, which can be overriden by settings APPROVAL_COMPLETE_EMAIL_SUBJECT, APPROVAL_COMPLETE_EMAIL_BODY, and APPROVAL_COMPLETE_EMAIL_HTML appropriately: ``registration/admin_approve_complete_email_subject.txt`` This template will be used for the subject line of the email. Because it is used as the subject line of an email, this template's output **must** be only a single line of text; output longer than one line will be forcibly joined into only a single line. ``registration/admin_approve_complete_email.txt`` This template will be used for the text body of the email. ``registration/admin_approve_complete_email.html`` This template will be used for the text body of the email. These templates will each receive the following context variables: ``user`` The new user account ``site`` An object representing the site on which the user registered; depending on whether ``django.contrib.sites`` is installed, this may be an instance of either ``django.contrib.sites.models.Site`` (if the sites application is installed) or ``django.contrib.sites.requests.RequestSite`` (if not). Consult the documentation for the Django sites framework for details regarding these objects' interfaces. ``request`` Optional Django's ``HttpRequest`` object from view. If supplied will be passed to the template for better flexibility via ``RequestContext``. """ admin_approve_complete_email_subject = getattr( settings, 'APPROVAL_COMPLETE_EMAIL_SUBJECT', 'registration/admin_approve_complete_email_subject.txt') admin_approve_complete_email_body = getattr( settings, 'APPROVAL_COMPLETE_EMAIL_BODY', 'registration/admin_approve_complete_email.txt') admin_approve_complete_email_html = getattr( settings, 'APPROVAL_COMPLETE_EMAIL_HTML', 'registration/admin_approve_complete_email.html') ctx_dict = { 'user': self.user.username, 'site': site, } send_email( [self.user.email], ctx_dict, admin_approve_complete_email_subject, admin_approve_complete_email_body, admin_approve_complete_email_html )
bsd-3-clause
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 2197, 199, 646, 8337, 199, 646, 295, 199, 646, 1059, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1018, 14, 3924, 492, 24803, 199, 504, 1639, 14, 1018, 14, 1198, 492, 11426, 3947, 19978, 10661, 199, 504, 1639, 14, 697, 492, 1709, 12, 6008, 199, 504, 1639, 14, 1160, 492, 27193, 199, 504, 1639, 14, 1160, 14, 3422, 492, 3795, 63, 475, 63, 875, 199, 504, 1639, 14, 1208, 14, 10316, 492, 664, 63, 2355, 63, 875, 199, 504, 1639, 14, 1208, 14, 2991, 492, 2366, 63, 18, 63, 2975, 63, 6490, 199, 504, 1639, 14, 1208, 14, 7145, 492, 3063, 465, 2197, 63, 2131, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 199, 199, 504, 1275, 3707, 492, 2876, 1685, 12, 2876, 1685, 1558, 199, 199, 8461, 17, 63, 907, 275, 295, 14, 2014, 9097, 59, 65, 13, 70, 16, 13, 25, 8194, 2167, 93, 9988, 421, 199, 318, 3222, 63, 2123, 8, 7423, 63, 475, 12, 4027, 63, 807, 12, 5420, 63, 1160, 12, 2396, 63, 1160, 12, 2049, 2396, 63, 1360, 63, 1160, 304, 272, 408, 272, 6801, 626, 16178, 376, 3031, 272, 408, 272, 5420, 275, 334, 267, 2519, 8, 1751, 12, 283, 25304, 2594, 63, 10089, 63, 6348, 5550, 63, 6351, 297, 4074, 435, 267, 3795, 63, 475, 63, 875, 8, 288, 5420, 63, 1160, 12, 4027, 63, 807, 9, 272, 776, 272, 327, 11426, 5420, 627, 7790, 440, 10, 1395, 14930, 272, 5420, 275, 6522, 904, 8, 5875, 14, 7644, 1012, 272, 687, 63, 2123, 275, 2519, 8, 1751, 12, 283, 25304, 2594, 63, 3472, 63, 12491, 63, 10089, 297, 586, 2202, 14, 3472, 63, 12491, 63, 10089, 9, 272, 1245, 63, 2424, 275, 3795, 63, 475, 63, 875, 8, 2030, 63, 1160, 12, 3521, 4027, 63, 807, 9, 339, 3031, 63, 1188, 275, 11426, 3947, 19978, 10661, 8, 5875, 12, 1245, 63, 2424, 12, 5644, 687, 63, 2123, 12, 7149, 63, 475, 9, 339, 340, 2519, 8, 1751, 12, 283, 25304, 2594, 63, 10089, 63, 4943, 297, 715, 304, 267, 862, 26, 288, 1245, 63, 1360, 275, 3795, 63, 475, 63, 875, 8, 355, 2396, 63, 1360, 63, 1160, 12, 4027, 63, 807, 9, 267, 871, 27193, 26, 288, 986, 267, 587, 26, 288, 3031, 63, 1188, 14, 5040, 63, 19389, 8, 1188, 63, 1360, 12, 283, 505, 15, 1360, 358, 339, 3031, 63, 1188, 14, 2254, 342, 421, 199, 533, 20764, 2988, 8, 992, 14, 2988, 304, 272, 408, 272, 8388, 5256, 367, 314, 1124, 11757, 5736, 1040, 1402, 14, 339, 710, 3102, 3247, 2348, 5647, 3974, 12946, 367, 2933, 7143, 272, 436, 10361, 334, 15768, 10152, 436, 3031, 316, 402, 10361, 272, 2883, 395, 436, 367, 29579, 734, 14721, 21325, 12639, 14, 339, 408, 339, 347, 485, 8222, 8, 277, 12, 4690, 12, 4770, 12, 664, 63, 2913, 304, 267, 408, 267, 21904, 2409, 314, 1124, 11757, 5736, 1040, 1627, 465, 1423, 14, 267, 2876, 365, 7688, 370, 4676, 12, 465, 1124, 374, 63, 2682, 1040, 365, 663, 370, 1124, 549, 1040, 267, 408, 267, 922, 275, 4690, 14, 751, 267, 922, 14, 374, 63, 2682, 275, 715, 267, 4690, 14, 18218, 275, 715, 398, 543, 6008, 14, 10910, 837, 288, 922, 14, 2117, 342, 288, 4690, 14, 2117, 342, 267, 340, 664, 63, 2913, 26, 288, 372, 4690, 267, 587, 26, 288, 372, 922, 339, 347, 15422, 63, 751, 8, 277, 12, 10361, 63, 498, 12, 4770, 12, 664, 63, 2913, 29, 797, 304, 267, 408, 267, 12134, 376, 10361, 790, 436, 15422, 314, 5226, 267, 1124, 1899, 1040, 340, 1686, 14, 398, 982, 314, 790, 365, 1686, 436, 965, 440, 14721, 12, 372, 314, 1124, 1899, 1040, 267, 2410, 6633, 86, 1958, 14, 398, 982, 314, 790, 365, 440, 1686, 503, 965, 14721, 12, 372, 1124, 797, 4345, 398, 982, 314, 790, 365, 1686, 1325, 314, 1124, 1899, 1040, 365, 2575, 4702, 12, 267, 372, 1124, 1899, 4345, 398, 982, 314, 790, 365, 1686, 1325, 314, 1124, 1899, 1040, 365, 21325, 12, 372, 1124, 797, 4345, 398, 4005, 7981, 295, 12312, 402, 376, 2933, 1314, 965, 2757, 267, 477, 18218, 701, 4770, 4628, 3075, 2750, 12, 1124, 11757, 5736, 14, 18218, 1040, 267, 365, 663, 370, 1124, 549, 1040, 2410, 9512, 10361, 14, 398, 408, 267, 327, 4155, 3238, 314, 790, 781, 3984, 9936, 406, 3351, 370, 314, 3851, 402, 282, 267, 327, 12002, 17, 2631, 27, 340, 652, 3181, 1133, 12, 949, 2376, 9936, 370, 3648, 652, 1536, 315, 267, 327, 314, 3050, 14, 267, 340, 12002, 17, 63, 907, 14, 1733, 8, 12312, 63, 498, 304, 288, 862, 26, 355, 4690, 275, 291, 14, 362, 8, 12312, 63, 498, 29, 12312, 63, 498, 9, 288, 871, 291, 14, 1238, 14, 7400, 26, 355, 327, 961, 365, 376, 3503, 10361, 5988, 465, 314, 10361, 355, 327, 790, 1630, 440, 2187, 14, 2779, 365, 627, 1397, 10, 314, 15728, 2382, 376, 355, 327, 2575, 22225, 2876, 295, 5589, 376, 10361, 790, 14, 355, 372, 756, 953, 340, 4690, 14, 18218, 26, 355, 327, 710, 2876, 965, 2575, 22225, 436, 365, 9936, 370, 15422, 355, 327, 4020, 14, 982, 314, 2876, 365, 4702, 12, 372, 314, 2876, 14, 19524, 12, 355, 327, 372, 756, 465, 314, 2876, 965, 2757, 477, 18218, 701, 282, 4770, 355, 327, 31056, 14, 355, 340, 4690, 14, 751, 14, 374, 63, 2682, 26, 490, 372, 4690, 14, 751, 355, 587, 26, 490, 372, 756, 953, 340, 440, 4690, 14, 12312, 63, 498, 63, 16340, 837, 355, 372, 291, 423, 8222, 8, 2913, 12, 4770, 12, 664, 63, 2913, 9, 398, 372, 756, 339, 347, 1218, 63, 16856, 63, 751, 8, 277, 12, 4770, 12, 892, 63, 751, 29, 403, 12, 3222, 63, 2123, 29, 549, 12, 2490, 1056, 29, 403, 12, 4690, 63, 815, 10324, 1011, 751, 63, 815, 304, 267, 408, 267, 2790, 282, 892, 12, 21325, 1124, 1899, 4542, 3550, 282, 267, 1124, 11757, 5736, 1040, 436, 3031, 2399, 10361, 790, 370, 314, 267, 1124, 1899, 4542, 8152 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 2197, 199, 646, 8337, 199, 646, 295, 199, 646, 1059, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1018, 14, 3924, 492, 24803, 199, 504, 1639, 14, 1018, 14, 1198, 492, 11426, 3947, 19978, 10661, 199, 504, 1639, 14, 697, 492, 1709, 12, 6008, 199, 504, 1639, 14, 1160, 492, 27193, 199, 504, 1639, 14, 1160, 14, 3422, 492, 3795, 63, 475, 63, 875, 199, 504, 1639, 14, 1208, 14, 10316, 492, 664, 63, 2355, 63, 875, 199, 504, 1639, 14, 1208, 14, 2991, 492, 2366, 63, 18, 63, 2975, 63, 6490, 199, 504, 1639, 14, 1208, 14, 7145, 492, 3063, 465, 2197, 63, 2131, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 199, 199, 504, 1275, 3707, 492, 2876, 1685, 12, 2876, 1685, 1558, 199, 199, 8461, 17, 63, 907, 275, 295, 14, 2014, 9097, 59, 65, 13, 70, 16, 13, 25, 8194, 2167, 93, 9988, 421, 199, 318, 3222, 63, 2123, 8, 7423, 63, 475, 12, 4027, 63, 807, 12, 5420, 63, 1160, 12, 2396, 63, 1160, 12, 2049, 2396, 63, 1360, 63, 1160, 304, 272, 408, 272, 6801, 626, 16178, 376, 3031, 272, 408, 272, 5420, 275, 334, 267, 2519, 8, 1751, 12, 283, 25304, 2594, 63, 10089, 63, 6348, 5550, 63, 6351, 297, 4074, 435, 267, 3795, 63, 475, 63, 875, 8, 288, 5420, 63, 1160, 12, 4027, 63, 807, 9, 272, 776, 272, 327, 11426, 5420, 627, 7790, 440, 10, 1395, 14930, 272, 5420, 275, 6522, 904, 8, 5875, 14, 7644, 1012, 272, 687, 63, 2123, 275, 2519, 8, 1751, 12, 283, 25304, 2594, 63, 3472, 63, 12491, 63, 10089, 297, 586, 2202, 14, 3472, 63, 12491, 63, 10089, 9, 272, 1245, 63, 2424, 275, 3795, 63, 475, 63, 875, 8, 2030, 63, 1160, 12, 3521, 4027, 63, 807, 9, 339, 3031, 63, 1188, 275, 11426, 3947, 19978, 10661, 8, 5875, 12, 1245, 63, 2424, 12, 5644, 687, 63, 2123, 12, 7149, 63, 475, 9, 339, 340, 2519, 8, 1751, 12, 283, 25304, 2594, 63, 10089, 63, 4943, 297, 715, 304, 267, 862, 26, 288, 1245, 63, 1360, 275, 3795, 63, 475, 63, 875, 8, 355, 2396, 63, 1360, 63, 1160, 12, 4027, 63, 807, 9, 267, 871, 27193, 26, 288, 986, 267, 587, 26, 288, 3031, 63, 1188, 14, 5040, 63, 19389, 8, 1188, 63, 1360, 12, 283, 505, 15, 1360, 358, 339, 3031, 63, 1188, 14, 2254, 342, 421, 199, 533, 20764, 2988, 8, 992, 14, 2988, 304, 272, 408, 272, 8388, 5256, 367, 314, 1124, 11757, 5736, 1040, 1402, 14, 339, 710, 3102, 3247, 2348, 5647, 3974, 12946, 367, 2933, 7143, 272, 436, 10361, 334, 15768, 10152, 436, 3031, 316, 402, 10361, 272, 2883, 395, 436, 367, 29579, 734, 14721, 21325, 12639, 14, 339, 408, 339, 347, 485, 8222, 8, 277, 12, 4690, 12, 4770, 12, 664, 63, 2913, 304, 267, 408, 267, 21904, 2409, 314, 1124, 11757, 5736, 1040, 1627, 465, 1423, 14, 267, 2876, 365, 7688, 370, 4676, 12, 465, 1124, 374, 63, 2682, 1040, 365, 663, 370, 1124, 549, 1040, 267, 408, 267, 922, 275, 4690, 14, 751, 267, 922, 14, 374, 63, 2682, 275, 715, 267, 4690, 14, 18218, 275, 715, 398, 543, 6008, 14, 10910, 837, 288, 922, 14, 2117, 342, 288, 4690, 14, 2117, 342, 267, 340, 664, 63, 2913, 26, 288, 372, 4690, 267, 587, 26, 288, 372, 922, 339, 347, 15422, 63, 751, 8, 277, 12, 10361, 63, 498, 12, 4770, 12, 664, 63, 2913, 29, 797, 304, 267, 408, 267, 12134, 376, 10361, 790, 436, 15422, 314, 5226, 267, 1124, 1899, 1040, 340, 1686, 14, 398, 982, 314, 790, 365, 1686, 436, 965, 440, 14721, 12, 372, 314, 1124, 1899, 1040, 267, 2410, 6633, 86, 1958, 14, 398, 982, 314, 790, 365, 440, 1686, 503, 965, 14721, 12, 372, 1124, 797, 4345, 398, 982, 314, 790, 365, 1686, 1325, 314, 1124, 1899, 1040, 365, 2575, 4702, 12, 267, 372, 1124, 1899, 4345, 398, 982, 314, 790, 365, 1686, 1325, 314, 1124, 1899, 1040, 365, 21325, 12, 372, 1124, 797, 4345, 398, 4005, 7981, 295, 12312, 402, 376, 2933, 1314, 965, 2757, 267, 477, 18218, 701, 4770, 4628, 3075, 2750, 12, 1124, 11757, 5736, 14, 18218, 1040, 267, 365, 663, 370, 1124, 549, 1040, 2410, 9512, 10361, 14, 398, 408, 267, 327, 4155, 3238, 314, 790, 781, 3984, 9936, 406, 3351, 370, 314, 3851, 402, 282, 267, 327, 12002, 17, 2631, 27, 340, 652, 3181, 1133, 12, 949, 2376, 9936, 370, 3648, 652, 1536, 315, 267, 327, 314, 3050, 14, 267, 340, 12002, 17, 63, 907, 14, 1733, 8, 12312, 63, 498, 304, 288, 862, 26, 355, 4690, 275, 291, 14, 362, 8, 12312, 63, 498, 29, 12312, 63, 498, 9, 288, 871, 291, 14, 1238, 14, 7400, 26, 355, 327, 961, 365, 376, 3503, 10361, 5988, 465, 314, 10361, 355, 327, 790, 1630, 440, 2187, 14, 2779, 365, 627, 1397, 10, 314, 15728, 2382, 376, 355, 327, 2575, 22225, 2876, 295, 5589, 376, 10361, 790, 14, 355, 372, 756, 953, 340, 4690, 14, 18218, 26, 355, 327, 710, 2876, 965, 2575, 22225, 436, 365, 9936, 370, 15422, 355, 327, 4020, 14, 982, 314, 2876, 365, 4702, 12, 372, 314, 2876, 14, 19524, 12, 355, 327, 372, 756, 465, 314, 2876, 965, 2757, 477, 18218, 701, 282, 4770, 355, 327, 31056, 14, 355, 340, 4690, 14, 751, 14, 374, 63, 2682, 26, 490, 372, 4690, 14, 751, 355, 587, 26, 490, 372, 756, 953, 340, 440, 4690, 14, 12312, 63, 498, 63, 16340, 837, 355, 372, 291, 423, 8222, 8, 2913, 12, 4770, 12, 664, 63, 2913, 9, 398, 372, 756, 339, 347, 1218, 63, 16856, 63, 751, 8, 277, 12, 4770, 12, 892, 63, 751, 29, 403, 12, 3222, 63, 2123, 29, 549, 12, 2490, 1056, 29, 403, 12, 4690, 63, 815, 10324, 1011, 751, 63, 815, 304, 267, 408, 267, 2790, 282, 892, 12, 21325, 1124, 1899, 4542, 3550, 282, 267, 1124, 11757, 5736, 1040, 436, 3031, 2399, 10361, 790, 370, 314, 267, 1124, 1899, 4542, 8152, 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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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 ]
miquelo/caviar
packages/caviar/engine/__init__.py
1
3783
# # This file is part of CAVIAR. # # CAVIAR 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. # # CAVIAR 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 CAVIAR. If not, see <http://www.gnu.org/licenses/>. # """ Engine module. """ import caviar.engine.asadmin import caviar.engine.keytool import caviar.engine.lb import caviar.engine.management import caviar.engine.nodealloc import caviar.network class Engine: """ GlassFish engine. :param Machinery machinery: Provided machinery. :param ssh.SSHSessionFactory ssh_session_fact: SSH session factory. :param str master_password: Used master password. """ def __init__(self, machinery, ssh_session_fact, master_password, das_server_name, node_alloc_server_prefix): self.__machinery = machinery self.__ssh_session_fact = ssh_session_fact self.__master_password = master_password self.__das_server_name = das_server_name self.__node_alloc_server_prefix = node_alloc_server_prefix def __das_machine(self): return self.__machinery.server(self.__das_server_name) def __node_allocator_machine(self, name): return self.__machinery.server( "{}-{}".format( self.__node_alloc_server_prefix, name ), self.__das_machine().appserver_public_key_path ) def __load_balancer_machine(self, name): return self.__machinery.load_balancer( name, self.__das_machine().appserver_public_key_path ) @property def server_node_dir(self): """ Server node directory. :rtype: str """ return self.__das_machine().server_node_dir def management(self, domain_name, admin_port, admin_user, admin_password): """ DAS management client. :rtype: management.Management :return: The DAS management client. """ return caviar.engine.management.Management( self.__das_machine(), admin_port, caviar.network.http.HTTPBasicAuth( admin_user, admin_password ) ) def asadmin(self): """ DAS `asadmin` utility. :rtype: asadmin.Asadmin :return: The DAS `asadmin` utility. """ return caviar.engine.asadmin.Asadmin( self.__ssh_session_fact, self.__das_machine(), self.__master_password ) def keytool(self): return caviar.engine.keytool.Keytool( self.__ssh_session_fact, self.__das_machine(), self.__master_password ) def node_allocator(self, name): """ Restore the node allocator with the given name and make it manageable. :param str name: Node allocator name. :rtype: nodealloc.NodeAllocator :return: The node allocator. """ return caviar.engine.nodealloc.NodeAllocator( self.__ssh_session_fact, self.__das_machine(), self.__node_allocator_machine(name) ) def load_balancer(self, cluster_name): """ Restore the load balance machine for the specified cluster and make it manageable. :param str cluster_name: Name of the cluster which load will be balanced. :rtype: lb.LoadBalancer :return: The load balancer. """ return caviar.engine.lb.LoadBalancer( self.__ssh_session_fact, self.__das_machine(), self.__load_balancer_machine(cluster_name), self.__master_password ) def close(self): """ Close this engine. Log out from all SSH sessions. """ self.__ssh_session_fact.close()
gpl-3.0
[ 3, 199, 3, 961, 570, 365, 1777, 402, 445, 32636, 689, 14, 199, 3, 199, 3, 445, 32636, 689, 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, 445, 32636, 689, 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, 445, 32636, 689, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 624, 199, 8524, 859, 14, 199, 624, 199, 199, 646, 1704, 433, 285, 14, 3908, 14, 305, 2113, 199, 646, 1704, 433, 285, 14, 3908, 14, 498, 3557, 199, 646, 1704, 433, 285, 14, 3908, 14, 6374, 199, 646, 1704, 433, 285, 14, 3908, 14, 8110, 199, 646, 1704, 433, 285, 14, 3908, 14, 932, 9373, 199, 646, 1704, 433, 285, 14, 1200, 199, 199, 533, 12580, 26, 421, 198, 624, 199, 198, 39, 4297, 38, 2453, 6869, 14, 421, 198, 26, 635, 30611, 20067, 28540, 26, 21979, 2165, 11923, 28540, 14, 199, 198, 26, 635, 8635, 14, 13716, 4434, 2927, 8635, 63, 1730, 63, 7783, 26, 21979, 12027, 2351, 6434, 14, 199, 198, 26, 635, 620, 5288, 63, 2060, 26, 21979, 8051, 5288, 2505, 14, 199, 198, 624, 421, 198, 318, 636, 826, 721, 277, 12, 28540, 12, 8635, 63, 1730, 63, 7783, 12, 5288, 63, 2060, 12, 686, 198, 24315, 63, 1000, 63, 354, 12, 1031, 63, 9373, 63, 1000, 63, 1861, 304, 2742, 198, 277, 855, 14121, 20067, 275, 28540, 507, 198, 277, 855, 5510, 63, 1730, 63, 7783, 275, 8635, 63, 1730, 63, 7783, 507, 198, 277, 855, 4133, 63, 2060, 275, 5288, 63, 2060, 507, 198, 277, 855, 24315, 63, 1000, 63, 354, 275, 366, 305, 63, 1000, 63, 354, 507, 198, 277, 855, 932, 63, 9373, 63, 1000, 63, 1861, 275, 1031, 63, 9373, 63, 1000, 63, 1861, 421, 198, 318, 636, 24315, 63, 6744, 8, 277, 304, 28550, 198, 1107, 291, 855, 14121, 20067, 14, 1000, 8, 277, 855, 24315, 63, 1000, 63, 354, 9, 18118, 198, 318, 636, 932, 63, 14228, 63, 6744, 8, 277, 12, 536, 304, 28550, 198, 1107, 291, 855, 14121, 20067, 14, 1000, 8, 686, 198, 2, 2440, 13, 13536, 908, 8, 1585, 198, 277, 855, 932, 63, 9373, 63, 1000, 63, 1861, 12, 1585, 198, 354, 686, 198, 395, 686, 198, 277, 855, 24315, 63, 6744, 1252, 571, 1000, 63, 3455, 63, 498, 63, 515, 507, 198, 9, 18118, 198, 318, 636, 912, 63, 11841, 63, 6744, 8, 277, 12, 536, 304, 28550, 198, 1107, 291, 855, 14121, 20067, 14, 912, 63, 11841, 8, 686, 198, 354, 12, 686, 198, 277, 855, 24315, 63, 6744, 1252, 571, 1000, 63, 3455, 63, 498, 63, 515, 507, 198, 9, 18118, 198, 32, 1829, 199, 198, 318, 1654, 63, 932, 63, 694, 8, 277, 304, 28550, 198, 624, 507, 198, 3120, 1031, 2082, 14, 9068, 198, 26, 4500, 26, 686, 257, 620, 507, 198, 624, 9068, 198, 1107, 291, 855, 24315, 63, 6744, 1252, 1000, 63, 932, 63, 694, 18118, 198, 318, 10041, 8, 277, 12, 2881, 63, 354, 12, 4628, 63, 719, 12, 4628, 63, 751, 12, 4628, 63, 2060, 304, 2742, 198, 624, 507, 198, 36, 1179, 10041, 1890, 14, 15075, 507, 198, 26, 4500, 26, 686, 257, 10041, 14, 14552, 507, 198, 26, 1107, 26, 686, 257, 710, 577, 1179, 10041, 1890, 14, 507, 198, 624, 2742, 198, 1107, 1704, 433, 285, 14, 3908, 14, 8110, 14, 14552, 8, 686, 198, 277, 855, 24315, 63, 6744, 1062, 686, 198, 2113, 63, 719, 12, 686, 198, 696, 433, 285, 14, 1200, 14, 1014, 14, 2856, 6845, 2817, 8, 1585, 198, 2113, 63, 751, 12, 1585, 198, 2113, 63, 2060, 686, 198, 9, 507, 198, 9, 421, 198, 318, 465, 2113, 8, 277, 304, 2742, 198, 624, 507, 198, 36, 1179, 658, 305, 2113, 64, 11420, 14, 2742, 198, 26, 4500, 26, 686, 257, 465, 2113, 14, 2822, 2113, 507, 198, 26, 1107, 26, 686, 257, 710, 577, 1179, 658, 305, 2113, 64, 11420, 14, 507, 198, 624, 2742, 198, 1107, 1704, 433, 285, 14, 3908, 14, 305, 2113, 14, 2822, 2113, 8, 686, 198, 277, 855, 5510, 63, 1730, 63, 7783, 12, 686, 198, 277, 855, 24315, 63, 6744, 1062, 686, 198, 277, 855, 4133, 63, 2060, 507, 198, 9, 18118, 198, 318, 790, 3557, 8, 277, 304, 28550, 198, 1107, 1704, 433, 285, 14, 3908, 14, 498, 3557, 14, 1197, 3557, 8, 686, 198, 277, 855, 5510, 63, 1730, 63, 7783, 12, 686, 198, 277, 855, 24315, 63, 6744, 1062, 686, 198, 277, 855, 4133, 63, 2060, 507, 198, 9, 18118, 198, 318, 1031, 63, 14228, 8, 277, 12, 536, 304, 28550, 198, 624, 507, 198, 21012, 314, 1031, 741, 6354, 543, 314, 1627, 536, 436, 1852, 652, 9635, 461, 14, 9068, 198, 26, 635, 620, 536, 26, 686, 257, 5013, 741, 6354, 536, 14, 15075, 507, 198, 26, 4500, 26, 686, 257, 1031, 9373, 14, 1716, 20191, 507, 198, 26, 1107, 26, 686, 257, 710, 1031, 741, 6354, 14, 507, 198, 624, 9068, 198, 1107, 1704, 433, 285, 14, 3908, 14, 932, 9373, 14, 1716, 20191, 8, 686, 198, 277, 855, 5510, 63, 1730, 63, 7783, 12, 686, 198, 277, 855, 24315, 63, 6744, 1062, 686, 198, 277, 855, 932, 63, 14228, 63, 6744, 8, 354, 9, 507, 198, 9, 18118, 198, 318, 2248, 63, 11841, 8, 277, 12, 4350, 63, 354, 304, 28550, 198, 624, 507, 198, 21012, 314, 2248, 14094, 6844, 367, 314, 2013, 4350, 436, 1852, 652, 507, 198, 9053, 461, 14, 9068, 198, 26, 635, 620 ]
[ 199, 3, 961, 570, 365, 1777, 402, 445, 32636, 689, 14, 199, 3, 199, 3, 445, 32636, 689, 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, 445, 32636, 689, 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, 445, 32636, 689, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 199, 624, 199, 8524, 859, 14, 199, 624, 199, 199, 646, 1704, 433, 285, 14, 3908, 14, 305, 2113, 199, 646, 1704, 433, 285, 14, 3908, 14, 498, 3557, 199, 646, 1704, 433, 285, 14, 3908, 14, 6374, 199, 646, 1704, 433, 285, 14, 3908, 14, 8110, 199, 646, 1704, 433, 285, 14, 3908, 14, 932, 9373, 199, 646, 1704, 433, 285, 14, 1200, 199, 199, 533, 12580, 26, 421, 198, 624, 199, 198, 39, 4297, 38, 2453, 6869, 14, 421, 198, 26, 635, 30611, 20067, 28540, 26, 21979, 2165, 11923, 28540, 14, 199, 198, 26, 635, 8635, 14, 13716, 4434, 2927, 8635, 63, 1730, 63, 7783, 26, 21979, 12027, 2351, 6434, 14, 199, 198, 26, 635, 620, 5288, 63, 2060, 26, 21979, 8051, 5288, 2505, 14, 199, 198, 624, 421, 198, 318, 636, 826, 721, 277, 12, 28540, 12, 8635, 63, 1730, 63, 7783, 12, 5288, 63, 2060, 12, 686, 198, 24315, 63, 1000, 63, 354, 12, 1031, 63, 9373, 63, 1000, 63, 1861, 304, 2742, 198, 277, 855, 14121, 20067, 275, 28540, 507, 198, 277, 855, 5510, 63, 1730, 63, 7783, 275, 8635, 63, 1730, 63, 7783, 507, 198, 277, 855, 4133, 63, 2060, 275, 5288, 63, 2060, 507, 198, 277, 855, 24315, 63, 1000, 63, 354, 275, 366, 305, 63, 1000, 63, 354, 507, 198, 277, 855, 932, 63, 9373, 63, 1000, 63, 1861, 275, 1031, 63, 9373, 63, 1000, 63, 1861, 421, 198, 318, 636, 24315, 63, 6744, 8, 277, 304, 28550, 198, 1107, 291, 855, 14121, 20067, 14, 1000, 8, 277, 855, 24315, 63, 1000, 63, 354, 9, 18118, 198, 318, 636, 932, 63, 14228, 63, 6744, 8, 277, 12, 536, 304, 28550, 198, 1107, 291, 855, 14121, 20067, 14, 1000, 8, 686, 198, 2, 2440, 13, 13536, 908, 8, 1585, 198, 277, 855, 932, 63, 9373, 63, 1000, 63, 1861, 12, 1585, 198, 354, 686, 198, 395, 686, 198, 277, 855, 24315, 63, 6744, 1252, 571, 1000, 63, 3455, 63, 498, 63, 515, 507, 198, 9, 18118, 198, 318, 636, 912, 63, 11841, 63, 6744, 8, 277, 12, 536, 304, 28550, 198, 1107, 291, 855, 14121, 20067, 14, 912, 63, 11841, 8, 686, 198, 354, 12, 686, 198, 277, 855, 24315, 63, 6744, 1252, 571, 1000, 63, 3455, 63, 498, 63, 515, 507, 198, 9, 18118, 198, 32, 1829, 199, 198, 318, 1654, 63, 932, 63, 694, 8, 277, 304, 28550, 198, 624, 507, 198, 3120, 1031, 2082, 14, 9068, 198, 26, 4500, 26, 686, 257, 620, 507, 198, 624, 9068, 198, 1107, 291, 855, 24315, 63, 6744, 1252, 1000, 63, 932, 63, 694, 18118, 198, 318, 10041, 8, 277, 12, 2881, 63, 354, 12, 4628, 63, 719, 12, 4628, 63, 751, 12, 4628, 63, 2060, 304, 2742, 198, 624, 507, 198, 36, 1179, 10041, 1890, 14, 15075, 507, 198, 26, 4500, 26, 686, 257, 10041, 14, 14552, 507, 198, 26, 1107, 26, 686, 257, 710, 577, 1179, 10041, 1890, 14, 507, 198, 624, 2742, 198, 1107, 1704, 433, 285, 14, 3908, 14, 8110, 14, 14552, 8, 686, 198, 277, 855, 24315, 63, 6744, 1062, 686, 198, 2113, 63, 719, 12, 686, 198, 696, 433, 285, 14, 1200, 14, 1014, 14, 2856, 6845, 2817, 8, 1585, 198, 2113, 63, 751, 12, 1585, 198, 2113, 63, 2060, 686, 198, 9, 507, 198, 9, 421, 198, 318, 465, 2113, 8, 277, 304, 2742, 198, 624, 507, 198, 36, 1179, 658, 305, 2113, 64, 11420, 14, 2742, 198, 26, 4500, 26, 686, 257, 465, 2113, 14, 2822, 2113, 507, 198, 26, 1107, 26, 686, 257, 710, 577, 1179, 658, 305, 2113, 64, 11420, 14, 507, 198, 624, 2742, 198, 1107, 1704, 433, 285, 14, 3908, 14, 305, 2113, 14, 2822, 2113, 8, 686, 198, 277, 855, 5510, 63, 1730, 63, 7783, 12, 686, 198, 277, 855, 24315, 63, 6744, 1062, 686, 198, 277, 855, 4133, 63, 2060, 507, 198, 9, 18118, 198, 318, 790, 3557, 8, 277, 304, 28550, 198, 1107, 1704, 433, 285, 14, 3908, 14, 498, 3557, 14, 1197, 3557, 8, 686, 198, 277, 855, 5510, 63, 1730, 63, 7783, 12, 686, 198, 277, 855, 24315, 63, 6744, 1062, 686, 198, 277, 855, 4133, 63, 2060, 507, 198, 9, 18118, 198, 318, 1031, 63, 14228, 8, 277, 12, 536, 304, 28550, 198, 624, 507, 198, 21012, 314, 1031, 741, 6354, 543, 314, 1627, 536, 436, 1852, 652, 9635, 461, 14, 9068, 198, 26, 635, 620, 536, 26, 686, 257, 5013, 741, 6354, 536, 14, 15075, 507, 198, 26, 4500, 26, 686, 257, 1031, 9373, 14, 1716, 20191, 507, 198, 26, 1107, 26, 686, 257, 710, 1031, 741, 6354, 14, 507, 198, 624, 9068, 198, 1107, 1704, 433, 285, 14, 3908, 14, 932, 9373, 14, 1716, 20191, 8, 686, 198, 277, 855, 5510, 63, 1730, 63, 7783, 12, 686, 198, 277, 855, 24315, 63, 6744, 1062, 686, 198, 277, 855, 932, 63, 14228, 63, 6744, 8, 354, 9, 507, 198, 9, 18118, 198, 318, 2248, 63, 11841, 8, 277, 12, 4350, 63, 354, 304, 28550, 198, 624, 507, 198, 21012, 314, 2248, 14094, 6844, 367, 314, 2013, 4350, 436, 1852, 652, 507, 198, 9053, 461, 14, 9068, 198, 26, 635, 620, 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, 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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 ]
harlowja/networkx
networkx/algorithms/flow/utils.py
41
5885
# -*- coding: utf-8 -*- """ Utility classes and functions for network flow algorithms. """ __author__ = """ysitu <ysitu@users.noreply.github.com>""" # Copyright (C) 2014 ysitu <ysitu@users.noreply.github.com> # All rights reserved. # BSD license. from collections import deque import networkx as nx __all__ = ['CurrentEdge', 'Level', 'GlobalRelabelThreshold', 'build_residual_network', 'detect_unboundedness', 'build_flow_dict'] class CurrentEdge(object): """Mechanism for iterating over out-edges incident to a node in a circular manner. StopIteration exception is raised when wraparound occurs. """ __slots__ = ('_edges', '_it', '_curr') def __init__(self, edges): self._edges = edges if self._edges: self._rewind() def get(self): return self._curr def move_to_next(self): try: self._curr = next(self._it) except StopIteration: self._rewind() raise def _rewind(self): self._it = iter(self._edges.items()) self._curr = next(self._it) class Level(object): """Active and inactive nodes in a level. """ __slots__ = ('active', 'inactive') def __init__(self): self.active = set() self.inactive = set() class GlobalRelabelThreshold(object): """Measurement of work before the global relabeling heuristic should be applied. """ def __init__(self, n, m, freq): self._threshold = (n + m) / freq if freq else float('inf') self._work = 0 def add_work(self, work): self._work += work def is_reached(self): return self._work >= self._threshold def clear_work(self): self._work = 0 def build_residual_network(G, capacity): """Build a residual network and initialize a zero flow. The residual network :samp:`R` from an input graph :samp:`G` has the same nodes as :samp:`G`. :samp:`R` is a DiGraph that contains a pair of edges :samp:`(u, v)` and :samp:`(v, u)` iff :samp:`(u, v)` is not a self-loop, and at least one of :samp:`(u, v)` and :samp:`(v, u)` exists in :samp:`G`. For each edge :samp:`(u, v)` in :samp:`R`, :samp:`R[u][v]['capacity']` is equal to the capacity of :samp:`(u, v)` in :samp:`G` if it exists in :samp:`G` or zero otherwise. If the capacity is infinite, :samp:`R[u][v]['capacity']` will have a high arbitrary finite value that does not affect the solution of the problem. This value is stored in :samp:`R.graph['inf']`. For each edge :samp:`(u, v)` in :samp:`R`, :samp:`R[u][v]['flow']` represents the flow function of :samp:`(u, v)` and satisfies :samp:`R[u][v]['flow'] == -R[v][u]['flow']`. The flow value, defined as the total flow into :samp:`t`, the sink, is stored in :samp:`R.graph['flow_value']`. If :samp:`cutoff` is not specified, reachability to :samp:`t` using only edges :samp:`(u, v)` such that :samp:`R[u][v]['flow'] < R[u][v]['capacity']` induces a minimum :samp:`s`-:samp:`t` cut. """ if G.is_multigraph(): raise nx.NetworkXError( 'MultiGraph and MultiDiGraph not supported (yet).') R = nx.DiGraph() R.add_nodes_from(G) inf = float('inf') # Extract edges with positive capacities. Self loops excluded. edge_list = [(u, v, attr) for u, v, attr in G.edges_iter(data=True) if u != v and attr.get(capacity, inf) > 0] # Simulate infinity with three times the sum of the finite edge capacities # or any positive value if the sum is zero. This allows the # infinite-capacity edges to be distinguished for unboundedness detection # and directly participate in residual capacity calculation. If the maximum # flow is finite, these edges cannot appear in the minimum cut and thus # guarantee correctness. Since the residual capacity of an # infinite-capacity edge is always at least 2/3 of inf, while that of an # finite-capacity edge is at most 1/3 of inf, if an operation moves more # than 1/3 of inf units of flow to t, there must be an infinite-capacity # s-t path in G. inf = 3 * sum(attr[capacity] for u, v, attr in edge_list if capacity in attr and attr[capacity] != inf) or 1 if G.is_directed(): for u, v, attr in edge_list: r = min(attr.get(capacity, inf), inf) if not R.has_edge(u, v): # Both (u, v) and (v, u) must be present in the residual # network. R.add_edge(u, v, capacity=r) R.add_edge(v, u, capacity=0) else: # The edge (u, v) was added when (v, u) was visited. R[u][v]['capacity'] = r else: for u, v, attr in edge_list: # Add a pair of edges with equal residual capacities. r = min(attr.get(capacity, inf), inf) R.add_edge(u, v, capacity=r) R.add_edge(v, u, capacity=r) # Record the value simulating infinity. R.graph['inf'] = inf return R def detect_unboundedness(R, s, t): """Detect an infinite-capacity s-t path in R. """ q = deque([s]) seen = set([s]) inf = R.graph['inf'] while q: u = q.popleft() for v, attr in R[u].items(): if attr['capacity'] == inf and v not in seen: if v == t: raise nx.NetworkXUnbounded( 'Infinite capacity path, flow unbounded above.') seen.add(v) q.append(v) def build_flow_dict(G, R): """Build a flow dictionary from a residual network. """ flow_dict = {} for u in G: flow_dict[u] = dict((v, 0) for v in G[u]) flow_dict[u].update((v, attr['flow']) for v, attr in R[u].items() if attr['flow'] > 0) return flow_dict
bsd-3-clause
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 199, 17505, 3992, 436, 3423, 367, 2784, 6369, 18036, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 408, 89, 2221, 85, 665, 89, 2221, 85, 32, 3707, 14, 27400, 19786, 14, 5031, 14, 957, 11193, 199, 3, 1898, 334, 35, 9, 6927, 612, 2221, 85, 665, 89, 2221, 85, 32, 3707, 14, 27400, 19786, 14, 5031, 14, 957, 30, 199, 3, 2900, 4481, 4644, 14, 199, 3, 6289, 4190, 14, 199, 199, 504, 5055, 492, 15782, 199, 646, 24313, 465, 8484, 199, 199, 363, 452, 363, 275, 788, 5639, 12886, 297, 283, 4670, 297, 283, 7025, 5640, 902, 12109, 297, 1779, 283, 1506, 63, 20161, 63, 1200, 297, 283, 13552, 63, 324, 7547, 4171, 297, 283, 1506, 63, 1659, 63, 807, 418, 421, 199, 533, 9338, 12886, 8, 785, 304, 272, 408, 1352, 11993, 367, 25012, 1806, 734, 13, 6929, 315, 12689, 370, 282, 1031, 315, 282, 15032, 272, 30800, 14, 10852, 1919, 365, 4915, 1380, 336, 345, 462, 1034, 11058, 14, 272, 408, 272, 636, 7257, 363, 275, 12331, 6929, 297, 2513, 390, 297, 2513, 9808, 358, 339, 347, 636, 826, 721, 277, 12, 8207, 304, 267, 291, 423, 6929, 275, 8207, 267, 340, 291, 423, 6929, 26, 288, 291, 423, 5257, 688, 342, 339, 347, 664, 8, 277, 304, 267, 372, 291, 423, 9808, 339, 347, 4057, 63, 475, 63, 2184, 8, 277, 304, 267, 862, 26, 288, 291, 423, 9808, 275, 2163, 8, 277, 423, 390, 9, 267, 871, 10852, 26, 288, 291, 423, 5257, 688, 342, 288, 746, 339, 347, 485, 5257, 688, 8, 277, 304, 267, 291, 423, 390, 275, 2740, 8, 277, 423, 6929, 14, 1744, 1012, 267, 291, 423, 9808, 275, 2163, 8, 277, 423, 390, 9, 421, 199, 533, 20400, 8, 785, 304, 272, 408, 7472, 436, 21325, 3380, 315, 282, 2166, 14, 272, 408, 272, 636, 7257, 363, 275, 661, 2682, 297, 283, 16856, 358, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 2682, 275, 663, 342, 267, 291, 14, 16856, 275, 663, 342, 421, 199, 533, 13641, 5640, 902, 12109, 8, 785, 304, 272, 408, 18611, 434, 402, 1736, 2544, 314, 2288, 295, 1302, 316, 25332, 1077, 506, 272, 6781, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 302, 12, 333, 12, 9220, 304, 267, 291, 423, 7227, 275, 334, 78, 435, 333, 9, 1182, 9220, 340, 9220, 587, 2069, 360, 4904, 358, 267, 291, 423, 800, 275, 378, 339, 347, 1050, 63, 800, 8, 277, 12, 1736, 304, 267, 291, 423, 800, 847, 1736, 339, 347, 365, 63, 30931, 8, 277, 304, 267, 372, 291, 423, 800, 2356, 291, 423, 7227, 339, 347, 5436, 63, 800, 8, 277, 304, 267, 291, 423, 800, 275, 378, 421, 199, 318, 1900, 63, 20161, 63, 1200, 8, 39, 12, 14893, 304, 272, 408, 3425, 282, 16731, 2784, 436, 8265, 282, 4697, 6369, 14, 339, 710, 16731, 2784, 520, 16557, 1705, 50, 64, 687, 376, 1324, 3343, 520, 16557, 1705, 39, 64, 965, 314, 272, 2011, 3380, 465, 520, 16557, 1705, 39, 2313, 520, 16557, 1705, 50, 64, 365, 282, 3757, 4578, 626, 3509, 282, 4092, 272, 402, 8207, 520, 16557, 1705, 8, 85, 12, 373, 12544, 436, 520, 16557, 1705, 8, 86, 12, 399, 12544, 17963, 520, 16557, 1705, 8, 85, 12, 373, 12544, 365, 440, 282, 272, 291, 13, 3813, 12, 436, 737, 5210, 1373, 402, 520, 16557, 1705, 8, 85, 12, 373, 12544, 436, 520, 16557, 1705, 8, 86, 12, 399, 12544, 3495, 272, 315, 520, 16557, 1705, 39, 2313, 339, 2104, 1924, 6275, 520, 16557, 1705, 8, 85, 12, 373, 12544, 315, 520, 16557, 1705, 50, 3559, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 10457, 418, 64, 272, 365, 4472, 370, 314, 14893, 402, 520, 16557, 1705, 8, 85, 12, 373, 12544, 315, 520, 16557, 1705, 39, 64, 340, 652, 3495, 272, 315, 520, 16557, 1705, 39, 64, 503, 4697, 4257, 14, 982, 314, 14893, 365, 15258, 12, 272, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 10457, 418, 64, 911, 1172, 282, 4721, 9697, 21837, 574, 272, 626, 1630, 440, 12787, 314, 8744, 402, 314, 5160, 14, 961, 574, 365, 5489, 315, 272, 520, 16557, 1705, 50, 14, 2180, 459, 4904, 418, 2313, 2104, 1924, 6275, 520, 16557, 1705, 8, 85, 12, 373, 12544, 315, 520, 16557, 1705, 50, 3559, 272, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 1659, 418, 64, 8469, 314, 6369, 805, 402, 520, 16557, 1705, 8, 85, 12, 373, 12544, 436, 272, 13529, 5604, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 1659, 418, 508, 446, 50, 59, 86, 1527, 85, 2733, 1659, 418, 2313, 339, 710, 6369, 574, 12, 3247, 465, 314, 3141, 6369, 1901, 520, 16557, 1705, 84, 3559, 314, 19241, 12, 365, 272, 5489, 315, 520, 16557, 1705, 50, 14, 2180, 459, 1659, 63, 585, 418, 2313, 982, 520, 16557, 1705, 17708, 64, 365, 440, 272, 2013, 12, 12276, 3616, 370, 520, 16557, 1705, 84, 64, 1808, 1454, 8207, 520, 16557, 1705, 8, 85, 12, 373, 12544, 4066, 272, 626, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 1659, 418, 665, 820, 59, 85, 1527, 86, 2733, 10457, 418, 64, 315, 10569, 282, 7481, 272, 520, 16557, 1705, 83, 64, 13, 26, 16557, 1705, 84, 64, 10415, 14, 339, 408, 272, 340, 598, 14, 374, 63, 3029, 2180, 837, 267, 746, 8484, 14, 4491, 29356, 8, 288, 283, 3947, 4578, 436, 6879, 23208, 440, 3748, 334, 28064, 28583, 339, 820, 275, 8484, 14, 23208, 342, 272, 820, 14, 525, 63, 2415, 63, 504, 8, 39, 9, 339, 10739, 275, 2069, 360, 4904, 358, 272, 327, 12892, 8207, 543, 7317, 28068, 18207, 14, 23820, 17222, 8789, 14, 272, 6275, 63, 513, 275, 3842, 85, 12, 373, 12, 1921, 9, 367, 399, 12, 373, 12, 1921, 315, 598, 14, 6929, 63, 1661, 8, 576, 29, 549, 9, 326, 340, 399, 1137, 373, 436, 1921, 14, 362, 8, 10457, 12, 10739, 9, 690, 378, 61, 272, 327, 10751, 5434, 23573, 543, 7795, 5431, 314, 3089, 402, 314, 21837, 6275, 28068, 18207, 272, 327, 503, 1263, 7317 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 199, 17505, 3992, 436, 3423, 367, 2784, 6369, 18036, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 408, 89, 2221, 85, 665, 89, 2221, 85, 32, 3707, 14, 27400, 19786, 14, 5031, 14, 957, 11193, 199, 3, 1898, 334, 35, 9, 6927, 612, 2221, 85, 665, 89, 2221, 85, 32, 3707, 14, 27400, 19786, 14, 5031, 14, 957, 30, 199, 3, 2900, 4481, 4644, 14, 199, 3, 6289, 4190, 14, 199, 199, 504, 5055, 492, 15782, 199, 646, 24313, 465, 8484, 199, 199, 363, 452, 363, 275, 788, 5639, 12886, 297, 283, 4670, 297, 283, 7025, 5640, 902, 12109, 297, 1779, 283, 1506, 63, 20161, 63, 1200, 297, 283, 13552, 63, 324, 7547, 4171, 297, 283, 1506, 63, 1659, 63, 807, 418, 421, 199, 533, 9338, 12886, 8, 785, 304, 272, 408, 1352, 11993, 367, 25012, 1806, 734, 13, 6929, 315, 12689, 370, 282, 1031, 315, 282, 15032, 272, 30800, 14, 10852, 1919, 365, 4915, 1380, 336, 345, 462, 1034, 11058, 14, 272, 408, 272, 636, 7257, 363, 275, 12331, 6929, 297, 2513, 390, 297, 2513, 9808, 358, 339, 347, 636, 826, 721, 277, 12, 8207, 304, 267, 291, 423, 6929, 275, 8207, 267, 340, 291, 423, 6929, 26, 288, 291, 423, 5257, 688, 342, 339, 347, 664, 8, 277, 304, 267, 372, 291, 423, 9808, 339, 347, 4057, 63, 475, 63, 2184, 8, 277, 304, 267, 862, 26, 288, 291, 423, 9808, 275, 2163, 8, 277, 423, 390, 9, 267, 871, 10852, 26, 288, 291, 423, 5257, 688, 342, 288, 746, 339, 347, 485, 5257, 688, 8, 277, 304, 267, 291, 423, 390, 275, 2740, 8, 277, 423, 6929, 14, 1744, 1012, 267, 291, 423, 9808, 275, 2163, 8, 277, 423, 390, 9, 421, 199, 533, 20400, 8, 785, 304, 272, 408, 7472, 436, 21325, 3380, 315, 282, 2166, 14, 272, 408, 272, 636, 7257, 363, 275, 661, 2682, 297, 283, 16856, 358, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 2682, 275, 663, 342, 267, 291, 14, 16856, 275, 663, 342, 421, 199, 533, 13641, 5640, 902, 12109, 8, 785, 304, 272, 408, 18611, 434, 402, 1736, 2544, 314, 2288, 295, 1302, 316, 25332, 1077, 506, 272, 6781, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 302, 12, 333, 12, 9220, 304, 267, 291, 423, 7227, 275, 334, 78, 435, 333, 9, 1182, 9220, 340, 9220, 587, 2069, 360, 4904, 358, 267, 291, 423, 800, 275, 378, 339, 347, 1050, 63, 800, 8, 277, 12, 1736, 304, 267, 291, 423, 800, 847, 1736, 339, 347, 365, 63, 30931, 8, 277, 304, 267, 372, 291, 423, 800, 2356, 291, 423, 7227, 339, 347, 5436, 63, 800, 8, 277, 304, 267, 291, 423, 800, 275, 378, 421, 199, 318, 1900, 63, 20161, 63, 1200, 8, 39, 12, 14893, 304, 272, 408, 3425, 282, 16731, 2784, 436, 8265, 282, 4697, 6369, 14, 339, 710, 16731, 2784, 520, 16557, 1705, 50, 64, 687, 376, 1324, 3343, 520, 16557, 1705, 39, 64, 965, 314, 272, 2011, 3380, 465, 520, 16557, 1705, 39, 2313, 520, 16557, 1705, 50, 64, 365, 282, 3757, 4578, 626, 3509, 282, 4092, 272, 402, 8207, 520, 16557, 1705, 8, 85, 12, 373, 12544, 436, 520, 16557, 1705, 8, 86, 12, 399, 12544, 17963, 520, 16557, 1705, 8, 85, 12, 373, 12544, 365, 440, 282, 272, 291, 13, 3813, 12, 436, 737, 5210, 1373, 402, 520, 16557, 1705, 8, 85, 12, 373, 12544, 436, 520, 16557, 1705, 8, 86, 12, 399, 12544, 3495, 272, 315, 520, 16557, 1705, 39, 2313, 339, 2104, 1924, 6275, 520, 16557, 1705, 8, 85, 12, 373, 12544, 315, 520, 16557, 1705, 50, 3559, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 10457, 418, 64, 272, 365, 4472, 370, 314, 14893, 402, 520, 16557, 1705, 8, 85, 12, 373, 12544, 315, 520, 16557, 1705, 39, 64, 340, 652, 3495, 272, 315, 520, 16557, 1705, 39, 64, 503, 4697, 4257, 14, 982, 314, 14893, 365, 15258, 12, 272, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 10457, 418, 64, 911, 1172, 282, 4721, 9697, 21837, 574, 272, 626, 1630, 440, 12787, 314, 8744, 402, 314, 5160, 14, 961, 574, 365, 5489, 315, 272, 520, 16557, 1705, 50, 14, 2180, 459, 4904, 418, 2313, 2104, 1924, 6275, 520, 16557, 1705, 8, 85, 12, 373, 12544, 315, 520, 16557, 1705, 50, 3559, 272, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 1659, 418, 64, 8469, 314, 6369, 805, 402, 520, 16557, 1705, 8, 85, 12, 373, 12544, 436, 272, 13529, 5604, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 1659, 418, 508, 446, 50, 59, 86, 1527, 85, 2733, 1659, 418, 2313, 339, 710, 6369, 574, 12, 3247, 465, 314, 3141, 6369, 1901, 520, 16557, 1705, 84, 3559, 314, 19241, 12, 365, 272, 5489, 315, 520, 16557, 1705, 50, 14, 2180, 459, 1659, 63, 585, 418, 2313, 982, 520, 16557, 1705, 17708, 64, 365, 440, 272, 2013, 12, 12276, 3616, 370, 520, 16557, 1705, 84, 64, 1808, 1454, 8207, 520, 16557, 1705, 8, 85, 12, 373, 12544, 4066, 272, 626, 520, 16557, 1705, 50, 59, 85, 1527, 86, 2733, 1659, 418, 665, 820, 59, 85, 1527, 86, 2733, 10457, 418, 64, 315, 10569, 282, 7481, 272, 520, 16557, 1705, 83, 64, 13, 26, 16557, 1705, 84, 64, 10415, 14, 339, 408, 272, 340, 598, 14, 374, 63, 3029, 2180, 837, 267, 746, 8484, 14, 4491, 29356, 8, 288, 283, 3947, 4578, 436, 6879, 23208, 440, 3748, 334, 28064, 28583, 339, 820, 275, 8484, 14, 23208, 342, 272, 820, 14, 525, 63, 2415, 63, 504, 8, 39, 9, 339, 10739, 275, 2069, 360, 4904, 358, 272, 327, 12892, 8207, 543, 7317, 28068, 18207, 14, 23820, 17222, 8789, 14, 272, 6275, 63, 513, 275, 3842, 85, 12, 373, 12, 1921, 9, 367, 399, 12, 373, 12, 1921, 315, 598, 14, 6929, 63, 1661, 8, 576, 29, 549, 9, 326, 340, 399, 1137, 373, 436, 1921, 14, 362, 8, 10457, 12, 10739, 9, 690, 378, 61, 272, 327, 10751, 5434, 23573, 543, 7795, 5431, 314, 3089, 402, 314, 21837, 6275, 28068, 18207, 272, 327, 503, 1263, 7317, 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, 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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 ]
naziris/HomeSecPi
venv/lib/python2.7/site-packages/setuptools/tests/test_markerlib.py
449
2506
import os import unittest from setuptools.tests.py26compat import skipIf try: import ast except ImportError: pass class TestMarkerlib(unittest.TestCase): @skipIf('ast' not in globals(), "ast not available (Python < 2.6?)") def test_markers(self): from _markerlib import interpret, default_environment, compile os_name = os.name self.assertTrue(interpret("")) self.assertTrue(interpret("os.name != 'buuuu'")) self.assertTrue(interpret("os_name != 'buuuu'")) self.assertTrue(interpret("python_version > '1.0'")) self.assertTrue(interpret("python_version < '5.0'")) self.assertTrue(interpret("python_version <= '5.0'")) self.assertTrue(interpret("python_version >= '1.0'")) self.assertTrue(interpret("'%s' in os.name" % os_name)) self.assertTrue(interpret("'%s' in os_name" % os_name)) self.assertTrue(interpret("'buuuu' not in os.name")) self.assertFalse(interpret("os.name == 'buuuu'")) self.assertFalse(interpret("os_name == 'buuuu'")) self.assertFalse(interpret("python_version < '1.0'")) self.assertFalse(interpret("python_version > '5.0'")) self.assertFalse(interpret("python_version >= '5.0'")) self.assertFalse(interpret("python_version <= '1.0'")) self.assertFalse(interpret("'%s' not in os.name" % os_name)) self.assertFalse(interpret("'buuuu' in os.name and python_version >= '5.0'")) self.assertFalse(interpret("'buuuu' in os_name and python_version >= '5.0'")) environment = default_environment() environment['extra'] = 'test' self.assertTrue(interpret("extra == 'test'", environment)) self.assertFalse(interpret("extra == 'doc'", environment)) def raises_nameError(): try: interpret("python.version == '42'") except NameError: pass else: raise Exception("Expected NameError") raises_nameError() def raises_syntaxError(): try: interpret("(x for x in (4,))") except SyntaxError: pass else: raise Exception("Expected SyntaxError") raises_syntaxError() statement = "python_version == '5'" self.assertEqual(compile(statement).__doc__, statement)
apache-2.0
[ 646, 747, 199, 646, 2882, 199, 504, 9116, 14, 2219, 14, 647, 1479, 5819, 492, 3372, 3917, 199, 199, 893, 26, 272, 492, 6073, 199, 2590, 3545, 26, 272, 986, 199, 199, 533, 1379, 12825, 773, 8, 2796, 14, 1746, 304, 339, 768, 15118, 360, 1810, 7, 440, 315, 7992, 1062, 267, 298, 1810, 440, 2808, 334, 4718, 665, 499, 14, 22, 31, 6320, 272, 347, 511, 63, 16835, 8, 277, 304, 267, 687, 485, 4211, 773, 492, 15579, 12, 849, 63, 5418, 12, 6555, 2728, 747, 63, 354, 275, 747, 14, 354, 2728, 291, 14, 1815, 8, 21533, 31348, 2728, 291, 14, 1815, 8, 21533, 480, 736, 14, 354, 1137, 283, 464, 17031, 85, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 736, 63, 354, 1137, 283, 464, 17031, 85, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 1548, 63, 1023, 690, 283, 17, 14, 16, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 1548, 63, 1023, 665, 283, 21, 14, 16, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 1548, 63, 1023, 2695, 283, 21, 14, 16, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 1548, 63, 1023, 2356, 283, 17, 14, 16, 7, 2237, 267, 291, 14, 1815, 8, 21533, 21065, 83, 7, 315, 747, 14, 354, 2, 450, 747, 63, 354, 430, 267, 291, 14, 1815, 8, 21533, 21065, 83, 7, 315, 747, 63, 354, 2, 450, 747, 63, 354, 430, 267, 291, 14, 1815, 8, 21533, 15587, 464, 17031, 85, 7, 440, 315, 747, 14, 354, 2237, 2728, 291, 14, 3334, 8, 21533, 480, 736, 14, 354, 508, 283, 464, 17031, 85, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 736, 63, 354, 508, 283, 464, 17031, 85, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 1548, 63, 1023, 665, 283, 17, 14, 16, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 1548, 63, 1023, 690, 283, 21, 14, 16, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 1548, 63, 1023, 2356, 283, 21, 14, 16, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 1548, 63, 1023, 2695, 283, 17, 14, 16, 7, 2237, 267, 291, 14, 3334, 8, 21533, 21065, 83, 7, 440, 315, 747, 14, 354, 2, 450, 747, 63, 354, 430, 267, 291, 14, 3334, 8, 21533, 15587, 464, 17031, 85, 7, 315, 747, 14, 354, 436, 2366, 63, 1023, 2356, 283, 21, 14, 16, 7, 2237, 27144, 291, 14, 3334, 8, 21533, 15587, 464, 17031, 85, 7, 315, 747, 63, 354, 436, 2366, 63, 1023, 2356, 283, 21, 14, 16, 7, 2237, 258, 2728, 3734, 275, 849, 63, 5418, 342, 267, 3734, 459, 2911, 418, 275, 283, 396, 7, 267, 291, 14, 1815, 8, 21533, 480, 2911, 508, 283, 396, 4662, 3734, 430, 267, 291, 14, 3334, 8, 21533, 480, 2911, 508, 283, 1301, 4662, 3734, 430, 2728, 347, 6534, 63, 354, 547, 837, 288, 862, 26, 355, 15579, 480, 1548, 14, 1023, 508, 283, 2260, 9859, 288, 871, 12746, 26, 355, 986, 288, 587, 26, 355, 746, 2186, 480, 6964, 12746, 531, 2728, 6534, 63, 354, 547, 342, 2728, 347, 6534, 63, 1786, 6825, 837, 288, 862, 26, 355, 15579, 18353, 88, 367, 671, 315, 334, 20, 4641, 531, 288, 871, 12053, 26, 355, 986, 288, 587, 26, 355, 746, 2186, 480, 6964, 12053, 531, 10631, 6534, 63, 1786, 6825, 342, 2728, 5164, 275, 298, 1548, 63, 1023, 508, 283, 21, 4065, 267, 291, 14, 629, 8, 2014, 8, 6242, 2843, 1301, 3108, 5164, 9, 27844, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 199, 646, 2882, 199, 504, 9116, 14, 2219, 14, 647, 1479, 5819, 492, 3372, 3917, 199, 199, 893, 26, 272, 492, 6073, 199, 2590, 3545, 26, 272, 986, 199, 199, 533, 1379, 12825, 773, 8, 2796, 14, 1746, 304, 339, 768, 15118, 360, 1810, 7, 440, 315, 7992, 1062, 267, 298, 1810, 440, 2808, 334, 4718, 665, 499, 14, 22, 31, 6320, 272, 347, 511, 63, 16835, 8, 277, 304, 267, 687, 485, 4211, 773, 492, 15579, 12, 849, 63, 5418, 12, 6555, 2728, 747, 63, 354, 275, 747, 14, 354, 2728, 291, 14, 1815, 8, 21533, 31348, 2728, 291, 14, 1815, 8, 21533, 480, 736, 14, 354, 1137, 283, 464, 17031, 85, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 736, 63, 354, 1137, 283, 464, 17031, 85, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 1548, 63, 1023, 690, 283, 17, 14, 16, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 1548, 63, 1023, 665, 283, 21, 14, 16, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 1548, 63, 1023, 2695, 283, 21, 14, 16, 7, 2237, 267, 291, 14, 1815, 8, 21533, 480, 1548, 63, 1023, 2356, 283, 17, 14, 16, 7, 2237, 267, 291, 14, 1815, 8, 21533, 21065, 83, 7, 315, 747, 14, 354, 2, 450, 747, 63, 354, 430, 267, 291, 14, 1815, 8, 21533, 21065, 83, 7, 315, 747, 63, 354, 2, 450, 747, 63, 354, 430, 267, 291, 14, 1815, 8, 21533, 15587, 464, 17031, 85, 7, 440, 315, 747, 14, 354, 2237, 2728, 291, 14, 3334, 8, 21533, 480, 736, 14, 354, 508, 283, 464, 17031, 85, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 736, 63, 354, 508, 283, 464, 17031, 85, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 1548, 63, 1023, 665, 283, 17, 14, 16, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 1548, 63, 1023, 690, 283, 21, 14, 16, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 1548, 63, 1023, 2356, 283, 21, 14, 16, 7, 2237, 267, 291, 14, 3334, 8, 21533, 480, 1548, 63, 1023, 2695, 283, 17, 14, 16, 7, 2237, 267, 291, 14, 3334, 8, 21533, 21065, 83, 7, 440, 315, 747, 14, 354, 2, 450, 747, 63, 354, 430, 267, 291, 14, 3334, 8, 21533, 15587, 464, 17031, 85, 7, 315, 747, 14, 354, 436, 2366, 63, 1023, 2356, 283, 21, 14, 16, 7, 2237, 27144, 291, 14, 3334, 8, 21533, 15587, 464, 17031, 85, 7, 315, 747, 63, 354, 436, 2366, 63, 1023, 2356, 283, 21, 14, 16, 7, 2237, 258, 2728, 3734, 275, 849, 63, 5418, 342, 267, 3734, 459, 2911, 418, 275, 283, 396, 7, 267, 291, 14, 1815, 8, 21533, 480, 2911, 508, 283, 396, 4662, 3734, 430, 267, 291, 14, 3334, 8, 21533, 480, 2911, 508, 283, 1301, 4662, 3734, 430, 2728, 347, 6534, 63, 354, 547, 837, 288, 862, 26, 355, 15579, 480, 1548, 14, 1023, 508, 283, 2260, 9859, 288, 871, 12746, 26, 355, 986, 288, 587, 26, 355, 746, 2186, 480, 6964, 12746, 531, 2728, 6534, 63, 354, 547, 342, 2728, 347, 6534, 63, 1786, 6825, 837, 288, 862, 26, 355, 15579, 18353, 88, 367, 671, 315, 334, 20, 4641, 531, 288, 871, 12053, 26, 355, 986, 288, 587, 26, 355, 746, 2186, 480, 6964, 12053, 531, 10631, 6534, 63, 1786, 6825, 342, 2728, 5164, 275, 298, 1548, 63, 1023, 508, 283, 21, 4065, 267, 291, 14, 629, 8, 2014, 8, 6242, 2843, 1301, 3108, 5164, 9, 27844, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 ]
elelsee/pycfn-elasticsearch
pycfn_elasticsearch/vendored/requests/packages/urllib3/contrib/ntlmpool.py
1010
4507
""" NTLM authenticating pool, contributed by erikcederstran Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10 """ try: from http.client import HTTPSConnection except ImportError: from httplib import HTTPSConnection from logging import getLogger from ntlm import ntlm from urllib3 import HTTPSConnectionPool log = getLogger(__name__) class NTLMConnectionPool(HTTPSConnectionPool): """ Implements an NTLM authentication version of an urllib3 connection pool """ scheme = 'https' def __init__(self, user, pw, authurl, *args, **kwargs): """ authurl is a random URL on the server that is protected by NTLM. user is the Windows user, probably in the DOMAIN\\username format. pw is the password for the user. """ super(NTLMConnectionPool, self).__init__(*args, **kwargs) self.authurl = authurl self.rawuser = user user_parts = user.split('\\', 1) self.domain = user_parts[0].upper() self.user = user_parts[1] self.pw = pw def _new_conn(self): # Performs the NTLM handshake that secures the connection. The socket # must be kept open while requests are performed. self.num_connections += 1 log.debug('Starting NTLM HTTPS connection no. %d: https://%s%s' % (self.num_connections, self.host, self.authurl)) headers = {} headers['Connection'] = 'Keep-Alive' req_header = 'Authorization' resp_header = 'www-authenticate' conn = HTTPSConnection(host=self.host, port=self.port) # Send negotiation message headers[req_header] = ( 'NTLM %s' % ntlm.create_NTLM_NEGOTIATE_MESSAGE(self.rawuser)) log.debug('Request headers: %s' % headers) conn.request('GET', self.authurl, None, headers) res = conn.getresponse() reshdr = dict(res.getheaders()) log.debug('Response status: %s %s' % (res.status, res.reason)) log.debug('Response headers: %s' % reshdr) log.debug('Response data: %s [...]' % res.read(100)) # Remove the reference to the socket, so that it can not be closed by # the response object (we want to keep the socket open) res.fp = None # Server should respond with a challenge message auth_header_values = reshdr[resp_header].split(', ') auth_header_value = None for s in auth_header_values: if s[:5] == 'NTLM ': auth_header_value = s[5:] if auth_header_value is None: raise Exception('Unexpected %s response header: %s' % (resp_header, reshdr[resp_header])) # Send authentication message ServerChallenge, NegotiateFlags = \ ntlm.parse_NTLM_CHALLENGE_MESSAGE(auth_header_value) auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(ServerChallenge, self.user, self.domain, self.pw, NegotiateFlags) headers[req_header] = 'NTLM %s' % auth_msg log.debug('Request headers: %s' % headers) conn.request('GET', self.authurl, None, headers) res = conn.getresponse() log.debug('Response status: %s %s' % (res.status, res.reason)) log.debug('Response headers: %s' % dict(res.getheaders())) log.debug('Response data: %s [...]' % res.read()[:100]) if res.status != 200: if res.status == 401: raise Exception('Server rejected request: wrong ' 'username or password') raise Exception('Wrong server response: %s %s' % (res.status, res.reason)) res.fp = None log.debug('Connection established') return conn def urlopen(self, method, url, body=None, headers=None, retries=3, redirect=True, assert_same_host=True): if headers is None: headers = {} headers['Connection'] = 'Keep-Alive' return super(NTLMConnectionPool, self).urlopen(method, url, body, headers, retries, redirect, assert_same_host)
apache-2.0
[ 624, 199, 46, 25112, 28532, 1958, 4203, 12, 406, 24855, 701, 9266, 3258, 301, 424, 495, 290, 199, 199, 17106, 327, 709, 12, 1937, 26, 1455, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 4078, 19, 15, 10115, 15, 5506, 31, 344, 29, 709, 199, 624, 199, 199, 893, 26, 272, 687, 1455, 14, 1258, 492, 14147, 3225, 199, 2590, 3545, 26, 272, 687, 8809, 492, 14147, 3225, 199, 504, 2050, 492, 28138, 199, 504, 302, 5019, 77, 492, 302, 5019, 77, 199, 199, 504, 4011, 19, 492, 14147, 23929, 421, 199, 793, 275, 28138, 3460, 354, 3368, 421, 199, 533, 653, 25112, 23929, 8, 14921, 23929, 304, 272, 408, 272, 24664, 376, 653, 25112, 6299, 1015, 402, 376, 4011, 19, 1950, 4203, 272, 408, 339, 5687, 275, 283, 2859, 7, 339, 347, 636, 826, 721, 277, 12, 922, 12, 19206, 12, 1790, 633, 12, 627, 589, 12, 1011, 958, 304, 267, 408, 267, 1790, 633, 365, 282, 2196, 2851, 641, 314, 1654, 626, 365, 17819, 701, 653, 25112, 14, 267, 922, 365, 314, 5417, 922, 12, 8646, 315, 314, 15265, 1103, 2473, 1475, 14, 267, 19206, 365, 314, 2505, 367, 314, 922, 14, 267, 408, 267, 1613, 8, 46, 25112, 23929, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 1178, 633, 275, 1790, 633, 267, 291, 14, 1773, 751, 275, 922, 267, 922, 63, 4181, 275, 922, 14, 1294, 20786, 413, 9, 267, 291, 14, 2261, 275, 922, 63, 4181, 59, 16, 1055, 4142, 342, 267, 291, 14, 751, 275, 922, 63, 4181, 59, 17, 61, 267, 291, 14, 8796, 275, 19206, 339, 347, 485, 1222, 63, 1631, 8, 277, 304, 267, 327, 29822, 314, 653, 25112, 14305, 626, 6513, 1482, 314, 1950, 14, 710, 2838, 267, 327, 1471, 506, 16204, 1551, 1830, 4145, 787, 10585, 14, 267, 291, 14, 1507, 63, 7995, 847, 413, 267, 943, 14, 1757, 360, 14139, 653, 25112, 14147, 1950, 949, 14, 450, 68, 26, 4178, 13827, 83, 5, 83, 7, 450, 2116, 334, 277, 14, 1507, 63, 7995, 12, 291, 14, 1102, 12, 291, 14, 1178, 633, 430, 398, 2323, 275, 1052, 267, 2323, 459, 3225, 418, 275, 283, 18567, 13, 23692, 7, 267, 2648, 63, 1291, 275, 283, 11626, 7, 267, 3085, 63, 1291, 275, 283, 1544, 13, 13975, 7, 398, 2557, 275, 14147, 3225, 8, 1102, 29, 277, 14, 1102, 12, 1844, 29, 277, 14, 719, 9, 398, 327, 10217, 29184, 425, 1245, 267, 2323, 59, 2103, 63, 1291, 61, 275, 334, 288, 283, 46, 25112, 450, 83, 7, 450, 302, 5019, 77, 14, 981, 63, 46, 25112, 63, 31254, 1387, 41, 1951, 63, 8272, 8, 277, 14, 1773, 751, 430, 267, 943, 14, 1757, 360, 2017, 2323, 26, 450, 83, 7, 450, 2323, 9, 267, 2557, 14, 1069, 360, 2970, 297, 291, 14, 1178, 633, 12, 488, 12, 2323, 9, 267, 522, 275, 2557, 14, 25006, 342, 267, 522, 11244, 275, 1211, 8, 470, 14, 19958, 83, 1012, 267, 943, 14, 1757, 360, 2364, 2004, 26, 450, 83, 450, 83, 7, 450, 334, 470, 14, 1205, 12, 522, 14, 5764, 430, 267, 943, 14, 1757, 360, 2364, 2323, 26, 450, 83, 7, 450, 522, 11244, 9, 267, 943, 14, 1757, 360, 2364, 666, 26, 450, 83, 359, 1396, 6616, 450, 522, 14, 739, 8, 1960, 430, 398, 327, 5852, 314, 3659, 370, 314, 2838, 12, 880, 626, 652, 883, 440, 506, 6876, 701, 267, 327, 314, 1177, 909, 334, 1129, 2934, 370, 4215, 314, 2838, 1551, 9, 267, 522, 14, 3997, 275, 488, 398, 327, 7146, 1077, 22722, 543, 282, 14929, 1245, 267, 1790, 63, 1291, 63, 1459, 275, 522, 11244, 59, 4518, 63, 1291, 1055, 1294, 5102, 5320, 267, 1790, 63, 1291, 63, 585, 275, 488, 267, 367, 308, 315, 1790, 63, 1291, 63, 1459, 26, 288, 340, 308, 1491, 21, 61, 508, 283, 46, 25112, 7596, 355, 1790, 63, 1291, 63, 585, 275, 308, 59, 21, 2938, 267, 340, 1790, 63, 1291, 63, 585, 365, 488, 26, 288, 746, 2186, 360, 8708, 450, 83, 1177, 1406, 26, 450, 83, 7, 450, 1169, 334, 4518, 63, 1291, 12, 522, 11244, 59, 4518, 63, 1291, 2459, 398, 327, 10217, 6299, 1245, 267, 7146, 30531, 12, 5612, 14727, 323, 6381, 275, 971, 288, 302, 5019, 77, 14, 1122, 63, 46, 25112, 63, 1244, 1761, 742, 4962, 63, 8272, 8, 1178, 63, 1291, 63, 585, 9, 267, 1790, 63, 1328, 275, 302, 5019, 77, 14, 981, 63, 46, 25112, 63, 22923, 1951, 63, 8272, 8, 3120, 30531, 12, 12740, 291, 14, 751, 12, 12740, 291, 14, 2261, 12, 12740, 291, 14, 8796, 12, 12740, 5612, 14727, 323, 6381, 9, 267, 2323, 59, 2103, 63, 1291, 61, 275, 283, 46, 25112, 450, 83, 7, 450, 1790, 63, 1328, 267, 943, 14, 1757, 360, 2017, 2323, 26, 450, 83, 7, 450, 2323, 9, 267, 2557, 14, 1069, 360, 2970, 297, 291, 14, 1178, 633, 12, 488, 12, 2323, 9, 267, 522, 275, 2557, 14, 25006, 342, 267, 943, 14, 1757, 360, 2364, 2004, 26, 450, 83, 450, 83, 7, 450, 334, 470, 14, 1205, 12, 522, 14, 5764, 430, 267, 943, 14, 1757, 360, 2364, 2323, 26, 450, 83, 7, 450, 1211, 8, 470, 14, 19958, 83, 4059, 267, 943, 14, 1757, 360, 2364, 666, 26, 450, 83, 359, 1396, 6616, 450, 522, 14, 739, 20523, 1960, 566, 267, 340, 522, 14, 1205, 1137, 1926, 26, 288, 340, 522, 14, 1205, 508, 13952, 26, 355, 746, 2186, 360, 3120, 18935, 1056, 26, 6835, 283, 1816, 283, 2473, 503, 2505, 358, 288, 746, 2186, 360, 14858, 1654, 1177, 26, 450, 83, 450, 83, 7, 450, 1169, 334, 470, 14, 1205, 12, 522, 14, 5764, 430, 398, 522, 14, 3997, 275, 488, 267, 943, 14, 1757, 360, 3225, 23594, 358, 267, 372, 2557, 339, 347, 18279, 8, 277, 12, 1083, 12, 1166, 12, 2396, 29, 403, 12, 2323, 29, 403, 12, 10086, 29, 19, 12, 355, 4660, 29, 549, 12, 702, 63, 7191, 63, 1102, 29, 549, 304, 267, 340, 2323, 365, 488, 26, 288, 2323, 275, 1052, 267, 2323, 459, 3225, 418, 275, 283, 18567, 13, 23692, 7, 267, 372, 1613, 8, 46 ]
[ 199, 46, 25112, 28532, 1958, 4203, 12, 406, 24855, 701, 9266, 3258, 301, 424, 495, 290, 199, 199, 17106, 327, 709, 12, 1937, 26, 1455, 921, 600, 14, 3098, 14, 957, 15, 80, 15, 4078, 19, 15, 10115, 15, 5506, 31, 344, 29, 709, 199, 624, 199, 199, 893, 26, 272, 687, 1455, 14, 1258, 492, 14147, 3225, 199, 2590, 3545, 26, 272, 687, 8809, 492, 14147, 3225, 199, 504, 2050, 492, 28138, 199, 504, 302, 5019, 77, 492, 302, 5019, 77, 199, 199, 504, 4011, 19, 492, 14147, 23929, 421, 199, 793, 275, 28138, 3460, 354, 3368, 421, 199, 533, 653, 25112, 23929, 8, 14921, 23929, 304, 272, 408, 272, 24664, 376, 653, 25112, 6299, 1015, 402, 376, 4011, 19, 1950, 4203, 272, 408, 339, 5687, 275, 283, 2859, 7, 339, 347, 636, 826, 721, 277, 12, 922, 12, 19206, 12, 1790, 633, 12, 627, 589, 12, 1011, 958, 304, 267, 408, 267, 1790, 633, 365, 282, 2196, 2851, 641, 314, 1654, 626, 365, 17819, 701, 653, 25112, 14, 267, 922, 365, 314, 5417, 922, 12, 8646, 315, 314, 15265, 1103, 2473, 1475, 14, 267, 19206, 365, 314, 2505, 367, 314, 922, 14, 267, 408, 267, 1613, 8, 46, 25112, 23929, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 14, 1178, 633, 275, 1790, 633, 267, 291, 14, 1773, 751, 275, 922, 267, 922, 63, 4181, 275, 922, 14, 1294, 20786, 413, 9, 267, 291, 14, 2261, 275, 922, 63, 4181, 59, 16, 1055, 4142, 342, 267, 291, 14, 751, 275, 922, 63, 4181, 59, 17, 61, 267, 291, 14, 8796, 275, 19206, 339, 347, 485, 1222, 63, 1631, 8, 277, 304, 267, 327, 29822, 314, 653, 25112, 14305, 626, 6513, 1482, 314, 1950, 14, 710, 2838, 267, 327, 1471, 506, 16204, 1551, 1830, 4145, 787, 10585, 14, 267, 291, 14, 1507, 63, 7995, 847, 413, 267, 943, 14, 1757, 360, 14139, 653, 25112, 14147, 1950, 949, 14, 450, 68, 26, 4178, 13827, 83, 5, 83, 7, 450, 2116, 334, 277, 14, 1507, 63, 7995, 12, 291, 14, 1102, 12, 291, 14, 1178, 633, 430, 398, 2323, 275, 1052, 267, 2323, 459, 3225, 418, 275, 283, 18567, 13, 23692, 7, 267, 2648, 63, 1291, 275, 283, 11626, 7, 267, 3085, 63, 1291, 275, 283, 1544, 13, 13975, 7, 398, 2557, 275, 14147, 3225, 8, 1102, 29, 277, 14, 1102, 12, 1844, 29, 277, 14, 719, 9, 398, 327, 10217, 29184, 425, 1245, 267, 2323, 59, 2103, 63, 1291, 61, 275, 334, 288, 283, 46, 25112, 450, 83, 7, 450, 302, 5019, 77, 14, 981, 63, 46, 25112, 63, 31254, 1387, 41, 1951, 63, 8272, 8, 277, 14, 1773, 751, 430, 267, 943, 14, 1757, 360, 2017, 2323, 26, 450, 83, 7, 450, 2323, 9, 267, 2557, 14, 1069, 360, 2970, 297, 291, 14, 1178, 633, 12, 488, 12, 2323, 9, 267, 522, 275, 2557, 14, 25006, 342, 267, 522, 11244, 275, 1211, 8, 470, 14, 19958, 83, 1012, 267, 943, 14, 1757, 360, 2364, 2004, 26, 450, 83, 450, 83, 7, 450, 334, 470, 14, 1205, 12, 522, 14, 5764, 430, 267, 943, 14, 1757, 360, 2364, 2323, 26, 450, 83, 7, 450, 522, 11244, 9, 267, 943, 14, 1757, 360, 2364, 666, 26, 450, 83, 359, 1396, 6616, 450, 522, 14, 739, 8, 1960, 430, 398, 327, 5852, 314, 3659, 370, 314, 2838, 12, 880, 626, 652, 883, 440, 506, 6876, 701, 267, 327, 314, 1177, 909, 334, 1129, 2934, 370, 4215, 314, 2838, 1551, 9, 267, 522, 14, 3997, 275, 488, 398, 327, 7146, 1077, 22722, 543, 282, 14929, 1245, 267, 1790, 63, 1291, 63, 1459, 275, 522, 11244, 59, 4518, 63, 1291, 1055, 1294, 5102, 5320, 267, 1790, 63, 1291, 63, 585, 275, 488, 267, 367, 308, 315, 1790, 63, 1291, 63, 1459, 26, 288, 340, 308, 1491, 21, 61, 508, 283, 46, 25112, 7596, 355, 1790, 63, 1291, 63, 585, 275, 308, 59, 21, 2938, 267, 340, 1790, 63, 1291, 63, 585, 365, 488, 26, 288, 746, 2186, 360, 8708, 450, 83, 1177, 1406, 26, 450, 83, 7, 450, 1169, 334, 4518, 63, 1291, 12, 522, 11244, 59, 4518, 63, 1291, 2459, 398, 327, 10217, 6299, 1245, 267, 7146, 30531, 12, 5612, 14727, 323, 6381, 275, 971, 288, 302, 5019, 77, 14, 1122, 63, 46, 25112, 63, 1244, 1761, 742, 4962, 63, 8272, 8, 1178, 63, 1291, 63, 585, 9, 267, 1790, 63, 1328, 275, 302, 5019, 77, 14, 981, 63, 46, 25112, 63, 22923, 1951, 63, 8272, 8, 3120, 30531, 12, 12740, 291, 14, 751, 12, 12740, 291, 14, 2261, 12, 12740, 291, 14, 8796, 12, 12740, 5612, 14727, 323, 6381, 9, 267, 2323, 59, 2103, 63, 1291, 61, 275, 283, 46, 25112, 450, 83, 7, 450, 1790, 63, 1328, 267, 943, 14, 1757, 360, 2017, 2323, 26, 450, 83, 7, 450, 2323, 9, 267, 2557, 14, 1069, 360, 2970, 297, 291, 14, 1178, 633, 12, 488, 12, 2323, 9, 267, 522, 275, 2557, 14, 25006, 342, 267, 943, 14, 1757, 360, 2364, 2004, 26, 450, 83, 450, 83, 7, 450, 334, 470, 14, 1205, 12, 522, 14, 5764, 430, 267, 943, 14, 1757, 360, 2364, 2323, 26, 450, 83, 7, 450, 1211, 8, 470, 14, 19958, 83, 4059, 267, 943, 14, 1757, 360, 2364, 666, 26, 450, 83, 359, 1396, 6616, 450, 522, 14, 739, 20523, 1960, 566, 267, 340, 522, 14, 1205, 1137, 1926, 26, 288, 340, 522, 14, 1205, 508, 13952, 26, 355, 746, 2186, 360, 3120, 18935, 1056, 26, 6835, 283, 1816, 283, 2473, 503, 2505, 358, 288, 746, 2186, 360, 14858, 1654, 1177, 26, 450, 83, 450, 83, 7, 450, 1169, 334, 470, 14, 1205, 12, 522, 14, 5764, 430, 398, 522, 14, 3997, 275, 488, 267, 943, 14, 1757, 360, 3225, 23594, 358, 267, 372, 2557, 339, 347, 18279, 8, 277, 12, 1083, 12, 1166, 12, 2396, 29, 403, 12, 2323, 29, 403, 12, 10086, 29, 19, 12, 355, 4660, 29, 549, 12, 702, 63, 7191, 63, 1102, 29, 549, 304, 267, 340, 2323, 365, 488, 26, 288, 2323, 275, 1052, 267, 2323, 459, 3225, 418, 275, 283, 18567, 13, 23692, 7, 267, 372, 1613, 8, 46, 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 ]
harshita-gupta/Harvard-FRSEM-Catalog-2016-17
flask/lib/python2.7/site-packages/sqlalchemy/sql/schema.py
5
147636
# sql/schema.py # Copyright (C) 2005-2016 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 """The schema module provides the building blocks for database metadata. Each element within this module describes a database entity which can be created and dropped, or is otherwise part of such an entity. Examples include tables, columns, sequences, and indexes. All entities are subclasses of :class:`~sqlalchemy.schema.SchemaItem`, and as defined in this module they are intended to be agnostic of any vendor-specific constructs. A collection of entities are grouped into a unit called :class:`~sqlalchemy.schema.MetaData`. MetaData serves as a logical grouping of schema elements, and can also be associated with an actual database connection such that operations involving the contained elements can contact the database as needed. Two of the elements here also build upon their "syntactic" counterparts, which are defined in :class:`~sqlalchemy.sql.expression.`, specifically :class:`~sqlalchemy.schema.Table` and :class:`~sqlalchemy.schema.Column`. Since these objects are part of the SQL expression language, they are usable as components in SQL expressions. """ from __future__ import absolute_import import inspect from .. import exc, util, event, inspection from .base import SchemaEventTarget, DialectKWArgs from . import visitors from . import type_api from .base import _bind_or_error, ColumnCollection from .elements import ClauseElement, ColumnClause, _truncated_label, \ _as_truncated, TextClause, _literal_as_text,\ ColumnElement, _find_columns, quoted_name from .selectable import TableClause import collections import sqlalchemy from . import ddl import types RETAIN_SCHEMA = util.symbol('retain_schema') BLANK_SCHEMA = util.symbol( 'blank_schema', """Symbol indicating that a :class:`.Table` or :class:`.Sequence` should have 'None' for its schema, even if the parent :class:`.MetaData` has specified a schema. .. versionadded:: 1.0.14 """ ) def _get_table_key(name, schema): if schema is None: return name else: return schema + "." + name @inspection._self_inspects class SchemaItem(SchemaEventTarget, visitors.Visitable): """Base class for items that define a database schema.""" __visit_name__ = 'schema_item' def _execute_on_connection(self, connection, multiparams, params): return connection._execute_default(self, multiparams, params) def _init_items(self, *args): """Initialize the list of child items for this SchemaItem.""" for item in args: if item is not None: item._set_parent_with_dispatch(self) def get_children(self, **kwargs): """used to allow SchemaVisitor access""" return [] def __repr__(self): return util.generic_repr(self, omit_kwarg=['info']) @property @util.deprecated('0.9', 'Use ``<obj>.name.quote``') def quote(self): """Return the value of the ``quote`` flag passed to this schema object, for those schema items which have a ``name`` field. """ return self.name.quote @util.memoized_property def info(self): """Info dictionary associated with the object, allowing user-defined data to be associated with this :class:`.SchemaItem`. The dictionary is automatically generated when first accessed. It can also be specified in the constructor of some objects, such as :class:`.Table` and :class:`.Column`. """ return {} def _schema_item_copy(self, schema_item): if 'info' in self.__dict__: schema_item.info = self.info.copy() schema_item.dispatch._update(self.dispatch) return schema_item class Table(DialectKWArgs, SchemaItem, TableClause): """Represent a table in a database. e.g.:: mytable = Table("mytable", metadata, Column('mytable_id', Integer, primary_key=True), Column('value', String(50)) ) The :class:`.Table` object constructs a unique instance of itself based on its name and optional schema name within the given :class:`.MetaData` object. Calling the :class:`.Table` constructor with the same name and same :class:`.MetaData` argument a second time will return the *same* :class:`.Table` object - in this way the :class:`.Table` constructor acts as a registry function. .. seealso:: :ref:`metadata_describing` - Introduction to database metadata Constructor arguments are as follows: :param name: The name of this table as represented in the database. The table name, along with the value of the ``schema`` parameter, forms a key which uniquely identifies this :class:`.Table` within the owning :class:`.MetaData` collection. Additional calls to :class:`.Table` with the same name, metadata, and schema name will return the same :class:`.Table` object. Names which contain no upper case characters will be treated as case insensitive names, and will not be quoted unless they are a reserved word or contain special characters. A name with any number of upper case characters is considered to be case sensitive, and will be sent as quoted. To enable unconditional quoting for the table name, specify the flag ``quote=True`` to the constructor, or use the :class:`.quoted_name` construct to specify the name. :param metadata: a :class:`.MetaData` object which will contain this table. The metadata is used as a point of association of this table with other tables which are referenced via foreign key. It also may be used to associate this table with a particular :class:`.Connectable`. :param \*args: Additional positional arguments are used primarily to add the list of :class:`.Column` objects contained within this table. Similar to the style of a CREATE TABLE statement, other :class:`.SchemaItem` constructs may be added here, including :class:`.PrimaryKeyConstraint`, and :class:`.ForeignKeyConstraint`. :param autoload: Defaults to False, unless :paramref:`.Table.autoload_with` is set in which case it defaults to True; :class:`.Column` objects for this table should be reflected from the database, possibly augmenting or replacing existing :class:`.Column` objects that were expicitly specified. .. versionchanged:: 1.0.0 setting the :paramref:`.Table.autoload_with` parameter implies that :paramref:`.Table.autoload` will default to True. .. seealso:: :ref:`metadata_reflection_toplevel` :param autoload_replace: Defaults to ``True``; when using :paramref:`.Table.autoload` in conjunction with :paramref:`.Table.extend_existing`, indicates that :class:`.Column` objects present in the already-existing :class:`.Table` object should be replaced with columns of the same name retrieved from the autoload process. When ``False``, columns already present under existing names will be omitted from the reflection process. Note that this setting does not impact :class:`.Column` objects specified programmatically within the call to :class:`.Table` that also is autoloading; those :class:`.Column` objects will always replace existing columns of the same name when :paramref:`.Table.extend_existing` is ``True``. .. versionadded:: 0.7.5 .. seealso:: :paramref:`.Table.autoload` :paramref:`.Table.extend_existing` :param autoload_with: An :class:`.Engine` or :class:`.Connection` object with which this :class:`.Table` object will be reflected; when set to a non-None value, it implies that :paramref:`.Table.autoload` is ``True``. If left unset, but :paramref:`.Table.autoload` is explicitly set to ``True``, an autoload operation will attempt to proceed by locating an :class:`.Engine` or :class:`.Connection` bound to the underlying :class:`.MetaData` object. .. seealso:: :paramref:`.Table.autoload` :param extend_existing: When ``True``, indicates that if this :class:`.Table` is already present in the given :class:`.MetaData`, apply further arguments within the constructor to the existing :class:`.Table`. If :paramref:`.Table.extend_existing` or :paramref:`.Table.keep_existing` are not set, and the given name of the new :class:`.Table` refers to a :class:`.Table` that is already present in the target :class:`.MetaData` collection, and this :class:`.Table` specifies additional columns or other constructs or flags that modify the table's state, an error is raised. The purpose of these two mutually-exclusive flags is to specify what action should be taken when a :class:`.Table` is specified that matches an existing :class:`.Table`, yet specifies additional constructs. :paramref:`.Table.extend_existing` will also work in conjunction with :paramref:`.Table.autoload` to run a new reflection operation against the database, even if a :class:`.Table` of the same name is already present in the target :class:`.MetaData`; newly reflected :class:`.Column` objects and other options will be added into the state of the :class:`.Table`, potentially overwriting existing columns and options of the same name. .. versionchanged:: 0.7.4 :paramref:`.Table.extend_existing` will invoke a new reflection operation when combined with :paramref:`.Table.autoload` set to True. As is always the case with :paramref:`.Table.autoload`, :class:`.Column` objects can be specified in the same :class:`.Table` constructor, which will take precedence. Below, the existing table ``mytable`` will be augmented with :class:`.Column` objects both reflected from the database, as well as the given :class:`.Column` named "y":: Table("mytable", metadata, Column('y', Integer), extend_existing=True, autoload=True, autoload_with=engine ) .. seealso:: :paramref:`.Table.autoload` :paramref:`.Table.autoload_replace` :paramref:`.Table.keep_existing` :param implicit_returning: True by default - indicates that RETURNING can be used by default to fetch newly inserted primary key values, for backends which support this. Note that create_engine() also provides an implicit_returning flag. :param include_columns: A list of strings indicating a subset of columns to be loaded via the ``autoload`` operation; table columns who aren't present in this list will not be represented on the resulting ``Table`` object. Defaults to ``None`` which indicates all columns should be reflected. :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. :param keep_existing: When ``True``, indicates that if this Table is already present in the given :class:`.MetaData`, ignore further arguments within the constructor to the existing :class:`.Table`, and return the :class:`.Table` object as originally created. This is to allow a function that wishes to define a new :class:`.Table` on first call, but on subsequent calls will return the same :class:`.Table`, without any of the declarations (particularly constraints) being applied a second time. If :paramref:`.Table.extend_existing` or :paramref:`.Table.keep_existing` are not set, and the given name of the new :class:`.Table` refers to a :class:`.Table` that is already present in the target :class:`.MetaData` collection, and this :class:`.Table` specifies additional columns or other constructs or flags that modify the table's state, an error is raised. The purpose of these two mutually-exclusive flags is to specify what action should be taken when a :class:`.Table` is specified that matches an existing :class:`.Table`, yet specifies additional constructs. .. seealso:: :paramref:`.Table.extend_existing` :param listeners: A list of tuples of the form ``(<eventname>, <fn>)`` which will be passed to :func:`.event.listen` upon construction. This alternate hook to :func:`.event.listen` allows the establishment of a listener function specific to this :class:`.Table` before the "autoload" process begins. Particularly useful for the :meth:`.DDLEvents.column_reflect` event:: def listen_for_reflect(table, column_info): "handle the column reflection event" # ... t = Table( 'sometable', autoload=True, listeners=[ ('column_reflect', listen_for_reflect) ]) :param mustexist: When ``True``, indicates that this Table must already be present in the given :class:`.MetaData` collection, else an exception is raised. :param prefixes: A list of strings to insert after CREATE in the CREATE TABLE statement. They will be separated by spaces. :param quote: Force quoting of this table's name on or off, corresponding to ``True`` or ``False``. When left at its default of ``None``, the column identifier will be quoted according to whether the name is case sensitive (identifiers with at least one upper case character are treated as case sensitive), or if it's a reserved word. This flag is only needed to force quoting of a reserved word which is not known by the SQLAlchemy dialect. :param quote_schema: same as 'quote' but applies to the schema identifier. :param schema: The schema name for this table, which is required if the table resides in a schema other than the default selected schema for the engine's database connection. Defaults to ``None``. If the owning :class:`.MetaData` of this :class:`.Table` specifies its own :paramref:`.MetaData.schema` parameter, then that schema name will be applied to this :class:`.Table` if the schema parameter here is set to ``None``. To set a blank schema name on a :class:`.Table` that would otherwise use the schema set on the owning :class:`.MetaData`, specify the special symbol :attr:`.BLANK_SCHEMA`. .. versionadded:: 1.0.14 Added the :attr:`.BLANK_SCHEMA` symbol to allow a :class:`.Table` to have a blank schema name even when the parent :class:`.MetaData` specifies :paramref:`.MetaData.schema`. The quoting rules for the schema name are the same as those for the ``name`` parameter, in that quoting is applied for reserved words or case-sensitive names; to enable unconditional quoting for the schema name, specify the flag ``quote_schema=True`` to the constructor, or use the :class:`.quoted_name` construct to specify the name. :param useexisting: Deprecated. Use :paramref:`.Table.extend_existing`. :param \**kw: Additional keyword arguments not mentioned above are dialect specific, and passed in the form ``<dialectname>_<argname>``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. """ __visit_name__ = 'table' def __new__(cls, *args, **kw): if not args: # python3k pickle seems to call this return object.__new__(cls) try: name, metadata, args = args[0], args[1], args[2:] except IndexError: raise TypeError("Table() takes at least two arguments") schema = kw.get('schema', None) if schema is None: schema = metadata.schema elif schema is BLANK_SCHEMA: schema = None keep_existing = kw.pop('keep_existing', False) extend_existing = kw.pop('extend_existing', False) if 'useexisting' in kw: msg = "useexisting is deprecated. Use extend_existing." util.warn_deprecated(msg) if extend_existing: msg = "useexisting is synonymous with extend_existing." raise exc.ArgumentError(msg) extend_existing = kw.pop('useexisting', False) if keep_existing and extend_existing: msg = "keep_existing and extend_existing are mutually exclusive." raise exc.ArgumentError(msg) mustexist = kw.pop('mustexist', False) key = _get_table_key(name, schema) if key in metadata.tables: if not keep_existing and not extend_existing and bool(args): raise exc.InvalidRequestError( "Table '%s' is already defined for this MetaData " "instance. Specify 'extend_existing=True' " "to redefine " "options and columns on an " "existing Table object." % key) table = metadata.tables[key] if extend_existing: table._init_existing(*args, **kw) return table else: if mustexist: raise exc.InvalidRequestError( "Table '%s' not defined" % (key)) table = object.__new__(cls) table.dispatch.before_parent_attach(table, metadata) metadata._add_table(name, schema, table) try: table._init(name, metadata, *args, **kw) table.dispatch.after_parent_attach(table, metadata) return table except: with util.safe_reraise(): metadata._remove_table(name, schema) @property @util.deprecated('0.9', 'Use ``table.schema.quote``') def quote_schema(self): """Return the value of the ``quote_schema`` flag passed to this :class:`.Table`. """ return self.schema.quote def __init__(self, *args, **kw): """Constructor for :class:`~.schema.Table`. This method is a no-op. See the top-level documentation for :class:`~.schema.Table` for constructor arguments. """ # __init__ is overridden to prevent __new__ from # calling the superclass constructor. def _init(self, name, metadata, *args, **kwargs): super(Table, self).__init__( quoted_name(name, kwargs.pop('quote', None))) self.metadata = metadata self.schema = kwargs.pop('schema', None) if self.schema is None: self.schema = metadata.schema elif self.schema is BLANK_SCHEMA: self.schema = None else: quote_schema = kwargs.pop('quote_schema', None) self.schema = quoted_name(self.schema, quote_schema) self.indexes = set() self.constraints = set() self._columns = ColumnCollection() PrimaryKeyConstraint()._set_parent_with_dispatch(self) self.foreign_keys = set() self._extra_dependencies = set() if self.schema is not None: self.fullname = "%s.%s" % (self.schema, self.name) else: self.fullname = self.name autoload_with = kwargs.pop('autoload_with', None) autoload = kwargs.pop('autoload', autoload_with is not None) # this argument is only used with _init_existing() kwargs.pop('autoload_replace', True) include_columns = kwargs.pop('include_columns', None) self.implicit_returning = kwargs.pop('implicit_returning', True) if 'info' in kwargs: self.info = kwargs.pop('info') if 'listeners' in kwargs: listeners = kwargs.pop('listeners') for evt, fn in listeners: event.listen(self, evt, fn) self._prefixes = kwargs.pop('prefixes', []) self._extra_kwargs(**kwargs) # load column definitions from the database if 'autoload' is defined # we do it after the table is in the singleton dictionary to support # circular foreign keys if autoload: self._autoload(metadata, autoload_with, include_columns) # initialize all the column, etc. objects. done after reflection to # allow user-overrides self._init_items(*args) def _autoload(self, metadata, autoload_with, include_columns, exclude_columns=()): if autoload_with: autoload_with.run_callable( autoload_with.dialect.reflecttable, self, include_columns, exclude_columns ) else: bind = _bind_or_error( metadata, msg="No engine is bound to this Table's MetaData. " "Pass an engine to the Table via " "autoload_with=<someengine>, " "or associate the MetaData with an engine via " "metadata.bind=<someengine>") bind.run_callable( bind.dialect.reflecttable, self, include_columns, exclude_columns ) @property def _sorted_constraints(self): """Return the set of constraints as a list, sorted by creation order. """ return sorted(self.constraints, key=lambda c: c._creation_order) @property def foreign_key_constraints(self): """:class:`.ForeignKeyConstraint` objects referred to by this :class:`.Table`. This list is produced from the collection of :class:`.ForeignKey` objects currently associated. .. versionadded:: 1.0.0 """ return set(fkc.constraint for fkc in self.foreign_keys) def _init_existing(self, *args, **kwargs): autoload_with = kwargs.pop('autoload_with', None) autoload = kwargs.pop('autoload', autoload_with is not None) autoload_replace = kwargs.pop('autoload_replace', True) schema = kwargs.pop('schema', None) if schema and schema != self.schema: raise exc.ArgumentError( "Can't change schema of existing table from '%s' to '%s'", (self.schema, schema)) include_columns = kwargs.pop('include_columns', None) if include_columns is not None: for c in self.c: if c.name not in include_columns: self._columns.remove(c) for key in ('quote', 'quote_schema'): if key in kwargs: raise exc.ArgumentError( "Can't redefine 'quote' or 'quote_schema' arguments") if 'info' in kwargs: self.info = kwargs.pop('info') if autoload: if not autoload_replace: exclude_columns = [c.name for c in self.c] else: exclude_columns = () self._autoload( self.metadata, autoload_with, include_columns, exclude_columns) self._extra_kwargs(**kwargs) self._init_items(*args) def _extra_kwargs(self, **kwargs): self._validate_dialect_kwargs(kwargs) def _init_collections(self): pass @util.memoized_property def _autoincrement_column(self): for col in self.primary_key: if (col.autoincrement and col.type._type_affinity is not None and issubclass(col.type._type_affinity, type_api.INTEGERTYPE._type_affinity) and (not col.foreign_keys or col.autoincrement == 'ignore_fk') and isinstance(col.default, (type(None), Sequence)) and (col.server_default is None or col.server_default.reflected)): return col @property def key(self): """Return the 'key' for this :class:`.Table`. This value is used as the dictionary key within the :attr:`.MetaData.tables` collection. It is typically the same as that of :attr:`.Table.name` for a table with no :attr:`.Table.schema` set; otherwise it is typically of the form ``schemaname.tablename``. """ return _get_table_key(self.name, self.schema) def __repr__(self): return "Table(%s)" % ', '.join( [repr(self.name)] + [repr(self.metadata)] + [repr(x) for x in self.columns] + ["%s=%s" % (k, repr(getattr(self, k))) for k in ['schema']]) def __str__(self): return _get_table_key(self.description, self.schema) @property def bind(self): """Return the connectable associated with this Table.""" return self.metadata and self.metadata.bind or None def add_is_dependent_on(self, table): """Add a 'dependency' for this Table. This is another Table object which must be created first before this one can, or dropped after this one. Usually, dependencies between tables are determined via ForeignKey objects. However, for other situations that create dependencies outside of foreign keys (rules, inheriting), this method can manually establish such a link. """ self._extra_dependencies.add(table) def append_column(self, column): """Append a :class:`~.schema.Column` to this :class:`~.schema.Table`. The "key" of the newly added :class:`~.schema.Column`, i.e. the value of its ``.key`` attribute, will then be available in the ``.c`` collection of this :class:`~.schema.Table`, and the column definition will be included in any CREATE TABLE, SELECT, UPDATE, etc. statements generated from this :class:`~.schema.Table` construct. Note that this does **not** change the definition of the table as it exists within any underlying database, assuming that table has already been created in the database. Relational databases support the addition of columns to existing tables using the SQL ALTER command, which would need to be emitted for an already-existing table that doesn't contain the newly added column. """ column._set_parent_with_dispatch(self) def append_constraint(self, constraint): """Append a :class:`~.schema.Constraint` to this :class:`~.schema.Table`. This has the effect of the constraint being included in any future CREATE TABLE statement, assuming specific DDL creation events have not been associated with the given :class:`~.schema.Constraint` object. Note that this does **not** produce the constraint within the relational database automatically, for a table that already exists in the database. To add a constraint to an existing relational database table, the SQL ALTER command must be used. SQLAlchemy also provides the :class:`.AddConstraint` construct which can produce this SQL when invoked as an executable clause. """ constraint._set_parent_with_dispatch(self) def append_ddl_listener(self, event_name, listener): """Append a DDL event listener to this ``Table``. .. deprecated:: 0.7 See :class:`.DDLEvents`. """ def adapt_listener(target, connection, **kw): listener(event_name, target, connection) event.listen(self, "" + event_name.replace('-', '_'), adapt_listener) def _set_parent(self, metadata): metadata._add_table(self.name, self.schema, self) self.metadata = metadata def get_children(self, column_collections=True, schema_visitor=False, **kw): if not schema_visitor: return TableClause.get_children( self, column_collections=column_collections, **kw) else: if column_collections: return list(self.columns) else: return [] def exists(self, bind=None): """Return True if this table exists.""" if bind is None: bind = _bind_or_error(self) return bind.run_callable(bind.dialect.has_table, self.name, schema=self.schema) def create(self, bind=None, checkfirst=False): """Issue a ``CREATE`` statement for this :class:`.Table`, using the given :class:`.Connectable` for connectivity. .. seealso:: :meth:`.MetaData.create_all`. """ if bind is None: bind = _bind_or_error(self) bind._run_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst) def drop(self, bind=None, checkfirst=False): """Issue a ``DROP`` statement for this :class:`.Table`, using the given :class:`.Connectable` for connectivity. .. seealso:: :meth:`.MetaData.drop_all`. """ if bind is None: bind = _bind_or_error(self) bind._run_visitor(ddl.SchemaDropper, self, checkfirst=checkfirst) def tometadata(self, metadata, schema=RETAIN_SCHEMA, referred_schema_fn=None, name=None): """Return a copy of this :class:`.Table` associated with a different :class:`.MetaData`. E.g.:: m1 = MetaData() user = Table('user', m1, Column('id', Integer, priamry_key=True)) m2 = MetaData() user_copy = user.tometadata(m2) :param metadata: Target :class:`.MetaData` object, into which the new :class:`.Table` object will be created. :param schema: optional string name indicating the target schema. Defaults to the special symbol :attr:`.RETAIN_SCHEMA` which indicates that no change to the schema name should be made in the new :class:`.Table`. If set to a string name, the new :class:`.Table` will have this new name as the ``.schema``. If set to ``None``, the schema will be set to that of the schema set on the target :class:`.MetaData`, which is typically ``None`` as well, unless set explicitly:: m2 = MetaData(schema='newschema') # user_copy_one will have "newschema" as the schema name user_copy_one = user.tometadata(m2, schema=None) m3 = MetaData() # schema defaults to None # user_copy_two will have None as the schema name user_copy_two = user.tometadata(m3, schema=None) :param referred_schema_fn: optional callable which can be supplied in order to provide for the schema name that should be assigned to the referenced table of a :class:`.ForeignKeyConstraint`. The callable accepts this parent :class:`.Table`, the target schema that we are changing to, the :class:`.ForeignKeyConstraint` object, and the existing "target schema" of that constraint. The function should return the string schema name that should be applied. E.g.:: def referred_schema_fn(table, to_schema, constraint, referred_schema): if referred_schema == 'base_tables': return referred_schema else: return to_schema new_table = table.tometadata(m2, schema="alt_schema", referred_schema_fn=referred_schema_fn) .. versionadded:: 0.9.2 :param name: optional string name indicating the target table name. If not specified or None, the table name is retained. This allows a :class:`.Table` to be copied to the same :class:`.MetaData` target with a new name. .. versionadded:: 1.0.0 """ if name is None: name = self.name if schema is RETAIN_SCHEMA: schema = self.schema elif schema is None: schema = metadata.schema key = _get_table_key(name, schema) if key in metadata.tables: util.warn("Table '%s' already exists within the given " "MetaData - not copying." % self.description) return metadata.tables[key] args = [] for c in self.columns: args.append(c.copy(schema=schema)) table = Table( name, metadata, schema=schema, *args, **self.kwargs ) for c in self.constraints: if isinstance(c, ForeignKeyConstraint): referred_schema = c._referred_schema if referred_schema_fn: fk_constraint_schema = referred_schema_fn( self, schema, c, referred_schema) else: fk_constraint_schema = ( schema if referred_schema == self.schema else None) table.append_constraint( c.copy(schema=fk_constraint_schema, target_table=table)) elif not c._type_bound: # skip unique constraints that would be generated # by the 'unique' flag on Column if isinstance(c, UniqueConstraint) and \ len(c.columns) == 1 and \ list(c.columns)[0].unique: continue table.append_constraint( c.copy(schema=schema, target_table=table)) for index in self.indexes: # skip indexes that would be generated # by the 'index' flag on Column if len(index.columns) == 1 and \ list(index.columns)[0].index: continue Index(index.name, unique=index.unique, *[table.c[col] for col in index.columns.keys()], **index.kwargs) return self._schema_item_copy(table) class Column(SchemaItem, ColumnClause): """Represents a column in a database table.""" __visit_name__ = 'column' def __init__(self, *args, **kwargs): """ Construct a new ``Column`` object. :param name: The name of this column as represented in the database. This argument may be the first positional argument, or specified via keyword. Names which contain no upper case characters will be treated as case insensitive names, and will not be quoted unless they are a reserved word. Names with any number of upper case characters will be quoted and sent exactly. Note that this behavior applies even for databases which standardize upper case names as case insensitive such as Oracle. The name field may be omitted at construction time and applied later, at any time before the Column is associated with a :class:`.Table`. This is to support convenient usage within the :mod:`~sqlalchemy.ext.declarative` extension. :param type\_: The column's type, indicated using an instance which subclasses :class:`~sqlalchemy.types.TypeEngine`. If no arguments are required for the type, the class of the type can be sent as well, e.g.:: # use a type with arguments Column('data', String(50)) # use no arguments Column('level', Integer) The ``type`` argument may be the second positional argument or specified by keyword. If the ``type`` is ``None`` or is omitted, it will first default to the special type :class:`.NullType`. If and when this :class:`.Column` is made to refer to another column using :class:`.ForeignKey` and/or :class:`.ForeignKeyConstraint`, the type of the remote-referenced column will be copied to this column as well, at the moment that the foreign key is resolved against that remote :class:`.Column` object. .. versionchanged:: 0.9.0 Support for propagation of type to a :class:`.Column` from its :class:`.ForeignKey` object has been improved and should be more reliable and timely. :param \*args: Additional positional arguments include various :class:`.SchemaItem` derived constructs which will be applied as options to the column. These include instances of :class:`.Constraint`, :class:`.ForeignKey`, :class:`.ColumnDefault`, and :class:`.Sequence`. In some cases an equivalent keyword argument is available such as ``server_default``, ``default`` and ``unique``. :param autoincrement: This flag may be set to ``False`` to indicate an integer primary key column that should not be considered to be the "autoincrement" column, that is the integer primary key column which generates values implicitly upon INSERT and whose value is usually returned via the DBAPI cursor.lastrowid attribute. It defaults to ``True`` to satisfy the common use case of a table with a single integer primary key column. If the table has a composite primary key consisting of more than one integer column, set this flag to True only on the column that should be considered "autoincrement". The setting *only* has an effect for columns which are: * Integer derived (i.e. INT, SMALLINT, BIGINT). * Part of the primary key * Not refering to another column via :class:`.ForeignKey`, unless the value is specified as ``'ignore_fk'``:: # turn on autoincrement for this column despite # the ForeignKey() Column('id', ForeignKey('other.id'), primary_key=True, autoincrement='ignore_fk') It is typically not desirable to have "autoincrement" enabled on such a column as its value intends to mirror that of a primary key column elsewhere. * have no server side or client side defaults (with the exception of Postgresql SERIAL). The setting has these two effects on columns that meet the above criteria: * DDL issued for the column will include database-specific keywords intended to signify this column as an "autoincrement" column, such as AUTO INCREMENT on MySQL, SERIAL on Postgresql, and IDENTITY on MS-SQL. It does *not* issue AUTOINCREMENT for SQLite since this is a special SQLite flag that is not required for autoincrementing behavior. .. seealso:: :ref:`sqlite_autoincrement` * The column will be considered to be available as cursor.lastrowid or equivalent, for those dialects which "post fetch" newly inserted identifiers after a row has been inserted (SQLite, MySQL, MS-SQL). It does not have any effect in this regard for databases that use sequences to generate primary key identifiers (i.e. Firebird, Postgresql, Oracle). .. versionchanged:: 0.7.4 ``autoincrement`` accepts a special value ``'ignore_fk'`` to indicate that autoincrementing status regardless of foreign key references. This applies to certain composite foreign key setups, such as the one demonstrated in the ORM documentation at :ref:`post_update`. :param default: A scalar, Python callable, or :class:`.ColumnElement` expression representing the *default value* for this column, which will be invoked upon insert if this column is otherwise not specified in the VALUES clause of the insert. This is a shortcut to using :class:`.ColumnDefault` as a positional argument; see that class for full detail on the structure of the argument. Contrast this argument to :paramref:`.Column.server_default` which creates a default generator on the database side. .. seealso:: :ref:`metadata_defaults_toplevel` :param doc: optional String that can be used by the ORM or similar to document attributes. This attribute does not render SQL comments (a future attribute 'comment' will achieve that). :param key: An optional string identifier which will identify this ``Column`` object on the :class:`.Table`. When a key is provided, this is the only identifier referencing the ``Column`` within the application, including ORM attribute mapping; the ``name`` field is used only when rendering SQL. :param index: When ``True``, indicates that the column is indexed. This is a shortcut for using a :class:`.Index` construct on the table. To specify indexes with explicit names or indexes that contain multiple columns, use the :class:`.Index` construct instead. :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. :param nullable: If set to the default of ``True``, indicates the column will be rendered as allowing NULL, else it's rendered as NOT NULL. This parameter is only used when issuing CREATE TABLE statements. :param onupdate: A scalar, Python callable, or :class:`~sqlalchemy.sql.expression.ClauseElement` representing a default value to be applied to the column within UPDATE statements, which wil be invoked upon update if this column is not present in the SET clause of the update. This is a shortcut to using :class:`.ColumnDefault` as a positional argument with ``for_update=True``. :param primary_key: If ``True``, marks this column as a primary key column. Multiple columns can have this flag set to specify composite primary keys. As an alternative, the primary key of a :class:`.Table` can be specified via an explicit :class:`.PrimaryKeyConstraint` object. :param server_default: A :class:`.FetchedValue` instance, str, Unicode or :func:`~sqlalchemy.sql.expression.text` construct representing the DDL DEFAULT value for the column. String types will be emitted as-is, surrounded by single quotes:: Column('x', Text, server_default="val") x TEXT DEFAULT 'val' A :func:`~sqlalchemy.sql.expression.text` expression will be rendered as-is, without quotes:: Column('y', DateTime, server_default=text('NOW()')) y DATETIME DEFAULT NOW() Strings and text() will be converted into a :class:`.DefaultClause` object upon initialization. Use :class:`.FetchedValue` to indicate that an already-existing column will generate a default value on the database side which will be available to SQLAlchemy for post-fetch after inserts. This construct does not specify any DDL and the implementation is left to the database, such as via a trigger. .. seealso:: :ref:`server_defaults` :param server_onupdate: A :class:`.FetchedValue` instance representing a database-side default generation function. This indicates to SQLAlchemy that a newly generated value will be available after updates. This construct does not specify any DDL and the implementation is left to the database, such as via a trigger. :param quote: Force quoting of this column's name on or off, corresponding to ``True`` or ``False``. When left at its default of ``None``, the column identifier will be quoted according to whether the name is case sensitive (identifiers with at least one upper case character are treated as case sensitive), or if it's a reserved word. This flag is only needed to force quoting of a reserved word which is not known by the SQLAlchemy dialect. :param unique: When ``True``, indicates that this column contains a unique constraint, or if ``index`` is ``True`` as well, indicates that the :class:`.Index` should be created with the unique flag. To specify multiple columns in the constraint/index or to specify an explicit name, use the :class:`.UniqueConstraint` or :class:`.Index` constructs explicitly. :param system: When ``True``, indicates this is a "system" column, that is a column which is automatically made available by the database, and should not be included in the columns list for a ``CREATE TABLE`` statement. For more elaborate scenarios where columns should be conditionally rendered differently on different backends, consider custom compilation rules for :class:`.CreateColumn`. .. versionadded:: 0.8.3 Added the ``system=True`` parameter to :class:`.Column`. """ name = kwargs.pop('name', None) type_ = kwargs.pop('type_', None) args = list(args) if args: if isinstance(args[0], util.string_types): if name is not None: raise exc.ArgumentError( "May not pass name positionally and as a keyword.") name = args.pop(0) if args: coltype = args[0] if hasattr(coltype, "_sqla_type"): if type_ is not None: raise exc.ArgumentError( "May not pass type_ positionally and as a keyword.") type_ = args.pop(0) if name is not None: name = quoted_name(name, kwargs.pop('quote', None)) elif "quote" in kwargs: raise exc.ArgumentError("Explicit 'name' is required when " "sending 'quote' argument") super(Column, self).__init__(name, type_) self.key = kwargs.pop('key', name) self.primary_key = kwargs.pop('primary_key', False) self.nullable = kwargs.pop('nullable', not self.primary_key) self.default = kwargs.pop('default', None) self.server_default = kwargs.pop('server_default', None) self.server_onupdate = kwargs.pop('server_onupdate', None) # these default to None because .index and .unique is *not* # an informational flag about Column - there can still be an # Index or UniqueConstraint referring to this Column. self.index = kwargs.pop('index', None) self.unique = kwargs.pop('unique', None) self.system = kwargs.pop('system', False) self.doc = kwargs.pop('doc', None) self.onupdate = kwargs.pop('onupdate', None) self.autoincrement = kwargs.pop('autoincrement', True) self.constraints = set() self.foreign_keys = set() # check if this Column is proxying another column if '_proxies' in kwargs: self._proxies = kwargs.pop('_proxies') # otherwise, add DDL-related events elif isinstance(self.type, SchemaEventTarget): self.type._set_parent_with_dispatch(self) if self.default is not None: if isinstance(self.default, (ColumnDefault, Sequence)): args.append(self.default) else: if getattr(self.type, '_warn_on_bytestring', False): if isinstance(self.default, util.binary_type): util.warn( "Unicode column '%s' has non-unicode " "default value %r specified." % ( self.key, self.default )) args.append(ColumnDefault(self.default)) if self.server_default is not None: if isinstance(self.server_default, FetchedValue): args.append(self.server_default._as_for_update(False)) else: args.append(DefaultClause(self.server_default)) if self.onupdate is not None: if isinstance(self.onupdate, (ColumnDefault, Sequence)): args.append(self.onupdate) else: args.append(ColumnDefault(self.onupdate, for_update=True)) if self.server_onupdate is not None: if isinstance(self.server_onupdate, FetchedValue): args.append(self.server_onupdate._as_for_update(True)) else: args.append(DefaultClause(self.server_onupdate, for_update=True)) self._init_items(*args) util.set_creation_order(self) if 'info' in kwargs: self.info = kwargs.pop('info') if kwargs: raise exc.ArgumentError( "Unknown arguments passed to Column: " + repr(list(kwargs))) # @property # def quote(self): # return getattr(self.name, "quote", None) def __str__(self): if self.name is None: return "(no name)" elif self.table is not None: if self.table.named_with_column: return (self.table.description + "." + self.description) else: return self.description else: return self.description def references(self, column): """Return True if this Column references the given column via foreign key.""" for fk in self.foreign_keys: if fk.column.proxy_set.intersection(column.proxy_set): return True else: return False def append_foreign_key(self, fk): fk._set_parent_with_dispatch(self) def __repr__(self): kwarg = [] if self.key != self.name: kwarg.append('key') if self.primary_key: kwarg.append('primary_key') if not self.nullable: kwarg.append('nullable') if self.onupdate: kwarg.append('onupdate') if self.default: kwarg.append('default') if self.server_default: kwarg.append('server_default') return "Column(%s)" % ', '.join( [repr(self.name)] + [repr(self.type)] + [repr(x) for x in self.foreign_keys if x is not None] + [repr(x) for x in self.constraints] + [(self.table is not None and "table=<%s>" % self.table.description or "table=None")] + ["%s=%s" % (k, repr(getattr(self, k))) for k in kwarg]) def _set_parent(self, table): if not self.name: raise exc.ArgumentError( "Column must be constructed with a non-blank name or " "assign a non-blank .name before adding to a Table.") if self.key is None: self.key = self.name existing = getattr(self, 'table', None) if existing is not None and existing is not table: raise exc.ArgumentError( "Column object '%s' already assigned to Table '%s'" % ( self.key, existing.description )) if self.key in table._columns: col = table._columns.get(self.key) if col is not self: for fk in col.foreign_keys: table.foreign_keys.remove(fk) if fk.constraint in table.constraints: # this might have been removed # already, if it's a composite constraint # and more than one col being replaced table.constraints.remove(fk.constraint) table._columns.replace(self) if self.primary_key: table.primary_key._replace(self) Table._autoincrement_column._reset(table) elif self.key in table.primary_key: raise exc.ArgumentError( "Trying to redefine primary-key column '%s' as a " "non-primary-key column on table '%s'" % ( self.key, table.fullname)) self.table = table if self.index: if isinstance(self.index, util.string_types): raise exc.ArgumentError( "The 'index' keyword argument on Column is boolean only. " "To create indexes with a specific name, create an " "explicit Index object external to the Table.") Index(None, self, unique=bool(self.unique)) elif self.unique: if isinstance(self.unique, util.string_types): raise exc.ArgumentError( "The 'unique' keyword argument on Column is boolean " "only. To create unique constraints or indexes with a " "specific name, append an explicit UniqueConstraint to " "the Table's list of elements, or create an explicit " "Index object external to the Table.") table.append_constraint(UniqueConstraint(self.key)) self._setup_on_memoized_fks(lambda fk: fk._set_remote_table(table)) def _setup_on_memoized_fks(self, fn): fk_keys = [ ((self.table.key, self.key), False), ((self.table.key, self.name), True), ] for fk_key, link_to_name in fk_keys: if fk_key in self.table.metadata._fk_memos: for fk in self.table.metadata._fk_memos[fk_key]: if fk.link_to_name is link_to_name: fn(fk) def _on_table_attach(self, fn): if self.table is not None: fn(self, self.table) else: event.listen(self, 'after_parent_attach', fn) def copy(self, **kw): """Create a copy of this ``Column``, unitialized. This is used in ``Table.tometadata``. """ # Constraint objects plus non-constraint-bound ForeignKey objects args = \ [c.copy(**kw) for c in self.constraints if not c._type_bound] + \ [c.copy(**kw) for c in self.foreign_keys if not c.constraint] type_ = self.type if isinstance(type_, SchemaEventTarget): type_ = type_.copy(**kw) c = self._constructor( name=self.name, type_=type_, key=self.key, primary_key=self.primary_key, nullable=self.nullable, unique=self.unique, system=self.system, # quote=self.quote, index=self.index, autoincrement=self.autoincrement, default=self.default, server_default=self.server_default, onupdate=self.onupdate, server_onupdate=self.server_onupdate, doc=self.doc, *args ) return self._schema_item_copy(c) def _make_proxy(self, selectable, name=None, key=None, name_is_truncatable=False, **kw): """Create a *proxy* for this column. This is a copy of this ``Column`` referenced by a different parent (such as an alias or select statement). The column should be used only in select scenarios, as its full DDL/default information is not transferred. """ fk = [ForeignKey(f.column, _constraint=f.constraint) for f in self.foreign_keys] if name is None and self.name is None: raise exc.InvalidRequestError( "Cannot initialize a sub-selectable" " with this Column object until its 'name' has " "been assigned.") try: c = self._constructor( _as_truncated(name or self.name) if name_is_truncatable else (name or self.name), self.type, key=key if key else name if name else self.key, primary_key=self.primary_key, nullable=self.nullable, _proxies=[self], *fk) except TypeError: util.raise_from_cause( TypeError( "Could not create a copy of this %r object. " "Ensure the class includes a _constructor() " "attribute or method which accepts the " "standard Column constructor arguments, or " "references the Column class itself." % self.__class__) ) c.table = selectable selectable._columns.add(c) if selectable._is_clone_of is not None: c._is_clone_of = selectable._is_clone_of.columns[c.key] if self.primary_key: selectable.primary_key.add(c) c.dispatch.after_parent_attach(c, selectable) return c def get_children(self, schema_visitor=False, **kwargs): if schema_visitor: return [x for x in (self.default, self.onupdate) if x is not None] + \ list(self.foreign_keys) + list(self.constraints) else: return ColumnClause.get_children(self, **kwargs) class ForeignKey(DialectKWArgs, SchemaItem): """Defines a dependency between two columns. ``ForeignKey`` is specified as an argument to a :class:`.Column` object, e.g.:: t = Table("remote_table", metadata, Column("remote_id", ForeignKey("main_table.id")) ) Note that ``ForeignKey`` is only a marker object that defines a dependency between two columns. The actual constraint is in all cases represented by the :class:`.ForeignKeyConstraint` object. This object will be generated automatically when a ``ForeignKey`` is associated with a :class:`.Column` which in turn is associated with a :class:`.Table`. Conversely, when :class:`.ForeignKeyConstraint` is applied to a :class:`.Table`, ``ForeignKey`` markers are automatically generated to be present on each associated :class:`.Column`, which are also associated with the constraint object. Note that you cannot define a "composite" foreign key constraint, that is a constraint between a grouping of multiple parent/child columns, using ``ForeignKey`` objects. To define this grouping, the :class:`.ForeignKeyConstraint` object must be used, and applied to the :class:`.Table`. The associated ``ForeignKey`` objects are created automatically. The ``ForeignKey`` objects associated with an individual :class:`.Column` object are available in the `foreign_keys` collection of that column. Further examples of foreign key configuration are in :ref:`metadata_foreignkeys`. """ __visit_name__ = 'foreign_key' def __init__(self, column, _constraint=None, use_alter=False, name=None, onupdate=None, ondelete=None, deferrable=None, initially=None, link_to_name=False, match=None, info=None, **dialect_kw): """ Construct a column-level FOREIGN KEY. The :class:`.ForeignKey` object when constructed generates a :class:`.ForeignKeyConstraint` which is associated with the parent :class:`.Table` object's collection of constraints. :param column: A single target column for the key relationship. A :class:`.Column` object or a column name as a string: ``tablename.columnkey`` or ``schema.tablename.columnkey``. ``columnkey`` is the ``key`` which has been assigned to the column (defaults to the column name itself), unless ``link_to_name`` is ``True`` in which case the rendered name of the column is used. .. versionadded:: 0.7.4 Note that if the schema name is not included, and the underlying :class:`.MetaData` has a "schema", that value will be used. :param name: Optional string. An in-database name for the key if `constraint` is not provided. :param onupdate: Optional string. If set, emit ON UPDATE <value> when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. :param ondelete: Optional string. If set, emit ON DELETE <value> when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. :param deferrable: Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when issuing DDL for this constraint. :param initially: Optional string. If set, emit INITIALLY <value> when issuing DDL for this constraint. :param link_to_name: if True, the string name given in ``column`` is the rendered name of the referenced column, not its locally assigned ``key``. :param use_alter: passed to the underlying :class:`.ForeignKeyConstraint` to indicate the constraint should be generated/dropped externally from the CREATE TABLE/ DROP TABLE statement. See :paramref:`.ForeignKeyConstraint.use_alter` for further description. .. seealso:: :paramref:`.ForeignKeyConstraint.use_alter` :ref:`use_alter` :param match: Optional string. If set, emit MATCH <value> when issuing DDL for this constraint. Typical values include SIMPLE, PARTIAL and FULL. :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. .. versionadded:: 1.0.0 :param \**dialect_kw: Additional keyword arguments are dialect specific, and passed in the form ``<dialectname>_<argname>``. The arguments are ultimately handled by a corresponding :class:`.ForeignKeyConstraint`. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. .. versionadded:: 0.9.2 """ self._colspec = column if isinstance(self._colspec, util.string_types): self._table_column = None else: if hasattr(self._colspec, '__clause_element__'): self._table_column = self._colspec.__clause_element__() else: self._table_column = self._colspec if not isinstance(self._table_column, ColumnClause): raise exc.ArgumentError( "String, Column, or Column-bound argument " "expected, got %r" % self._table_column) elif not isinstance( self._table_column.table, (util.NoneType, TableClause)): raise exc.ArgumentError( "ForeignKey received Column not bound " "to a Table, got: %r" % self._table_column.table ) # the linked ForeignKeyConstraint. # ForeignKey will create this when parent Column # is attached to a Table, *or* ForeignKeyConstraint # object passes itself in when creating ForeignKey # markers. self.constraint = _constraint self.parent = None self.use_alter = use_alter self.name = name self.onupdate = onupdate self.ondelete = ondelete self.deferrable = deferrable self.initially = initially self.link_to_name = link_to_name self.match = match if info: self.info = info self._unvalidated_dialect_kw = dialect_kw def __repr__(self): return "ForeignKey(%r)" % self._get_colspec() def copy(self, schema=None): """Produce a copy of this :class:`.ForeignKey` object. The new :class:`.ForeignKey` will not be bound to any :class:`.Column`. This method is usually used by the internal copy procedures of :class:`.Column`, :class:`.Table`, and :class:`.MetaData`. :param schema: The returned :class:`.ForeignKey` will reference the original table and column name, qualified by the given string schema name. """ fk = ForeignKey( self._get_colspec(schema=schema), use_alter=self.use_alter, name=self.name, onupdate=self.onupdate, ondelete=self.ondelete, deferrable=self.deferrable, initially=self.initially, link_to_name=self.link_to_name, match=self.match, **self._unvalidated_dialect_kw ) return self._schema_item_copy(fk) def _get_colspec(self, schema=None, table_name=None): """Return a string based 'column specification' for this :class:`.ForeignKey`. This is usually the equivalent of the string-based "tablename.colname" argument first passed to the object's constructor. """ if schema: _schema, tname, colname = self._column_tokens if table_name is not None: tname = table_name return "%s.%s.%s" % (schema, tname, colname) elif table_name: schema, tname, colname = self._column_tokens if schema: return "%s.%s.%s" % (schema, table_name, colname) else: return "%s.%s" % (table_name, colname) elif self._table_column is not None: return "%s.%s" % ( self._table_column.table.fullname, self._table_column.key) else: return self._colspec @property def _referred_schema(self): return self._column_tokens[0] def _table_key(self): if self._table_column is not None: if self._table_column.table is None: return None else: return self._table_column.table.key else: schema, tname, colname = self._column_tokens return _get_table_key(tname, schema) target_fullname = property(_get_colspec) def references(self, table): """Return True if the given :class:`.Table` is referenced by this :class:`.ForeignKey`.""" return table.corresponding_column(self.column) is not None def get_referent(self, table): """Return the :class:`.Column` in the given :class:`.Table` referenced by this :class:`.ForeignKey`. Returns None if this :class:`.ForeignKey` does not reference the given :class:`.Table`. """ return table.corresponding_column(self.column) @util.memoized_property def _column_tokens(self): """parse a string-based _colspec into its component parts.""" m = self._get_colspec().split('.') if m is None: raise exc.ArgumentError( "Invalid foreign key column specification: %s" % self._colspec) if (len(m) == 1): tname = m.pop() colname = None else: colname = m.pop() tname = m.pop() # A FK between column 'bar' and table 'foo' can be # specified as 'foo', 'foo.bar', 'dbo.foo.bar', # 'otherdb.dbo.foo.bar'. Once we have the column name and # the table name, treat everything else as the schema # name. Some databases (e.g. Sybase) support # inter-database foreign keys. See tickets#1341 and -- # indirectly related -- Ticket #594. This assumes that '.' # will never appear *within* any component of the FK. if (len(m) > 0): schema = '.'.join(m) else: schema = None return schema, tname, colname def _resolve_col_tokens(self): if self.parent is None: raise exc.InvalidRequestError( "this ForeignKey object does not yet have a " "parent Column associated with it.") elif self.parent.table is None: raise exc.InvalidRequestError( "this ForeignKey's parent column is not yet associated " "with a Table.") parenttable = self.parent.table # assertion, can be commented out. # basically Column._make_proxy() sends the actual # target Column to the ForeignKey object, so the # string resolution here is never called. for c in self.parent.base_columns: if isinstance(c, Column): assert c.table is parenttable break else: assert False ###################### schema, tname, colname = self._column_tokens if schema is None and parenttable.metadata.schema is not None: schema = parenttable.metadata.schema tablekey = _get_table_key(tname, schema) return parenttable, tablekey, colname def _link_to_col_by_colstring(self, parenttable, table, colname): if not hasattr(self.constraint, '_referred_table'): self.constraint._referred_table = table else: assert self.constraint._referred_table is table _column = None if colname is None: # colname is None in the case that ForeignKey argument # was specified as table name only, in which case we # match the column name to the same column on the # parent. key = self.parent _column = table.c.get(self.parent.key, None) elif self.link_to_name: key = colname for c in table.c: if c.name == colname: _column = c else: key = colname _column = table.c.get(colname, None) if _column is None: raise exc.NoReferencedColumnError( "Could not initialize target column " "for ForeignKey '%s' on table '%s': " "table '%s' has no column named '%s'" % (self._colspec, parenttable.name, table.name, key), table.name, key) self._set_target_column(_column) def _set_target_column(self, column): # propagate TypeEngine to parent if it didn't have one if self.parent.type._isnull: self.parent.type = column.type # super-edgy case, if other FKs point to our column, # they'd get the type propagated out also. if isinstance(self.parent.table, Table): def set_type(fk): if fk.parent.type._isnull: fk.parent.type = column.type self.parent._setup_on_memoized_fks(set_type) self.column = column @util.memoized_property def column(self): """Return the target :class:`.Column` referenced by this :class:`.ForeignKey`. If no target column has been established, an exception is raised. .. versionchanged:: 0.9.0 Foreign key target column resolution now occurs as soon as both the ForeignKey object and the remote Column to which it refers are both associated with the same MetaData object. """ if isinstance(self._colspec, util.string_types): parenttable, tablekey, colname = self._resolve_col_tokens() if tablekey not in parenttable.metadata: raise exc.NoReferencedTableError( "Foreign key associated with column '%s' could not find " "table '%s' with which to generate a " "foreign key to target column '%s'" % (self.parent, tablekey, colname), tablekey) elif parenttable.key not in parenttable.metadata: raise exc.InvalidRequestError( "Table %s is no longer associated with its " "parent MetaData" % parenttable) else: raise exc.NoReferencedColumnError( "Could not initialize target column for " "ForeignKey '%s' on table '%s': " "table '%s' has no column named '%s'" % ( self._colspec, parenttable.name, tablekey, colname), tablekey, colname) elif hasattr(self._colspec, '__clause_element__'): _column = self._colspec.__clause_element__() return _column else: _column = self._colspec return _column def _set_parent(self, column): if self.parent is not None and self.parent is not column: raise exc.InvalidRequestError( "This ForeignKey already has a parent !") self.parent = column self.parent.foreign_keys.add(self) self.parent._on_table_attach(self._set_table) def _set_remote_table(self, table): parenttable, tablekey, colname = self._resolve_col_tokens() self._link_to_col_by_colstring(parenttable, table, colname) self.constraint._validate_dest_table(table) def _remove_from_metadata(self, metadata): parenttable, table_key, colname = self._resolve_col_tokens() fk_key = (table_key, colname) if self in metadata._fk_memos[fk_key]: # TODO: no test coverage for self not in memos metadata._fk_memos[fk_key].remove(self) def _set_table(self, column, table): # standalone ForeignKey - create ForeignKeyConstraint # on the hosting Table when attached to the Table. if self.constraint is None and isinstance(table, Table): self.constraint = ForeignKeyConstraint( [], [], use_alter=self.use_alter, name=self.name, onupdate=self.onupdate, ondelete=self.ondelete, deferrable=self.deferrable, initially=self.initially, match=self.match, **self._unvalidated_dialect_kw ) self.constraint._append_element(column, self) self.constraint._set_parent_with_dispatch(table) table.foreign_keys.add(self) # set up remote ".column" attribute, or a note to pick it # up when the other Table/Column shows up if isinstance(self._colspec, util.string_types): parenttable, table_key, colname = self._resolve_col_tokens() fk_key = (table_key, colname) if table_key in parenttable.metadata.tables: table = parenttable.metadata.tables[table_key] try: self._link_to_col_by_colstring( parenttable, table, colname) except exc.NoReferencedColumnError: # this is OK, we'll try later pass parenttable.metadata._fk_memos[fk_key].append(self) elif hasattr(self._colspec, '__clause_element__'): _column = self._colspec.__clause_element__() self._set_target_column(_column) else: _column = self._colspec self._set_target_column(_column) class _NotAColumnExpr(object): def _not_a_column_expr(self): raise exc.InvalidRequestError( "This %s cannot be used directly " "as a column expression." % self.__class__.__name__) __clause_element__ = self_group = lambda self: self._not_a_column_expr() _from_objects = property(lambda self: self._not_a_column_expr()) class DefaultGenerator(_NotAColumnExpr, SchemaItem): """Base class for column *default* values.""" __visit_name__ = 'default_generator' is_sequence = False is_server_default = False column = None def __init__(self, for_update=False): self.for_update = for_update def _set_parent(self, column): self.column = column if self.for_update: self.column.onupdate = self else: self.column.default = self def execute(self, bind=None, **kwargs): if bind is None: bind = _bind_or_error(self) return bind._execute_default(self, **kwargs) @property def bind(self): """Return the connectable associated with this default.""" if getattr(self, 'column', None) is not None: return self.column.table.bind else: return None class ColumnDefault(DefaultGenerator): """A plain default value on a column. This could correspond to a constant, a callable function, or a SQL clause. :class:`.ColumnDefault` is generated automatically whenever the ``default``, ``onupdate`` arguments of :class:`.Column` are used. A :class:`.ColumnDefault` can be passed positionally as well. For example, the following:: Column('foo', Integer, default=50) Is equivalent to:: Column('foo', Integer, ColumnDefault(50)) """ def __init__(self, arg, **kwargs): """"Construct a new :class:`.ColumnDefault`. :param arg: argument representing the default value. May be one of the following: * a plain non-callable Python value, such as a string, integer, boolean, or other simple type. The default value will be used as is each time. * a SQL expression, that is one which derives from :class:`.ColumnElement`. The SQL expression will be rendered into the INSERT or UPDATE statement, or in the case of a primary key column when RETURNING is not used may be pre-executed before an INSERT within a SELECT. * A Python callable. The function will be invoked for each new row subject to an INSERT or UPDATE. The callable must accept exactly zero or one positional arguments. The one-argument form will receive an instance of the :class:`.ExecutionContext`, which provides contextual information as to the current :class:`.Connection` in use as well as the current statement and parameters. """ super(ColumnDefault, self).__init__(**kwargs) if isinstance(arg, FetchedValue): raise exc.ArgumentError( "ColumnDefault may not be a server-side default type.") if util.callable(arg): arg = self._maybe_wrap_callable(arg) self.arg = arg @util.memoized_property def is_callable(self): return util.callable(self.arg) @util.memoized_property def is_clause_element(self): return isinstance(self.arg, ClauseElement) @util.memoized_property def is_scalar(self): return not self.is_callable and \ not self.is_clause_element and \ not self.is_sequence def _maybe_wrap_callable(self, fn): """Wrap callables that don't accept a context. This is to allow easy compatibility with default callables that aren't specific to accepting of a context. """ try: argspec = util.get_callable_argspec(fn, no_self=True) except TypeError: return lambda ctx: fn() defaulted = argspec[3] is not None and len(argspec[3]) or 0 positionals = len(argspec[0]) - defaulted if positionals == 0: return lambda ctx: fn() elif positionals == 1: return fn else: raise exc.ArgumentError( "ColumnDefault Python function takes zero or one " "positional arguments") def _visit_name(self): if self.for_update: return "column_onupdate" else: return "column_default" __visit_name__ = property(_visit_name) def __repr__(self): return "ColumnDefault(%r)" % self.arg class Sequence(DefaultGenerator): """Represents a named database sequence. The :class:`.Sequence` object represents the name and configurational parameters of a database sequence. It also represents a construct that can be "executed" by a SQLAlchemy :class:`.Engine` or :class:`.Connection`, rendering the appropriate "next value" function for the target database and returning a result. The :class:`.Sequence` is typically associated with a primary key column:: some_table = Table( 'some_table', metadata, Column('id', Integer, Sequence('some_table_seq'), primary_key=True) ) When CREATE TABLE is emitted for the above :class:`.Table`, if the target platform supports sequences, a CREATE SEQUENCE statement will be emitted as well. For platforms that don't support sequences, the :class:`.Sequence` construct is ignored. .. seealso:: :class:`.CreateSequence` :class:`.DropSequence` """ __visit_name__ = 'sequence' is_sequence = True def __init__(self, name, start=None, increment=None, minvalue=None, maxvalue=None, nominvalue=None, nomaxvalue=None, cycle=None, schema=None, optional=False, quote=None, metadata=None, quote_schema=None, for_update=False): """Construct a :class:`.Sequence` object. :param name: The name of the sequence. :param start: the starting index of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "START WITH" clause. If ``None``, the clause is omitted, which on most platforms indicates a starting value of 1. :param increment: the increment value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "INCREMENT BY" clause. If ``None``, the clause is omitted, which on most platforms indicates an increment of 1. :param minvalue: the minimum value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "MINVALUE" clause. If ``None``, the clause is omitted, which on most platforms indicates a minvalue of 1 and -2^63-1 for ascending and descending sequences, respectively. .. versionadded:: 1.0.7 :param maxvalue: the maximum value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "MAXVALUE" clause. If ``None``, the clause is omitted, which on most platforms indicates a maxvalue of 2^63-1 and -1 for ascending and descending sequences, respectively. .. versionadded:: 1.0.7 :param nominvalue: no minimum value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "NO MINVALUE" clause. If ``None``, the clause is omitted, which on most platforms indicates a minvalue of 1 and -2^63-1 for ascending and descending sequences, respectively. .. versionadded:: 1.0.7 :param nomaxvalue: no maximum value of the sequence. This value is used when the CREATE SEQUENCE command is emitted to the database as the value of the "NO MAXVALUE" clause. If ``None``, the clause is omitted, which on most platforms indicates a maxvalue of 2^63-1 and -1 for ascending and descending sequences, respectively. .. versionadded:: 1.0.7 :param cycle: allows the sequence to wrap around when the maxvalue or minvalue has been reached by an ascending or descending sequence respectively. This value is used when the CREATE SEQUENCE command is emitted to the database as the "CYCLE" clause. If the limit is reached, the next number generated will be the minvalue or maxvalue, respectively. If cycle=False (the default) any calls to nextval after the sequence has reached its maximum value will return an error. .. versionadded:: 1.0.7 :param schema: Optional schema name for the sequence, if located in a schema other than the default. The rules for selecting the schema name when a :class:`.MetaData` is also present are the same as that of :paramref:`.Table.schema`. :param optional: boolean value, when ``True``, indicates that this :class:`.Sequence` object only needs to be explicitly generated on backends that don't provide another way to generate primary key identifiers. Currently, it essentially means, "don't create this sequence on the Postgresql backend, where the SERIAL keyword creates a sequence for us automatically". :param quote: boolean value, when ``True`` or ``False``, explicitly forces quoting of the schema name on or off. When left at its default of ``None``, normal quoting rules based on casing and reserved words take place. :param quote_schema: set the quoting preferences for the ``schema`` name. :param metadata: optional :class:`.MetaData` object which will be associated with this :class:`.Sequence`. A :class:`.Sequence` that is associated with a :class:`.MetaData` gains access to the ``bind`` of that :class:`.MetaData`, meaning the :meth:`.Sequence.create` and :meth:`.Sequence.drop` methods will make usage of that engine automatically. .. versionchanged:: 0.7 Additionally, the appropriate CREATE SEQUENCE/ DROP SEQUENCE DDL commands will be emitted corresponding to this :class:`.Sequence` when :meth:`.MetaData.create_all` and :meth:`.MetaData.drop_all` are invoked. Note that when a :class:`.Sequence` is applied to a :class:`.Column`, the :class:`.Sequence` is automatically associated with the :class:`.MetaData` object of that column's parent :class:`.Table`, when that association is made. The :class:`.Sequence` will then be subject to automatic CREATE SEQUENCE/DROP SEQUENCE corresponding to when the :class:`.Table` object itself is created or dropped, rather than that of the :class:`.MetaData` object overall. :param for_update: Indicates this :class:`.Sequence`, when associated with a :class:`.Column`, should be invoked for UPDATE statements on that column's table, rather than for INSERT statements, when no value is otherwise present for that column in the statement. """ super(Sequence, self).__init__(for_update=for_update) self.name = quoted_name(name, quote) self.start = start self.increment = increment self.minvalue = minvalue self.maxvalue = maxvalue self.nominvalue = nominvalue self.nomaxvalue = nomaxvalue self.cycle = cycle self.optional = optional if schema is BLANK_SCHEMA: self.schema = schema = None elif metadata is not None and schema is None and metadata.schema: self.schema = schema = metadata.schema else: self.schema = quoted_name(schema, quote_schema) self.metadata = metadata self._key = _get_table_key(name, schema) if metadata: self._set_metadata(metadata) @util.memoized_property def is_callable(self): return False @util.memoized_property def is_clause_element(self): return False @util.dependencies("sqlalchemy.sql.functions.func") def next_value(self, func): """Return a :class:`.next_value` function element which will render the appropriate increment function for this :class:`.Sequence` within any SQL expression. """ return func.next_value(self, bind=self.bind) def _set_parent(self, column): super(Sequence, self)._set_parent(column) column._on_table_attach(self._set_table) def _set_table(self, column, table): self._set_metadata(table.metadata) def _set_metadata(self, metadata): self.metadata = metadata self.metadata._sequences[self._key] = self @property def bind(self): if self.metadata: return self.metadata.bind else: return None def create(self, bind=None, checkfirst=True): """Creates this sequence in the database.""" if bind is None: bind = _bind_or_error(self) bind._run_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst) def drop(self, bind=None, checkfirst=True): """Drops this sequence from the database.""" if bind is None: bind = _bind_or_error(self) bind._run_visitor(ddl.SchemaDropper, self, checkfirst=checkfirst) def _not_a_column_expr(self): raise exc.InvalidRequestError( "This %s cannot be used directly " "as a column expression. Use func.next_value(sequence) " "to produce a 'next value' function that's usable " "as a column element." % self.__class__.__name__) @inspection._self_inspects class FetchedValue(_NotAColumnExpr, SchemaEventTarget): """A marker for a transparent database-side default. Use :class:`.FetchedValue` when the database is configured to provide some automatic default for a column. E.g.:: Column('foo', Integer, FetchedValue()) Would indicate that some trigger or default generator will create a new value for the ``foo`` column during an INSERT. .. seealso:: :ref:`triggered_columns` """ is_server_default = True reflected = False has_argument = False def __init__(self, for_update=False): self.for_update = for_update def _as_for_update(self, for_update): if for_update == self.for_update: return self else: return self._clone(for_update) def _clone(self, for_update): n = self.__class__.__new__(self.__class__) n.__dict__.update(self.__dict__) n.__dict__.pop('column', None) n.for_update = for_update return n def _set_parent(self, column): self.column = column if self.for_update: self.column.server_onupdate = self else: self.column.server_default = self def __repr__(self): return util.generic_repr(self) class DefaultClause(FetchedValue): """A DDL-specified DEFAULT column value. :class:`.DefaultClause` is a :class:`.FetchedValue` that also generates a "DEFAULT" clause when "CREATE TABLE" is emitted. :class:`.DefaultClause` is generated automatically whenever the ``server_default``, ``server_onupdate`` arguments of :class:`.Column` are used. A :class:`.DefaultClause` can be passed positionally as well. For example, the following:: Column('foo', Integer, server_default="50") Is equivalent to:: Column('foo', Integer, DefaultClause("50")) """ has_argument = True def __init__(self, arg, for_update=False, _reflected=False): util.assert_arg_type(arg, (util.string_types[0], ClauseElement, TextClause), 'arg') super(DefaultClause, self).__init__(for_update) self.arg = arg self.reflected = _reflected def __repr__(self): return "DefaultClause(%r, for_update=%r)" % \ (self.arg, self.for_update) class PassiveDefault(DefaultClause): """A DDL-specified DEFAULT column value. .. deprecated:: 0.6 :class:`.PassiveDefault` is deprecated. Use :class:`.DefaultClause`. """ @util.deprecated("0.6", ":class:`.PassiveDefault` is deprecated. " "Use :class:`.DefaultClause`.", False) def __init__(self, *arg, **kw): DefaultClause.__init__(self, *arg, **kw) class Constraint(DialectKWArgs, SchemaItem): """A table-level SQL constraint.""" __visit_name__ = 'constraint' def __init__(self, name=None, deferrable=None, initially=None, _create_rule=None, info=None, _type_bound=False, **dialect_kw): """Create a SQL constraint. :param name: Optional, the in-database name of this ``Constraint``. :param deferrable: Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when issuing DDL for this constraint. :param initially: Optional string. If set, emit INITIALLY <value> when issuing DDL for this constraint. :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. .. versionadded:: 1.0.0 :param _create_rule: a callable which is passed the DDLCompiler object during compilation. Returns True or False to signal inline generation of this Constraint. The AddConstraint and DropConstraint DDL constructs provide DDLElement's more comprehensive "conditional DDL" approach that is passed a database connection when DDL is being issued. _create_rule is instead called during any CREATE TABLE compilation, where there may not be any transaction/connection in progress. However, it allows conditional compilation of the constraint even for backends which do not support addition of constraints through ALTER TABLE, which currently includes SQLite. _create_rule is used by some types to create constraints. Currently, its call signature is subject to change at any time. :param \**dialect_kw: Additional keyword arguments are dialect specific, and passed in the form ``<dialectname>_<argname>``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. """ self.name = name self.deferrable = deferrable self.initially = initially if info: self.info = info self._create_rule = _create_rule self._type_bound = _type_bound util.set_creation_order(self) self._validate_dialect_kwargs(dialect_kw) @property def table(self): try: if isinstance(self.parent, Table): return self.parent except AttributeError: pass raise exc.InvalidRequestError( "This constraint is not bound to a table. Did you " "mean to call table.append_constraint(constraint) ?") def _set_parent(self, parent): self.parent = parent parent.constraints.add(self) def copy(self, **kw): raise NotImplementedError() def _to_schema_column(element): if hasattr(element, '__clause_element__'): element = element.__clause_element__() if not isinstance(element, Column): raise exc.ArgumentError("schema.Column object expected") return element def _to_schema_column_or_string(element): if hasattr(element, '__clause_element__'): element = element.__clause_element__() if not isinstance(element, util.string_types + (ColumnElement, )): msg = "Element %r is not a string name or column element" raise exc.ArgumentError(msg % element) return element class ColumnCollectionMixin(object): columns = None """A :class:`.ColumnCollection` of :class:`.Column` objects. This collection represents the columns which are referred to by this object. """ _allow_multiple_tables = False def __init__(self, *columns, **kw): _autoattach = kw.pop('_autoattach', True) self.columns = ColumnCollection() self._pending_colargs = [_to_schema_column_or_string(c) for c in columns] if _autoattach and self._pending_colargs: self._check_attach() @classmethod def _extract_col_expression_collection(cls, expressions): for expr in expressions: strname = None column = None if not isinstance(expr, ClauseElement): # this assumes a string strname = expr else: cols = [] visitors.traverse(expr, {}, {'column': cols.append}) if cols: column = cols[0] add_element = column if column is not None else strname yield expr, column, strname, add_element def _check_attach(self, evt=False): col_objs = [ c for c in self._pending_colargs if isinstance(c, Column) ] cols_w_table = [ c for c in col_objs if isinstance(c.table, Table) ] cols_wo_table = set(col_objs).difference(cols_w_table) if cols_wo_table: # feature #3341 - place event listeners for Column objects # such that when all those cols are attached, we autoattach. assert not evt, "Should not reach here on event call" # issue #3411 - don't do the per-column auto-attach if some of the # columns are specified as strings. has_string_cols = set(self._pending_colargs).difference(col_objs) if not has_string_cols: def _col_attached(column, table): cols_wo_table.discard(column) if not cols_wo_table: self._check_attach(evt=True) self._cols_wo_table = cols_wo_table for col in cols_wo_table: col._on_table_attach(_col_attached) return columns = cols_w_table tables = set([c.table for c in columns]) if len(tables) == 1: self._set_parent_with_dispatch(tables.pop()) elif len(tables) > 1 and not self._allow_multiple_tables: table = columns[0].table others = [c for c in columns[1:] if c.table is not table] if others: raise exc.ArgumentError( "Column(s) %s are not part of table '%s'." % (", ".join("'%s'" % c for c in others), table.description) ) def _set_parent(self, table): for col in self._pending_colargs: if isinstance(col, util.string_types): col = table.c[col] self.columns.add(col) class ColumnCollectionConstraint(ColumnCollectionMixin, Constraint): """A constraint that proxies a ColumnCollection.""" def __init__(self, *columns, **kw): """ :param \*columns: A sequence of column names or Column objects. :param name: Optional, the in-database name of this constraint. :param deferrable: Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when issuing DDL for this constraint. :param initially: Optional string. If set, emit INITIALLY <value> when issuing DDL for this constraint. :param \**kw: other keyword arguments including dialect-specific arguments are propagated to the :class:`.Constraint` superclass. """ _autoattach = kw.pop('_autoattach', True) Constraint.__init__(self, **kw) ColumnCollectionMixin.__init__(self, *columns, _autoattach=_autoattach) def _set_parent(self, table): Constraint._set_parent(self, table) ColumnCollectionMixin._set_parent(self, table) def __contains__(self, x): return x in self.columns def copy(self, **kw): c = self.__class__(name=self.name, deferrable=self.deferrable, initially=self.initially, *self.columns.keys()) return self._schema_item_copy(c) def contains_column(self, col): """Return True if this constraint contains the given column. Note that this object also contains an attribute ``.columns`` which is a :class:`.ColumnCollection` of :class:`.Column` objects. """ return self.columns.contains_column(col) def __iter__(self): # inlining of # return iter(self.columns) # ColumnCollection->OrderedProperties->OrderedDict ordered_dict = self.columns._data return (ordered_dict[key] for key in ordered_dict._list) def __len__(self): return len(self.columns._data) class CheckConstraint(ColumnCollectionConstraint): """A table- or column-level CHECK constraint. Can be included in the definition of a Table or Column. """ _allow_multiple_tables = True def __init__(self, sqltext, name=None, deferrable=None, initially=None, table=None, info=None, _create_rule=None, _autoattach=True, _type_bound=False): """Construct a CHECK constraint. :param sqltext: A string containing the constraint definition, which will be used verbatim, or a SQL expression construct. If given as a string, the object is converted to a :class:`.Text` object. If the textual string includes a colon character, escape this using a backslash:: CheckConstraint(r"foo ~ E'a(?\:b|c)d") :param name: Optional, the in-database name of the constraint. :param deferrable: Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when issuing DDL for this constraint. :param initially: Optional string. If set, emit INITIALLY <value> when issuing DDL for this constraint. :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. .. versionadded:: 1.0.0 """ self.sqltext = _literal_as_text(sqltext, warn=False) columns = [] visitors.traverse(self.sqltext, {}, {'column': columns.append}) super(CheckConstraint, self).\ __init__( name=name, deferrable=deferrable, initially=initially, _create_rule=_create_rule, info=info, _type_bound=_type_bound, _autoattach=_autoattach, *columns) if table is not None: self._set_parent_with_dispatch(table) def __visit_name__(self): if isinstance(self.parent, Table): return "check_constraint" else: return "column_check_constraint" __visit_name__ = property(__visit_name__) def copy(self, target_table=None, **kw): if target_table is not None: def replace(col): if self.table.c.contains_column(col): return target_table.c[col.key] else: return None sqltext = visitors.replacement_traverse(self.sqltext, {}, replace) else: sqltext = self.sqltext c = CheckConstraint(sqltext, name=self.name, initially=self.initially, deferrable=self.deferrable, _create_rule=self._create_rule, table=target_table, _autoattach=False, _type_bound=self._type_bound) return self._schema_item_copy(c) class ForeignKeyConstraint(ColumnCollectionConstraint): """A table-level FOREIGN KEY constraint. Defines a single column or composite FOREIGN KEY ... REFERENCES constraint. For a no-frills, single column foreign key, adding a :class:`.ForeignKey` to the definition of a :class:`.Column` is a shorthand equivalent for an unnamed, single column :class:`.ForeignKeyConstraint`. Examples of foreign key configuration are in :ref:`metadata_foreignkeys`. """ __visit_name__ = 'foreign_key_constraint' def __init__(self, columns, refcolumns, name=None, onupdate=None, ondelete=None, deferrable=None, initially=None, use_alter=False, link_to_name=False, match=None, table=None, info=None, **dialect_kw): """Construct a composite-capable FOREIGN KEY. :param columns: A sequence of local column names. The named columns must be defined and present in the parent Table. The names should match the ``key`` given to each column (defaults to the name) unless ``link_to_name`` is True. :param refcolumns: A sequence of foreign column names or Column objects. The columns must all be located within the same Table. :param name: Optional, the in-database name of the key. :param onupdate: Optional string. If set, emit ON UPDATE <value> when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. :param ondelete: Optional string. If set, emit ON DELETE <value> when issuing DDL for this constraint. Typical values include CASCADE, DELETE and RESTRICT. :param deferrable: Optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when issuing DDL for this constraint. :param initially: Optional string. If set, emit INITIALLY <value> when issuing DDL for this constraint. :param link_to_name: if True, the string name given in ``column`` is the rendered name of the referenced column, not its locally assigned ``key``. :param use_alter: If True, do not emit the DDL for this constraint as part of the CREATE TABLE definition. Instead, generate it via an ALTER TABLE statement issued after the full collection of tables have been created, and drop it via an ALTER TABLE statement before the full collection of tables are dropped. The use of :paramref:`.ForeignKeyConstraint.use_alter` is particularly geared towards the case where two or more tables are established within a mutually-dependent foreign key constraint relationship; however, the :meth:`.MetaData.create_all` and :meth:`.MetaData.drop_all` methods will perform this resolution automatically, so the flag is normally not needed. .. versionchanged:: 1.0.0 Automatic resolution of foreign key cycles has been added, removing the need to use the :paramref:`.ForeignKeyConstraint.use_alter` in typical use cases. .. seealso:: :ref:`use_alter` :param match: Optional string. If set, emit MATCH <value> when issuing DDL for this constraint. Typical values include SIMPLE, PARTIAL and FULL. :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. .. versionadded:: 1.0.0 :param \**dialect_kw: Additional keyword arguments are dialect specific, and passed in the form ``<dialectname>_<argname>``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. .. versionadded:: 0.9.2 """ Constraint.__init__( self, name=name, deferrable=deferrable, initially=initially, info=info, **dialect_kw) self.onupdate = onupdate self.ondelete = ondelete self.link_to_name = link_to_name self.use_alter = use_alter self.match = match # standalone ForeignKeyConstraint - create # associated ForeignKey objects which will be applied to hosted # Column objects (in col.foreign_keys), either now or when attached # to the Table for string-specified names self.elements = [ ForeignKey( refcol, _constraint=self, name=self.name, onupdate=self.onupdate, ondelete=self.ondelete, use_alter=self.use_alter, link_to_name=self.link_to_name, match=self.match, deferrable=self.deferrable, initially=self.initially, **self.dialect_kwargs ) for refcol in refcolumns ] ColumnCollectionMixin.__init__(self, *columns) if table is not None: if hasattr(self, "parent"): assert table is self.parent self._set_parent_with_dispatch(table) def _append_element(self, column, fk): self.columns.add(column) self.elements.append(fk) @property def _elements(self): # legacy - provide a dictionary view of (column_key, fk) return util.OrderedDict( zip(self.column_keys, self.elements) ) @property def _referred_schema(self): for elem in self.elements: return elem._referred_schema else: return None @property def referred_table(self): """The :class:`.Table` object to which this :class:`.ForeignKeyConstraint` references. This is a dynamically calculated attribute which may not be available if the constraint and/or parent table is not yet associated with a metadata collection that contains the referred table. .. versionadded:: 1.0.0 """ return self.elements[0].column.table def _validate_dest_table(self, table): table_keys = set([elem._table_key() for elem in self.elements]) if None not in table_keys and len(table_keys) > 1: elem0, elem1 = sorted(table_keys)[0:2] raise exc.ArgumentError( 'ForeignKeyConstraint on %s(%s) refers to ' 'multiple remote tables: %s and %s' % ( table.fullname, self._col_description, elem0, elem1 )) @property def column_keys(self): """Return a list of string keys representing the local columns in this :class:`.ForeignKeyConstraint`. This list is either the original string arguments sent to the constructor of the :class:`.ForeignKeyConstraint`, or if the constraint has been initialized with :class:`.Column` objects, is the string .key of each element. .. versionadded:: 1.0.0 """ if hasattr(self, "parent"): return self.columns.keys() else: return [ col.key if isinstance(col, ColumnElement) else str(col) for col in self._pending_colargs ] @property def _col_description(self): return ", ".join(self.column_keys) def _set_parent(self, table): Constraint._set_parent(self, table) try: ColumnCollectionConstraint._set_parent(self, table) except KeyError as ke: raise exc.ArgumentError( "Can't create ForeignKeyConstraint " "on table '%s': no column " "named '%s' is present." % (table.description, ke.args[0])) for col, fk in zip(self.columns, self.elements): if not hasattr(fk, 'parent') or \ fk.parent is not col: fk._set_parent_with_dispatch(col) self._validate_dest_table(table) def copy(self, schema=None, target_table=None, **kw): fkc = ForeignKeyConstraint( [x.parent.key for x in self.elements], [x._get_colspec( schema=schema, table_name=target_table.name if target_table is not None and x._table_key() == x.parent.table.key else None) for x in self.elements], name=self.name, onupdate=self.onupdate, ondelete=self.ondelete, use_alter=self.use_alter, deferrable=self.deferrable, initially=self.initially, link_to_name=self.link_to_name, match=self.match ) for self_fk, other_fk in zip( self.elements, fkc.elements): self_fk._schema_item_copy(other_fk) return self._schema_item_copy(fkc) class PrimaryKeyConstraint(ColumnCollectionConstraint): """A table-level PRIMARY KEY constraint. The :class:`.PrimaryKeyConstraint` object is present automatically on any :class:`.Table` object; it is assigned a set of :class:`.Column` objects corresponding to those marked with the :paramref:`.Column.primary_key` flag:: >>> my_table = Table('mytable', metadata, ... Column('id', Integer, primary_key=True), ... Column('version_id', Integer, primary_key=True), ... Column('data', String(50)) ... ) >>> my_table.primary_key PrimaryKeyConstraint( Column('id', Integer(), table=<mytable>, primary_key=True, nullable=False), Column('version_id', Integer(), table=<mytable>, primary_key=True, nullable=False) ) The primary key of a :class:`.Table` can also be specified by using a :class:`.PrimaryKeyConstraint` object explicitly; in this mode of usage, the "name" of the constraint can also be specified, as well as other options which may be recognized by dialects:: my_table = Table('mytable', metadata, Column('id', Integer), Column('version_id', Integer), Column('data', String(50)), PrimaryKeyConstraint('id', 'version_id', name='mytable_pk') ) The two styles of column-specification should generally not be mixed. An warning is emitted if the columns present in the :class:`.PrimaryKeyConstraint` don't match the columns that were marked as ``primary_key=True``, if both are present; in this case, the columns are taken strictly from the :class:`.PrimaryKeyConstraint` declaration, and those columns otherwise marked as ``primary_key=True`` are ignored. This behavior is intended to be backwards compatible with previous behavior. .. versionchanged:: 0.9.2 Using a mixture of columns within a :class:`.PrimaryKeyConstraint` in addition to columns marked as ``primary_key=True`` now emits a warning if the lists don't match. The ultimate behavior of ignoring those columns marked with the flag only is currently maintained for backwards compatibility; this warning may raise an exception in a future release. For the use case where specific options are to be specified on the :class:`.PrimaryKeyConstraint`, but the usual style of using ``primary_key=True`` flags is still desirable, an empty :class:`.PrimaryKeyConstraint` may be specified, which will take on the primary key column collection from the :class:`.Table` based on the flags:: my_table = Table('mytable', metadata, Column('id', Integer, primary_key=True), Column('version_id', Integer, primary_key=True), Column('data', String(50)), PrimaryKeyConstraint(name='mytable_pk', mssql_clustered=True) ) .. versionadded:: 0.9.2 an empty :class:`.PrimaryKeyConstraint` may now be specified for the purposes of establishing keyword arguments with the constraint, independently of the specification of "primary key" columns within the :class:`.Table` itself; columns marked as ``primary_key=True`` will be gathered into the empty constraint's column collection. """ __visit_name__ = 'primary_key_constraint' def _set_parent(self, table): super(PrimaryKeyConstraint, self)._set_parent(table) if table.primary_key is not self: table.constraints.discard(table.primary_key) table.primary_key = self table.constraints.add(self) table_pks = [c for c in table.c if c.primary_key] if self.columns and table_pks and \ set(table_pks) != set(self.columns.values()): util.warn( "Table '%s' specifies columns %s as primary_key=True, " "not matching locally specified columns %s; setting the " "current primary key columns to %s. This warning " "may become an exception in a future release" % ( table.name, ", ".join("'%s'" % c.name for c in table_pks), ", ".join("'%s'" % c.name for c in self.columns), ", ".join("'%s'" % c.name for c in self.columns) ) ) table_pks[:] = [] for c in self.columns: c.primary_key = True c.nullable = False self.columns.extend(table_pks) def _reload(self, columns): """repopulate this :class:`.PrimaryKeyConstraint` given a set of columns. Existing columns in the table that are marked as primary_key=True are maintained. Also fires a new event. This is basically like putting a whole new :class:`.PrimaryKeyConstraint` object on the parent :class:`.Table` object without actually replacing the object. The ordering of the given list of columns is also maintained; these columns will be appended to the list of columns after any which are already present. """ # set the primary key flag on new columns. # note any existing PK cols on the table also have their # flag still set. for col in columns: col.primary_key = True self.columns.extend(columns) self._set_parent_with_dispatch(self.table) def _replace(self, col): self.columns.replace(col) class UniqueConstraint(ColumnCollectionConstraint): """A table-level UNIQUE constraint. Defines a single column or composite UNIQUE constraint. For a no-frills, single column constraint, adding ``unique=True`` to the ``Column`` definition is a shorthand equivalent for an unnamed, single column UniqueConstraint. """ __visit_name__ = 'unique_constraint' class Index(DialectKWArgs, ColumnCollectionMixin, SchemaItem): """A table-level INDEX. Defines a composite (one or more column) INDEX. E.g.:: sometable = Table("sometable", metadata, Column("name", String(50)), Column("address", String(100)) ) Index("some_index", sometable.c.name) For a no-frills, single column index, adding :class:`.Column` also supports ``index=True``:: sometable = Table("sometable", metadata, Column("name", String(50), index=True) ) For a composite index, multiple columns can be specified:: Index("some_index", sometable.c.name, sometable.c.address) Functional indexes are supported as well, typically by using the :data:`.func` construct in conjunction with table-bound :class:`.Column` objects:: Index("some_index", func.lower(sometable.c.name)) .. versionadded:: 0.8 support for functional and expression-based indexes. An :class:`.Index` can also be manually associated with a :class:`.Table`, either through inline declaration or using :meth:`.Table.append_constraint`. When this approach is used, the names of the indexed columns can be specified as strings:: Table("sometable", metadata, Column("name", String(50)), Column("address", String(100)), Index("some_index", "name", "address") ) To support functional or expression-based indexes in this form, the :func:`.text` construct may be used:: from sqlalchemy import text Table("sometable", metadata, Column("name", String(50)), Column("address", String(100)), Index("some_index", text("lower(name)")) ) .. versionadded:: 0.9.5 the :func:`.text` construct may be used to specify :class:`.Index` expressions, provided the :class:`.Index` is explicitly associated with the :class:`.Table`. .. seealso:: :ref:`schema_indexes` - General information on :class:`.Index`. :ref:`postgresql_indexes` - PostgreSQL-specific options available for the :class:`.Index` construct. :ref:`mysql_indexes` - MySQL-specific options available for the :class:`.Index` construct. :ref:`mssql_indexes` - MSSQL-specific options available for the :class:`.Index` construct. """ __visit_name__ = 'index' def __init__(self, name, *expressions, **kw): """Construct an index object. :param name: The name of the index :param \*expressions: Column expressions to include in the index. The expressions are normally instances of :class:`.Column`, but may also be arbitrary SQL expressions which ultimately refer to a :class:`.Column`. :param unique=False: Keyword only argument; if True, create a unique index. :param quote=None: Keyword only argument; whether to apply quoting to the name of the index. Works in the same manner as that of :paramref:`.Column.quote`. :param info=None: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. .. versionadded:: 1.0.0 :param \**kw: Additional keyword arguments not mentioned above are dialect specific, and passed in the form ``<dialectname>_<argname>``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. """ self.table = None columns = [] for expr, column, strname, add_element in self.\ _extract_col_expression_collection(expressions): if add_element is not None: columns.append(add_element) self.expressions = expressions self.name = quoted_name(name, kw.pop("quote", None)) self.unique = kw.pop('unique', False) if 'info' in kw: self.info = kw.pop('info') self._validate_dialect_kwargs(kw) # will call _set_parent() if table-bound column # objects are present ColumnCollectionMixin.__init__(self, *columns) def _set_parent(self, table): ColumnCollectionMixin._set_parent(self, table) if self.table is not None and table is not self.table: raise exc.ArgumentError( "Index '%s' is against table '%s', and " "cannot be associated with table '%s'." % ( self.name, self.table.description, table.description ) ) self.table = table table.indexes.add(self) self.expressions = [ expr if isinstance(expr, ClauseElement) else colexpr for expr, colexpr in util.zip_longest(self.expressions, self.columns) ] @property def bind(self): """Return the connectable associated with this Index.""" return self.table.bind def create(self, bind=None): """Issue a ``CREATE`` statement for this :class:`.Index`, using the given :class:`.Connectable` for connectivity. .. seealso:: :meth:`.MetaData.create_all`. """ if bind is None: bind = _bind_or_error(self) bind._run_visitor(ddl.SchemaGenerator, self) return self def drop(self, bind=None): """Issue a ``DROP`` statement for this :class:`.Index`, using the given :class:`.Connectable` for connectivity. .. seealso:: :meth:`.MetaData.drop_all`. """ if bind is None: bind = _bind_or_error(self) bind._run_visitor(ddl.SchemaDropper, self) def __repr__(self): return 'Index(%s)' % ( ", ".join( [repr(self.name)] + [repr(e) for e in self.expressions] + (self.unique and ["unique=True"] or []) )) DEFAULT_NAMING_CONVENTION = util.immutabledict({ "ix": 'ix_%(column_0_label)s' }) class MetaData(SchemaItem): """A collection of :class:`.Table` objects and their associated schema constructs. Holds a collection of :class:`.Table` objects as well as an optional binding to an :class:`.Engine` or :class:`.Connection`. If bound, the :class:`.Table` objects in the collection and their columns may participate in implicit SQL execution. The :class:`.Table` objects themselves are stored in the :attr:`.MetaData.tables` dictionary. :class:`.MetaData` is a thread-safe object for read operations. Construction of new tables within a single :class:`.MetaData` object, either explicitly or via reflection, may not be completely thread-safe. .. seealso:: :ref:`metadata_describing` - Introduction to database metadata """ __visit_name__ = 'metadata' def __init__(self, bind=None, reflect=False, schema=None, quote_schema=None, naming_convention=DEFAULT_NAMING_CONVENTION, info=None ): """Create a new MetaData object. :param bind: An Engine or Connection to bind to. May also be a string or URL instance, these are passed to create_engine() and this MetaData will be bound to the resulting engine. :param reflect: Optional, automatically load all tables from the bound database. Defaults to False. ``bind`` is required when this option is set. .. deprecated:: 0.8 Please use the :meth:`.MetaData.reflect` method. :param schema: The default schema to use for the :class:`.Table`, :class:`.Sequence`, and potentially other objects associated with this :class:`.MetaData`. Defaults to ``None``. When this value is set, any :class:`.Table` or :class:`.Sequence` which specifies ``None`` for the schema parameter will instead have this schema name defined. To build a :class:`.Table` or :class:`.Sequence` that still has ``None`` for the schema even when this parameter is present, use the :attr:`.BLANK_SCHEMA` symbol. .. seealso:: :paramref:`.Table.schema` :paramref:`.Sequence.schema` :param quote_schema: Sets the ``quote_schema`` flag for those :class:`.Table`, :class:`.Sequence`, and other objects which make usage of the local ``schema`` name. :param info: Optional data dictionary which will be populated into the :attr:`.SchemaItem.info` attribute of this object. .. versionadded:: 1.0.0 :param naming_convention: a dictionary referring to values which will establish default naming conventions for :class:`.Constraint` and :class:`.Index` objects, for those objects which are not given a name explicitly. The keys of this dictionary may be: * a constraint or Index class, e.g. the :class:`.UniqueConstraint`, :class:`.ForeignKeyConstraint` class, the :class:`.Index` class * a string mnemonic for one of the known constraint classes; ``"fk"``, ``"pk"``, ``"ix"``, ``"ck"``, ``"uq"`` for foreign key, primary key, index, check, and unique constraint, respectively. * the string name of a user-defined "token" that can be used to define new naming tokens. The values associated with each "constraint class" or "constraint mnemonic" key are string naming templates, such as ``"uq_%(table_name)s_%(column_0_name)s"``, which describe how the name should be composed. The values associated with user-defined "token" keys should be callables of the form ``fn(constraint, table)``, which accepts the constraint/index object and :class:`.Table` as arguments, returning a string result. The built-in names are as follows, some of which may only be available for certain types of constraint: * ``%(table_name)s`` - the name of the :class:`.Table` object associated with the constraint. * ``%(referred_table_name)s`` - the name of the :class:`.Table` object associated with the referencing target of a :class:`.ForeignKeyConstraint`. * ``%(column_0_name)s`` - the name of the :class:`.Column` at index position "0" within the constraint. * ``%(column_0_label)s`` - the label of the :class:`.Column` at index position "0", e.g. :attr:`.Column.label` * ``%(column_0_key)s`` - the key of the :class:`.Column` at index position "0", e.g. :attr:`.Column.key` * ``%(referred_column_0_name)s`` - the name of a :class:`.Column` at index position "0" referenced by a :class:`.ForeignKeyConstraint`. * ``%(constraint_name)s`` - a special key that refers to the existing name given to the constraint. When this key is present, the :class:`.Constraint` object's existing name will be replaced with one that is composed from template string that uses this token. When this token is present, it is required that the :class:`.Constraint` is given an expicit name ahead of time. * user-defined: any additional token may be implemented by passing it along with a ``fn(constraint, table)`` callable to the naming_convention dictionary. .. versionadded:: 0.9.2 .. seealso:: :ref:`constraint_naming_conventions` - for detailed usage examples. """ self.tables = util.immutabledict() self.schema = quoted_name(schema, quote_schema) self.naming_convention = naming_convention if info: self.info = info self._schemas = set() self._sequences = {} self._fk_memos = collections.defaultdict(list) self.bind = bind if reflect: util.warn_deprecated("reflect=True is deprecate; please " "use the reflect() method.") if not bind: raise exc.ArgumentError( "A bind must be supplied in conjunction " "with reflect=True") self.reflect() tables = None """A dictionary of :class:`.Table` objects keyed to their name or "table key". The exact key is that determined by the :attr:`.Table.key` attribute; for a table with no :attr:`.Table.schema` attribute, this is the same as :attr:`.Table.name`. For a table with a schema, it is typically of the form ``schemaname.tablename``. .. seealso:: :attr:`.MetaData.sorted_tables` """ def __repr__(self): return 'MetaData(bind=%r)' % self.bind def __contains__(self, table_or_key): if not isinstance(table_or_key, util.string_types): table_or_key = table_or_key.key return table_or_key in self.tables def _add_table(self, name, schema, table): key = _get_table_key(name, schema) dict.__setitem__(self.tables, key, table) if schema: self._schemas.add(schema) def _remove_table(self, name, schema): key = _get_table_key(name, schema) removed = dict.pop(self.tables, key, None) if removed is not None: for fk in removed.foreign_keys: fk._remove_from_metadata(self) if self._schemas: self._schemas = set([t.schema for t in self.tables.values() if t.schema is not None]) def __getstate__(self): return {'tables': self.tables, 'schema': self.schema, 'schemas': self._schemas, 'sequences': self._sequences, 'fk_memos': self._fk_memos, 'naming_convention': self.naming_convention } def __setstate__(self, state): self.tables = state['tables'] self.schema = state['schema'] self.naming_convention = state['naming_convention'] self._bind = None self._sequences = state['sequences'] self._schemas = state['schemas'] self._fk_memos = state['fk_memos'] def is_bound(self): """True if this MetaData is bound to an Engine or Connection.""" return self._bind is not None def bind(self): """An :class:`.Engine` or :class:`.Connection` to which this :class:`.MetaData` is bound. Typically, a :class:`.Engine` is assigned to this attribute so that "implicit execution" may be used, or alternatively as a means of providing engine binding information to an ORM :class:`.Session` object:: engine = create_engine("someurl://") metadata.bind = engine .. seealso:: :ref:`dbengine_implicit` - background on "bound metadata" """ return self._bind @util.dependencies("sqlalchemy.engine.url") def _bind_to(self, url, bind): """Bind this MetaData to an Engine, Connection, string or URL.""" if isinstance(bind, util.string_types + (url.URL, )): self._bind = sqlalchemy.create_engine(bind) else: self._bind = bind bind = property(bind, _bind_to) def clear(self): """Clear all Table objects from this MetaData.""" dict.clear(self.tables) self._schemas.clear() self._fk_memos.clear() def remove(self, table): """Remove the given Table object from this MetaData.""" self._remove_table(table.name, table.schema) @property def sorted_tables(self): """Returns a list of :class:`.Table` objects sorted in order of foreign key dependency. The sorting will place :class:`.Table` objects that have dependencies first, before the dependencies themselves, representing the order in which they can be created. To get the order in which the tables would be dropped, use the ``reversed()`` Python built-in. .. warning:: The :attr:`.sorted_tables` accessor cannot by itself accommodate automatic resolution of dependency cycles between tables, which are usually caused by mutually dependent foreign key constraints. To resolve these cycles, either the :paramref:`.ForeignKeyConstraint.use_alter` parameter may be appled to those constraints, or use the :func:`.schema.sort_tables_and_constraints` function which will break out foreign key constraints involved in cycles separately. .. seealso:: :func:`.schema.sort_tables` :func:`.schema.sort_tables_and_constraints` :attr:`.MetaData.tables` :meth:`.Inspector.get_table_names` :meth:`.Inspector.get_sorted_table_and_fkc_names` """ return ddl.sort_tables(sorted(self.tables.values(), key=lambda t: t.key)) def reflect(self, bind=None, schema=None, views=False, only=None, extend_existing=False, autoload_replace=True, **dialect_kwargs): """Load all available table definitions from the database. Automatically creates ``Table`` entries in this ``MetaData`` for any table available in the database but not yet present in the ``MetaData``. May be called multiple times to pick up tables recently added to the database, however no special action is taken if a table in this ``MetaData`` no longer exists in the database. :param bind: A :class:`.Connectable` used to access the database; if None, uses the existing bind on this ``MetaData``, if any. :param schema: Optional, query and reflect tables from an alterate schema. If None, the schema associated with this :class:`.MetaData` is used, if any. :param views: If True, also reflect views. :param only: Optional. Load only a sub-set of available named tables. May be specified as a sequence of names or a callable. If a sequence of names is provided, only those tables will be reflected. An error is raised if a table is requested but not available. Named tables already present in this ``MetaData`` are ignored. If a callable is provided, it will be used as a boolean predicate to filter the list of potential table names. The callable is called with a table name and this ``MetaData`` instance as positional arguments and should return a true value for any table to reflect. :param extend_existing: Passed along to each :class:`.Table` as :paramref:`.Table.extend_existing`. .. versionadded:: 0.9.1 :param autoload_replace: Passed along to each :class:`.Table` as :paramref:`.Table.autoload_replace`. .. versionadded:: 0.9.1 :param \**dialect_kwargs: Additional keyword arguments not mentioned above are dialect specific, and passed in the form ``<dialectname>_<argname>``. See the documentation regarding an individual dialect at :ref:`dialect_toplevel` for detail on documented arguments. .. versionadded:: 0.9.2 - Added :paramref:`.MetaData.reflect.**dialect_kwargs` to support dialect-level reflection options for all :class:`.Table` objects reflected. """ if bind is None: bind = _bind_or_error(self) with bind.connect() as conn: reflect_opts = { 'autoload': True, 'autoload_with': conn, 'extend_existing': extend_existing, 'autoload_replace': autoload_replace } reflect_opts.update(dialect_kwargs) if schema is None: schema = self.schema if schema is not None: reflect_opts['schema'] = schema available = util.OrderedSet( bind.engine.table_names(schema, connection=conn)) if views: available.update( bind.dialect.get_view_names(conn, schema) ) if schema is not None: available_w_schema = util.OrderedSet(["%s.%s" % (schema, name) for name in available]) else: available_w_schema = available current = set(self.tables) if only is None: load = [name for name, schname in zip(available, available_w_schema) if extend_existing or schname not in current] elif util.callable(only): load = [name for name, schname in zip(available, available_w_schema) if (extend_existing or schname not in current) and only(name, self)] else: missing = [name for name in only if name not in available] if missing: s = schema and (" schema '%s'" % schema) or '' raise exc.InvalidRequestError( 'Could not reflect: requested table(s) not available ' 'in %s%s: (%s)' % (bind.engine.url, s, ', '.join(missing))) load = [name for name in only if extend_existing or name not in current] for name in load: Table(name, self, **reflect_opts) def append_ddl_listener(self, event_name, listener): """Append a DDL event listener to this ``MetaData``. .. deprecated:: 0.7 See :class:`.DDLEvents`. """ def adapt_listener(target, connection, **kw): tables = kw['tables'] listener(event, target, connection, tables=tables) event.listen(self, "" + event_name.replace('-', '_'), adapt_listener) def create_all(self, bind=None, tables=None, checkfirst=True): """Create all tables stored in this metadata. Conditional by default, will not attempt to recreate tables already present in the target database. :param bind: A :class:`.Connectable` used to access the database; if None, uses the existing bind on this ``MetaData``, if any. :param tables: Optional list of ``Table`` objects, which is a subset of the total tables in the ``MetaData`` (others are ignored). :param checkfirst: Defaults to True, don't issue CREATEs for tables already present in the target database. """ if bind is None: bind = _bind_or_error(self) bind._run_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst, tables=tables) def drop_all(self, bind=None, tables=None, checkfirst=True): """Drop all tables stored in this metadata. Conditional by default, will not attempt to drop tables not present in the target database. :param bind: A :class:`.Connectable` used to access the database; if None, uses the existing bind on this ``MetaData``, if any. :param tables: Optional list of ``Table`` objects, which is a subset of the total tables in the ``MetaData`` (others are ignored). :param checkfirst: Defaults to True, only issue DROPs for tables confirmed to be present in the target database. """ if bind is None: bind = _bind_or_error(self) bind._run_visitor(ddl.SchemaDropper, self, checkfirst=checkfirst, tables=tables) class ThreadLocalMetaData(MetaData): """A MetaData variant that presents a different ``bind`` in every thread. Makes the ``bind`` property of the MetaData a thread-local value, allowing this collection of tables to be bound to different ``Engine`` implementations or connections in each thread. The ThreadLocalMetaData starts off bound to None in each thread. Binds must be made explicitly by assigning to the ``bind`` property or using ``connect()``. You can also re-bind dynamically multiple times per thread, just like a regular ``MetaData``. """ __visit_name__ = 'metadata' def __init__(self): """Construct a ThreadLocalMetaData.""" self.context = util.threading.local() self.__engines = {} super(ThreadLocalMetaData, self).__init__() def bind(self): """The bound Engine or Connection for this thread. This property may be assigned an Engine or Connection, or assigned a string or URL to automatically create a basic Engine for this bind with ``create_engine()``.""" return getattr(self.context, '_engine', None) @util.dependencies("sqlalchemy.engine.url") def _bind_to(self, url, bind): """Bind to a Connectable in the caller's thread.""" if isinstance(bind, util.string_types + (url.URL, )): try: self.context._engine = self.__engines[bind] except KeyError: e = sqlalchemy.create_engine(bind) self.__engines[bind] = e self.context._engine = e else: # TODO: this is squirrely. we shouldn't have to hold onto engines # in a case like this if bind not in self.__engines: self.__engines[bind] = bind self.context._engine = bind bind = property(bind, _bind_to) def is_bound(self): """True if there is a bind for this thread.""" return (hasattr(self.context, '_engine') and self.context._engine is not None) def dispose(self): """Dispose all bound engines, in all thread contexts.""" for e in self.__engines.values(): if hasattr(e, 'dispose'): e.dispose()
mit
[ 3, 3875, 15, 3629, 14, 647, 199, 3, 1898, 334, 35, 9, 11811, 13, 9261, 314, 14303, 11462, 436, 8417, 199, 3, 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, 1918, 4177, 859, 6571, 314, 10015, 5664, 367, 3050, 3341, 14, 199, 199, 22321, 1819, 4453, 642, 859, 23369, 282, 3050, 4642, 1314, 883, 506, 199, 3966, 436, 17481, 12, 503, 365, 4257, 1777, 402, 4066, 376, 4642, 14, 221, 6058, 2387, 199, 5987, 12, 4362, 12, 8013, 12, 436, 10507, 14, 199, 199, 2422, 9045, 787, 9180, 402, 520, 533, 6054, 14536, 14, 3629, 14, 6700, 2081, 3559, 436, 465, 199, 4037, 315, 642, 859, 2985, 787, 11619, 370, 506, 282, 784, 941, 530, 402, 1263, 20868, 13, 6100, 199, 8514, 83, 14, 199, 199, 33, 3245, 402, 9045, 787, 16251, 1901, 282, 4137, 2797, 199, 26, 533, 6054, 14536, 14, 3629, 14, 25285, 2313, 24905, 23739, 465, 282, 11461, 17786, 402, 199, 3629, 4008, 12, 436, 883, 2597, 506, 4568, 543, 376, 3503, 3050, 1950, 199, 10180, 626, 5331, 25613, 4007, 314, 10470, 4008, 883, 8966, 314, 3050, 199, 305, 4346, 14, 199, 199, 11467, 402, 314, 4008, 2348, 2597, 1900, 12188, 3932, 298, 1786, 343, 27296, 2, 7055, 4181, 12, 1314, 199, 1530, 3247, 315, 520, 533, 6054, 14536, 14, 3009, 14, 5599, 14, 3559, 22543, 199, 26, 533, 6054, 14536, 14, 3629, 14, 3186, 64, 436, 520, 533, 6054, 14536, 14, 3629, 14, 4547, 2313, 199, 24430, 3520, 2251, 787, 1777, 402, 314, 5385, 3965, 2637, 12, 2985, 787, 18025, 199, 305, 7323, 315, 5385, 8455, 14, 199, 199, 624, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 6485, 199, 504, 2508, 492, 3178, 12, 4884, 12, 1566, 12, 5261, 10303, 199, 504, 1275, 1095, 492, 13268, 2390, 4277, 12, 3757, 9062, 25114, 6213, 199, 504, 1275, 492, 5684, 1384, 199, 504, 1275, 492, 730, 63, 1246, 199, 504, 1275, 1095, 492, 485, 3409, 63, 269, 63, 705, 12, 4996, 7768, 199, 504, 1275, 5527, 492, 24433, 1180, 2162, 12, 4996, 16009, 12, 485, 19347, 63, 1302, 12, 971, 272, 485, 305, 63, 19347, 12, 4516, 16009, 12, 485, 8939, 63, 305, 63, 505, 4202, 272, 4996, 2162, 12, 485, 1623, 63, 3406, 12, 10999, 63, 354, 199, 504, 1275, 18837, 492, 6957, 16009, 199, 646, 5055, 199, 646, 8335, 199, 504, 1275, 492, 366, 5030, 199, 646, 2943, 199, 199, 7341, 9021, 63, 10926, 275, 4884, 14, 5155, 360, 264, 877, 63, 3629, 358, 199, 199, 20438, 63, 10926, 275, 4884, 14, 5155, 8, 272, 283, 2500, 63, 3629, 297, 272, 408, 8169, 9297, 626, 282, 520, 533, 5026, 3186, 64, 503, 520, 533, 5026, 5826, 64, 272, 1077, 1172, 283, 403, 7, 367, 2399, 4177, 12, 2755, 340, 314, 1676, 272, 520, 533, 5026, 25285, 64, 965, 2013, 282, 4177, 14, 339, 2508, 7445, 447, 413, 14, 16, 14, 1079, 339, 408, 199, 9, 421, 199, 318, 485, 362, 63, 1224, 63, 498, 8, 354, 12, 4177, 304, 272, 340, 4177, 365, 488, 26, 267, 372, 536, 272, 587, 26, 267, 372, 4177, 435, 14530, 435, 536, 421, 199, 32, 25098, 423, 277, 63, 10955, 83, 199, 533, 13268, 2081, 8, 6700, 2390, 4277, 12, 5684, 1384, 14, 2201, 338, 1224, 304, 272, 408, 1563, 1021, 367, 2974, 626, 5627, 282, 3050, 4177, 1041, 339, 636, 5427, 63, 354, 363, 275, 283, 3629, 63, 1053, 7, 339, 347, 485, 2526, 63, 265, 63, 2105, 8, 277, 12, 1950, 12, 3510, 1162, 12, 1862, 304, 267, 372, 1950, 423, 2526, 63, 885, 8, 277, 12, 3510, 1162, 12, 1862, 9, 339, 347, 485, 826, 63, 1744, 8, 277, 12, 627, 589, 304, 267, 408, 9345, 314, 769, 402, 1982, 2974, 367, 642, 13268, 2081, 1041, 398, 367, 1242, 315, 1249, 26, 288, 340, 1242, 365, 440, 488, 26, 355, 1242, 423, 409, 63, 1708, 63, 1045, 63, 6052, 8, 277, 9, 339, 347, 664, 63, 3223, 8, 277, 12, 1011, 958, 304, 267, 408, 2972, 370, 2040, 13268, 18324, 2879, 624, 267, 372, 942, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 4884, 14, 6767, 63, 2722, 8, 277, 12, 19413, 63, 12745, 2968, 815, 1105, 339, 768, 1829, 272, 768, 1974, 14, 6667, 360, 16, 14, 25, 297, 283, 6119, 23696, 1113, 10827, 354, 14, 3513, 1040, 358, 272, 347, 6313, 8, 277, 304, 267, 408, 1767, 314, 574, 402, 314, 1124, 3513, 1040, 3305, 3032, 267, 370, 642, 4177, 909, 12, 367, 5204, 4177, 2974, 1314, 267, 1172, 282, 1124, 354, 1040, 901, 14, 398, 408, 398, 372, 291, 14, 354, 14, 3513, 339, 768, 1974, 14, 20457, 63, 1829, 272, 347, 2256, 8, 277, 304, 267, 408, 2354, 2600, 4568, 543, 314, 909, 12, 17266, 922, 13, 4037, 267, 666, 370, 506, 4568, 543, 642, 520, 533, 5026, 6700, 2081, 2313, 398, 710, 2600, 365, 5847, 4046, 1380, 1642, 13810, 14, 267, 2779, 883, 2597, 506, 2013, 315, 314, 3787, 402, 2005, 2251, 12, 267, 4066, 465, 520, 533, 5026, 3186, 64, 436, 520, 533, 5026, 4547, 2313, 398, 408, 267, 372, 1052, 339, 347, 485, 3629, 63, 1053, 63, 1574, 8, 277, 12, 4177, 63, 1053, 304, 267, 340, 283, 815, 7, 315, 291, 855, 807, 10651, 288, 4177, 63, 1053, 14, 815, 275, 291, 14, 815, 14, 1574, 342, 267, 4177, 63, 1053, 14, 6052, 423, 873, 8, 277, 14, 6052, 9, 267, 372, 4177, 63, 1053, 421, 199, 533, 6957, 8, 22080, 25114, 6213, 12, 13268, 2081, 12, 6957, 16009, 304, 272, 408, 10755, 282, 1817, 315, 282, 3050, 14, 339, 325, 14, 71, 28383, 398, 3002, 1224, 275, 6957, 480, 1662, 1224, 401, 3341, 12, 717, 4996, 360, 1662, 1224, 63, 344, 297, 7225, 12, 5062, 63, 498, 29, 549, 395, 717, 4996, 360, 585, 297, 2624, 8, 1400, 430, 673, 776, 339, 710, 520, 533, 5026, 3186, 64, 909, 21638, 282, 3747, 1256, 402, 6337, 4079, 272, 641, 2399, 536, 436 ]
[ 3875, 15, 3629, 14, 647, 199, 3, 1898, 334, 35, 9, 11811, 13, 9261, 314, 14303, 11462, 436, 8417, 199, 3, 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, 1918, 4177, 859, 6571, 314, 10015, 5664, 367, 3050, 3341, 14, 199, 199, 22321, 1819, 4453, 642, 859, 23369, 282, 3050, 4642, 1314, 883, 506, 199, 3966, 436, 17481, 12, 503, 365, 4257, 1777, 402, 4066, 376, 4642, 14, 221, 6058, 2387, 199, 5987, 12, 4362, 12, 8013, 12, 436, 10507, 14, 199, 199, 2422, 9045, 787, 9180, 402, 520, 533, 6054, 14536, 14, 3629, 14, 6700, 2081, 3559, 436, 465, 199, 4037, 315, 642, 859, 2985, 787, 11619, 370, 506, 282, 784, 941, 530, 402, 1263, 20868, 13, 6100, 199, 8514, 83, 14, 199, 199, 33, 3245, 402, 9045, 787, 16251, 1901, 282, 4137, 2797, 199, 26, 533, 6054, 14536, 14, 3629, 14, 25285, 2313, 24905, 23739, 465, 282, 11461, 17786, 402, 199, 3629, 4008, 12, 436, 883, 2597, 506, 4568, 543, 376, 3503, 3050, 1950, 199, 10180, 626, 5331, 25613, 4007, 314, 10470, 4008, 883, 8966, 314, 3050, 199, 305, 4346, 14, 199, 199, 11467, 402, 314, 4008, 2348, 2597, 1900, 12188, 3932, 298, 1786, 343, 27296, 2, 7055, 4181, 12, 1314, 199, 1530, 3247, 315, 520, 533, 6054, 14536, 14, 3009, 14, 5599, 14, 3559, 22543, 199, 26, 533, 6054, 14536, 14, 3629, 14, 3186, 64, 436, 520, 533, 6054, 14536, 14, 3629, 14, 4547, 2313, 199, 24430, 3520, 2251, 787, 1777, 402, 314, 5385, 3965, 2637, 12, 2985, 787, 18025, 199, 305, 7323, 315, 5385, 8455, 14, 199, 199, 624, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 646, 6485, 199, 504, 2508, 492, 3178, 12, 4884, 12, 1566, 12, 5261, 10303, 199, 504, 1275, 1095, 492, 13268, 2390, 4277, 12, 3757, 9062, 25114, 6213, 199, 504, 1275, 492, 5684, 1384, 199, 504, 1275, 492, 730, 63, 1246, 199, 504, 1275, 1095, 492, 485, 3409, 63, 269, 63, 705, 12, 4996, 7768, 199, 504, 1275, 5527, 492, 24433, 1180, 2162, 12, 4996, 16009, 12, 485, 19347, 63, 1302, 12, 971, 272, 485, 305, 63, 19347, 12, 4516, 16009, 12, 485, 8939, 63, 305, 63, 505, 4202, 272, 4996, 2162, 12, 485, 1623, 63, 3406, 12, 10999, 63, 354, 199, 504, 1275, 18837, 492, 6957, 16009, 199, 646, 5055, 199, 646, 8335, 199, 504, 1275, 492, 366, 5030, 199, 646, 2943, 199, 199, 7341, 9021, 63, 10926, 275, 4884, 14, 5155, 360, 264, 877, 63, 3629, 358, 199, 199, 20438, 63, 10926, 275, 4884, 14, 5155, 8, 272, 283, 2500, 63, 3629, 297, 272, 408, 8169, 9297, 626, 282, 520, 533, 5026, 3186, 64, 503, 520, 533, 5026, 5826, 64, 272, 1077, 1172, 283, 403, 7, 367, 2399, 4177, 12, 2755, 340, 314, 1676, 272, 520, 533, 5026, 25285, 64, 965, 2013, 282, 4177, 14, 339, 2508, 7445, 447, 413, 14, 16, 14, 1079, 339, 408, 199, 9, 421, 199, 318, 485, 362, 63, 1224, 63, 498, 8, 354, 12, 4177, 304, 272, 340, 4177, 365, 488, 26, 267, 372, 536, 272, 587, 26, 267, 372, 4177, 435, 14530, 435, 536, 421, 199, 32, 25098, 423, 277, 63, 10955, 83, 199, 533, 13268, 2081, 8, 6700, 2390, 4277, 12, 5684, 1384, 14, 2201, 338, 1224, 304, 272, 408, 1563, 1021, 367, 2974, 626, 5627, 282, 3050, 4177, 1041, 339, 636, 5427, 63, 354, 363, 275, 283, 3629, 63, 1053, 7, 339, 347, 485, 2526, 63, 265, 63, 2105, 8, 277, 12, 1950, 12, 3510, 1162, 12, 1862, 304, 267, 372, 1950, 423, 2526, 63, 885, 8, 277, 12, 3510, 1162, 12, 1862, 9, 339, 347, 485, 826, 63, 1744, 8, 277, 12, 627, 589, 304, 267, 408, 9345, 314, 769, 402, 1982, 2974, 367, 642, 13268, 2081, 1041, 398, 367, 1242, 315, 1249, 26, 288, 340, 1242, 365, 440, 488, 26, 355, 1242, 423, 409, 63, 1708, 63, 1045, 63, 6052, 8, 277, 9, 339, 347, 664, 63, 3223, 8, 277, 12, 1011, 958, 304, 267, 408, 2972, 370, 2040, 13268, 18324, 2879, 624, 267, 372, 942, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 4884, 14, 6767, 63, 2722, 8, 277, 12, 19413, 63, 12745, 2968, 815, 1105, 339, 768, 1829, 272, 768, 1974, 14, 6667, 360, 16, 14, 25, 297, 283, 6119, 23696, 1113, 10827, 354, 14, 3513, 1040, 358, 272, 347, 6313, 8, 277, 304, 267, 408, 1767, 314, 574, 402, 314, 1124, 3513, 1040, 3305, 3032, 267, 370, 642, 4177, 909, 12, 367, 5204, 4177, 2974, 1314, 267, 1172, 282, 1124, 354, 1040, 901, 14, 398, 408, 398, 372, 291, 14, 354, 14, 3513, 339, 768, 1974, 14, 20457, 63, 1829, 272, 347, 2256, 8, 277, 304, 267, 408, 2354, 2600, 4568, 543, 314, 909, 12, 17266, 922, 13, 4037, 267, 666, 370, 506, 4568, 543, 642, 520, 533, 5026, 6700, 2081, 2313, 398, 710, 2600, 365, 5847, 4046, 1380, 1642, 13810, 14, 267, 2779, 883, 2597, 506, 2013, 315, 314, 3787, 402, 2005, 2251, 12, 267, 4066, 465, 520, 533, 5026, 3186, 64, 436, 520, 533, 5026, 4547, 2313, 398, 408, 267, 372, 1052, 339, 347, 485, 3629, 63, 1053, 63, 1574, 8, 277, 12, 4177, 63, 1053, 304, 267, 340, 283, 815, 7, 315, 291, 855, 807, 10651, 288, 4177, 63, 1053, 14, 815, 275, 291, 14, 815, 14, 1574, 342, 267, 4177, 63, 1053, 14, 6052, 423, 873, 8, 277, 14, 6052, 9, 267, 372, 4177, 63, 1053, 421, 199, 533, 6957, 8, 22080, 25114, 6213, 12, 13268, 2081, 12, 6957, 16009, 304, 272, 408, 10755, 282, 1817, 315, 282, 3050, 14, 339, 325, 14, 71, 28383, 398, 3002, 1224, 275, 6957, 480, 1662, 1224, 401, 3341, 12, 717, 4996, 360, 1662, 1224, 63, 344, 297, 7225, 12, 5062, 63, 498, 29, 549, 395, 717, 4996, 360, 585, 297, 2624, 8, 1400, 430, 673, 776, 339, 710, 520, 533, 5026, 3186, 64, 909, 21638, 282, 3747, 1256, 402, 6337, 4079, 272, 641, 2399, 536, 436, 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,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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 ]
msikma/zembu.py
zembu.py
1
7381
#!/usr/bin/env python # coding=utf8 # # zembu.py 0.1 # Script that checks whether dictionary words are available as domain names. import subprocess import datetime import argparse import pprint import time import sys import os # Get current console size. ROWS, COLS = [int(n) for n in os.popen('stty size', 'r').read().split()] VERSION = '0.2' def rate_limited(max_per_second): ''' Decorator function to rate limit a function to run n times per second. Usage is as follows: @rate_limited(2) # 2 per second at most def my_function(n): print('hello %d' % n) # Takes 50 seconds to complete for n in range(100): my_function(n) Modified version of the following Stack Overflow answer: <http://stackoverflow.com/a/667706/3553425> ''' min_interval = 1.0 / float(max_per_second) def decorate(func): last_time_called = [0.0] def rate_limited_function(*args, **kargs): elapsed = time.clock() - last_time_called[0] left_to_wait = min_interval - elapsed if left_to_wait > 0: time.sleep(left_to_wait) ret = func(*args, **kargs) last_time_called[0] = time.clock() return ret return rate_limited_function return decorate def get_exec_unsafe(cmd, ignore_errors=False): ''' Returns the output of a subprocess command. NOTE: DO NOT PASS UNSANITIZED INPUT TO THIS FUNCTION. ''' try: return subprocess.check_output(cmd, shell=True).strip() except subprocess.CalledProcessError as e: if ignore_errors: return e.output.strip() else: return False def print_progress(curr, amount, domain, is_available): ''' Shows the current progress indicator as a percentage. ''' sys.stdout.write('\r{}'.format(' ' * ROWS)) sys.stdout.write('\r[{:7.3f}%] {}'.format( (float(curr) / amount) * 100, domain )) sys.stdout.flush() def get_dict_words(dict_file): ''' Extracts the individual words from a dictionary file, with whitespace stripped, and returns them as a list. ''' word_info = [] with open(dict_file) as file: words = [word.strip().lower() for word in file.readlines()] # If we've got semicolons, we're saving extra information # about the words. if ';' in words[0]: new_words = [] for word in words: slices = word.split(';') new_words.append(slices[0]) word_info.append(slices[1:]) words = new_words else: words = filter(None, words) # remove empty strings words = list(set(words)) # remove duplicates words.sort() return [words, word_info] @rate_limited(1) def check_domain(domain, verbose=False): if verbose: print('whois "%s"' % (domain)) output = get_exec_unsafe('whois "%s"' % (domain), ignore_errors=True) if output is False: return False if 'no match for' in output.lower(): return True else: return False def check_domains(words, word_info, tlds=['com'], log='zembu_output.log', verbose=False): ''' Iterates through a provided list of words and checks their availability as domain names with the given tld. ''' amount = len(words) * len(tlds) print('Checking %d domain names. This might take a while.' % amount) print('Upon completion, the results will be saved to %s.' % log) print('The escape sequence is ^C.') available = [] n = 0 for n in range(len(words)): word = words[n] info = word_info[n] for tld in tlds: domain = (word + '.' + tld).lower() is_available = check_domain(domain, verbose) if is_available: available.append(domain + ' (' + (', '.join(info)) + ')') n += 1 if not verbose: print_progress(n, amount, domain, is_available) return (amount, available) def is_writable(log): ''' Returns whether the log file can be opened for writing. ''' try: filehandle = open(log, 'w') filehandle.close() return True except IOError: return False def log_output(version, amount, available, words, duration, args, log): ''' Writes the results of the script to the log file. ''' available_list = '\n'.join(available) now = str(datetime.datetime.utcnow()) + ' UTC' settings = { 'version': version, 'duration': duration, 'checked': amount, 'words': len(words), 'available': len(available), 'options': args } print('\nThe following domains are available:\n%s' % available_list) print('Saving output to %s...' % log) with open(log, 'w') as file: file.write('zembu.py: %s:\n' % now) file.write(pprint.pformat(settings)) file.write('\n----\n') file.write(available_list) file.write('\n') print('Saved.') def main(): ''' Checks the user's command line input and runs the main program. ''' argparser = argparse.ArgumentParser(add_help=False) argparser.description = 'zembu.py: checks all entries in a list of words \ for domain availability' argparser.add_argument( '-h', '--help', action='help', help='Show this help message and exit.' ) argparser.add_argument( '-V', '--version', action='version', version='zembu.py: ' + VERSION, help='Show version number and exit.' ) argparser.add_argument( '--dict', action='store', default='/usr/share/dict/words', required=True, help='Path to the dictionary file to use. Must contain one word per ' 'line.' ) argparser.add_argument( '--tlds', action='store', default='com', help='Top-level domain to check, e.g. "com,net" to check "<word>.com" ' 'and "<word>.net". (Default: "com")' ) argparser.add_argument( '--verbose', action='store_true', default=False, help='Outputs all Whois commands we run. (Default: False)' ) argparser.add_argument( '--log-file', action='store', default='zembu_output.log', help='Saves a list of all available domain names to a text file. ' '(Default: "zembu_output.log")' ) args = argparser.parse_args() argdict = args.__dict__ words, word_info = get_dict_words(args.dict) tlds = args.tlds.split(',') log = args.log_file # Ensure the log file is writable before we check 200,000 domains. if not is_writable(log): print('The log file %s is not available for writing.' % log) exit(1) start = time.time() # Go through the entire words list and check the domains, or until # interrupted by the escape sequence. try: amount, available = check_domains(words, word_info, tlds, log, args.verbose) end = time.time() duration = int(end - start) log_output(VERSION, amount, available, words, duration, argdict, log) exit(0) except KeyboardInterrupt: print('\nCanceled.\n') exit(2) if __name__ == '__main__': main()
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 2803, 29, 1624, 24, 199, 3, 199, 3, 29986, 77, 464, 14, 647, 378, 14, 17, 199, 3, 14914, 626, 5920, 3775, 2600, 5932, 787, 2808, 465, 2881, 1561, 14, 199, 199, 646, 3873, 199, 646, 2197, 199, 646, 7534, 199, 646, 10933, 199, 646, 900, 199, 646, 984, 199, 646, 747, 199, 199, 3, 2372, 1453, 8559, 1568, 14, 199, 1092, 5035, 12, 13513, 51, 275, 359, 442, 8, 78, 9, 367, 302, 315, 747, 14, 12207, 360, 270, 369, 1568, 297, 283, 82, 1959, 739, 1252, 1294, 5106, 199, 4612, 275, 283, 16, 14, 18, 7, 421, 199, 318, 6634, 63, 14136, 8, 988, 63, 529, 63, 4375, 304, 272, 1449, 272, 30684, 805, 370, 6634, 2304, 282, 805, 370, 1255, 302, 5431, 1126, 3499, 14, 272, 11028, 365, 465, 11924, 26, 398, 768, 1866, 63, 14136, 8, 18, 9, 221, 327, 499, 1126, 3499, 737, 4750, 267, 347, 3002, 63, 1593, 8, 78, 304, 288, 870, 360, 5006, 450, 68, 7, 450, 302, 9, 398, 327, 17415, 5238, 4696, 370, 4890, 267, 367, 302, 315, 1425, 8, 1960, 304, 288, 3002, 63, 1593, 8, 78, 9, 339, 22016, 1015, 402, 314, 2569, 13894, 7259, 1659, 6385, 26, 272, 665, 1014, 921, 23153, 14, 957, 15, 65, 15, 1272, 1138, 1690, 15, 10156, 1082, 821, 30, 272, 1449, 272, 1748, 63, 4284, 275, 413, 14, 16, 1182, 2069, 8, 988, 63, 529, 63, 4375, 9, 339, 347, 24774, 8, 1532, 304, 267, 2061, 63, 521, 63, 3527, 275, 359, 16, 14, 16, 61, 398, 347, 6634, 63, 14136, 63, 1593, 2031, 589, 12, 1011, 24459, 304, 288, 14439, 275, 900, 14, 9597, 342, 446, 2061, 63, 521, 63, 3527, 59, 16, 61, 288, 3602, 63, 475, 63, 2573, 275, 1748, 63, 4284, 446, 14439, 953, 340, 3602, 63, 475, 63, 2573, 690, 378, 26, 355, 900, 14, 4532, 8, 3039, 63, 475, 63, 2573, 9, 953, 2203, 275, 2562, 2031, 589, 12, 1011, 24459, 9, 288, 2061, 63, 521, 63, 3527, 59, 16, 61, 275, 900, 14, 9597, 342, 953, 372, 2203, 398, 372, 6634, 63, 14136, 63, 1593, 339, 372, 24774, 421, 199, 318, 664, 63, 1628, 63, 14242, 8, 1760, 12, 3686, 63, 2550, 29, 797, 304, 272, 1449, 272, 1803, 314, 1072, 402, 282, 3873, 1414, 14, 339, 6944, 26, 3506, 2845, 21705, 32708, 879, 649, 18732, 21955, 2296, 5749, 32744, 14, 272, 1449, 272, 862, 26, 267, 372, 3873, 14, 1074, 63, 1199, 8, 1760, 12, 5218, 29, 549, 680, 1913, 342, 272, 871, 3873, 14, 24691, 465, 325, 26, 267, 340, 3686, 63, 2550, 26, 288, 372, 325, 14, 1199, 14, 1913, 342, 267, 587, 26, 288, 372, 756, 421, 199, 318, 870, 63, 5734, 8, 9808, 12, 5982, 12, 2881, 12, 365, 63, 4561, 304, 272, 1449, 272, 12968, 83, 314, 1453, 6696, 16385, 465, 282, 16327, 14, 272, 1449, 272, 984, 14, 2703, 14, 952, 2258, 82, 11123, 908, 360, 283, 627, 9769, 5035, 430, 272, 984, 14, 2703, 14, 952, 2258, 82, 59, 28476, 23, 14, 19, 70, 22109, 61, 9499, 908, 8, 267, 334, 1609, 8, 9808, 9, 1182, 5982, 9, 627, 2948, 12, 267, 2881, 272, 5082, 272, 984, 14, 2703, 14, 4939, 342, 421, 199, 318, 664, 63, 807, 63, 3148, 8, 807, 63, 493, 304, 272, 1449, 272, 12892, 83, 314, 8212, 5932, 687, 282, 2600, 570, 12, 543, 8139, 272, 14489, 12, 436, 2529, 3062, 465, 282, 769, 14, 272, 1449, 272, 4349, 63, 815, 275, 942, 2286, 543, 1551, 8, 807, 63, 493, 9, 465, 570, 26, 267, 5932, 275, 359, 1027, 14, 1913, 1252, 2325, 342, 367, 4349, 315, 570, 14, 9684, 5106, 5493, 327, 982, 781, 9064, 4788, 18734, 761, 4654, 12, 781, 3984, 13369, 2402, 2556, 272, 327, 3595, 314, 5932, 14, 272, 340, 20054, 315, 5932, 59, 16, 2189, 267, 892, 63, 3148, 275, 942, 267, 367, 4349, 315, 5932, 26, 288, 17184, 275, 4349, 14, 1294, 26468, 288, 892, 63, 3148, 14, 740, 8, 14865, 59, 16, 566, 288, 4349, 63, 815, 14, 740, 8, 14865, 59, 17, 5728, 267, 5932, 275, 892, 63, 3148, 272, 587, 26, 267, 5932, 275, 2457, 8, 403, 12, 5932, 9, 221, 327, 2813, 2701, 3326, 267, 5932, 275, 769, 8, 409, 8, 3148, 430, 221, 327, 2813, 15755, 267, 5932, 14, 3191, 342, 2286, 372, 359, 3148, 12, 4349, 63, 815, 61, 421, 199, 32, 1866, 63, 14136, 8, 17, 9, 199, 318, 1104, 63, 2261, 8, 2261, 12, 3376, 29, 797, 304, 272, 340, 3376, 26, 267, 870, 360, 11345, 374, 2071, 83, 4507, 450, 334, 2261, 430, 339, 1072, 275, 664, 63, 1628, 63, 14242, 360, 11345, 374, 2071, 83, 4507, 450, 334, 2261, 395, 3686, 63, 2550, 29, 549, 9, 2286, 340, 1072, 365, 756, 26, 267, 372, 756, 339, 340, 283, 889, 1336, 367, 7, 315, 1072, 14, 2325, 837, 267, 372, 715, 272, 587, 26, 267, 372, 756, 421, 199, 318, 1104, 63, 9756, 8, 3148, 12, 4349, 63, 815, 12, 25168, 795, 2968, 957, 995, 943, 534, 806, 77, 464, 63, 1199, 14, 793, 297, 3376, 29, 797, 304, 272, 1449, 272, 11953, 2335, 4012, 282, 2741, 769, 402, 5932, 436, 5920, 3932, 14962, 272, 465, 2881, 1561, 543, 314, 1627, 307, 1447, 14, 272, 1449, 272, 5982, 275, 822, 8, 3148, 9, 627, 822, 8, 5019, 795, 9, 272, 870, 360, 14740, 450, 68, 2881, 1561, 14, 961, 5594, 5452, 282, 1830, 3530, 450, 5982, 9, 272, 870, 360, 53, 678, 13659, 12, 314, 2058, 911, 506, 6290, 370, 450, 83, 3530, 450, 943, 9, 272, 870, 360, 1918, 4772, 3414, 365, 7167, 35, 2659, 339, 2808, 275, 942, 272, 302, 275, 378, 272, 367, 302, 315, 1425, 8, 552, 8, 3148, 2298, 267, 4349, 275, 5932, 59, 78, 61, 267, 2256, 275, 4349, 63, 815, 59, 78, 61, 267, 367, 307, 1447, 315, 25168, 795, 26, 288, 2881, 275, 334, 1027, 435, 7815, 435, 307, 1447, 680, 2325, 342, 288, 365, 63, 4561, 275, 1104, 63, 2261, 8, 2261, 12, 3376, 9, 288, 340, 365, 63, 4561, 26, 355 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 2803, 29, 1624, 24, 199, 3, 199, 3, 29986, 77, 464, 14, 647, 378, 14, 17, 199, 3, 14914, 626, 5920, 3775, 2600, 5932, 787, 2808, 465, 2881, 1561, 14, 199, 199, 646, 3873, 199, 646, 2197, 199, 646, 7534, 199, 646, 10933, 199, 646, 900, 199, 646, 984, 199, 646, 747, 199, 199, 3, 2372, 1453, 8559, 1568, 14, 199, 1092, 5035, 12, 13513, 51, 275, 359, 442, 8, 78, 9, 367, 302, 315, 747, 14, 12207, 360, 270, 369, 1568, 297, 283, 82, 1959, 739, 1252, 1294, 5106, 199, 4612, 275, 283, 16, 14, 18, 7, 421, 199, 318, 6634, 63, 14136, 8, 988, 63, 529, 63, 4375, 304, 272, 1449, 272, 30684, 805, 370, 6634, 2304, 282, 805, 370, 1255, 302, 5431, 1126, 3499, 14, 272, 11028, 365, 465, 11924, 26, 398, 768, 1866, 63, 14136, 8, 18, 9, 221, 327, 499, 1126, 3499, 737, 4750, 267, 347, 3002, 63, 1593, 8, 78, 304, 288, 870, 360, 5006, 450, 68, 7, 450, 302, 9, 398, 327, 17415, 5238, 4696, 370, 4890, 267, 367, 302, 315, 1425, 8, 1960, 304, 288, 3002, 63, 1593, 8, 78, 9, 339, 22016, 1015, 402, 314, 2569, 13894, 7259, 1659, 6385, 26, 272, 665, 1014, 921, 23153, 14, 957, 15, 65, 15, 1272, 1138, 1690, 15, 10156, 1082, 821, 30, 272, 1449, 272, 1748, 63, 4284, 275, 413, 14, 16, 1182, 2069, 8, 988, 63, 529, 63, 4375, 9, 339, 347, 24774, 8, 1532, 304, 267, 2061, 63, 521, 63, 3527, 275, 359, 16, 14, 16, 61, 398, 347, 6634, 63, 14136, 63, 1593, 2031, 589, 12, 1011, 24459, 304, 288, 14439, 275, 900, 14, 9597, 342, 446, 2061, 63, 521, 63, 3527, 59, 16, 61, 288, 3602, 63, 475, 63, 2573, 275, 1748, 63, 4284, 446, 14439, 953, 340, 3602, 63, 475, 63, 2573, 690, 378, 26, 355, 900, 14, 4532, 8, 3039, 63, 475, 63, 2573, 9, 953, 2203, 275, 2562, 2031, 589, 12, 1011, 24459, 9, 288, 2061, 63, 521, 63, 3527, 59, 16, 61, 275, 900, 14, 9597, 342, 953, 372, 2203, 398, 372, 6634, 63, 14136, 63, 1593, 339, 372, 24774, 421, 199, 318, 664, 63, 1628, 63, 14242, 8, 1760, 12, 3686, 63, 2550, 29, 797, 304, 272, 1449, 272, 1803, 314, 1072, 402, 282, 3873, 1414, 14, 339, 6944, 26, 3506, 2845, 21705, 32708, 879, 649, 18732, 21955, 2296, 5749, 32744, 14, 272, 1449, 272, 862, 26, 267, 372, 3873, 14, 1074, 63, 1199, 8, 1760, 12, 5218, 29, 549, 680, 1913, 342, 272, 871, 3873, 14, 24691, 465, 325, 26, 267, 340, 3686, 63, 2550, 26, 288, 372, 325, 14, 1199, 14, 1913, 342, 267, 587, 26, 288, 372, 756, 421, 199, 318, 870, 63, 5734, 8, 9808, 12, 5982, 12, 2881, 12, 365, 63, 4561, 304, 272, 1449, 272, 12968, 83, 314, 1453, 6696, 16385, 465, 282, 16327, 14, 272, 1449, 272, 984, 14, 2703, 14, 952, 2258, 82, 11123, 908, 360, 283, 627, 9769, 5035, 430, 272, 984, 14, 2703, 14, 952, 2258, 82, 59, 28476, 23, 14, 19, 70, 22109, 61, 9499, 908, 8, 267, 334, 1609, 8, 9808, 9, 1182, 5982, 9, 627, 2948, 12, 267, 2881, 272, 5082, 272, 984, 14, 2703, 14, 4939, 342, 421, 199, 318, 664, 63, 807, 63, 3148, 8, 807, 63, 493, 304, 272, 1449, 272, 12892, 83, 314, 8212, 5932, 687, 282, 2600, 570, 12, 543, 8139, 272, 14489, 12, 436, 2529, 3062, 465, 282, 769, 14, 272, 1449, 272, 4349, 63, 815, 275, 942, 2286, 543, 1551, 8, 807, 63, 493, 9, 465, 570, 26, 267, 5932, 275, 359, 1027, 14, 1913, 1252, 2325, 342, 367, 4349, 315, 570, 14, 9684, 5106, 5493, 327, 982, 781, 9064, 4788, 18734, 761, 4654, 12, 781, 3984, 13369, 2402, 2556, 272, 327, 3595, 314, 5932, 14, 272, 340, 20054, 315, 5932, 59, 16, 2189, 267, 892, 63, 3148, 275, 942, 267, 367, 4349, 315, 5932, 26, 288, 17184, 275, 4349, 14, 1294, 26468, 288, 892, 63, 3148, 14, 740, 8, 14865, 59, 16, 566, 288, 4349, 63, 815, 14, 740, 8, 14865, 59, 17, 5728, 267, 5932, 275, 892, 63, 3148, 272, 587, 26, 267, 5932, 275, 2457, 8, 403, 12, 5932, 9, 221, 327, 2813, 2701, 3326, 267, 5932, 275, 769, 8, 409, 8, 3148, 430, 221, 327, 2813, 15755, 267, 5932, 14, 3191, 342, 2286, 372, 359, 3148, 12, 4349, 63, 815, 61, 421, 199, 32, 1866, 63, 14136, 8, 17, 9, 199, 318, 1104, 63, 2261, 8, 2261, 12, 3376, 29, 797, 304, 272, 340, 3376, 26, 267, 870, 360, 11345, 374, 2071, 83, 4507, 450, 334, 2261, 430, 339, 1072, 275, 664, 63, 1628, 63, 14242, 360, 11345, 374, 2071, 83, 4507, 450, 334, 2261, 395, 3686, 63, 2550, 29, 549, 9, 2286, 340, 1072, 365, 756, 26, 267, 372, 756, 339, 340, 283, 889, 1336, 367, 7, 315, 1072, 14, 2325, 837, 267, 372, 715, 272, 587, 26, 267, 372, 756, 421, 199, 318, 1104, 63, 9756, 8, 3148, 12, 4349, 63, 815, 12, 25168, 795, 2968, 957, 995, 943, 534, 806, 77, 464, 63, 1199, 14, 793, 297, 3376, 29, 797, 304, 272, 1449, 272, 11953, 2335, 4012, 282, 2741, 769, 402, 5932, 436, 5920, 3932, 14962, 272, 465, 2881, 1561, 543, 314, 1627, 307, 1447, 14, 272, 1449, 272, 5982, 275, 822, 8, 3148, 9, 627, 822, 8, 5019, 795, 9, 272, 870, 360, 14740, 450, 68, 2881, 1561, 14, 961, 5594, 5452, 282, 1830, 3530, 450, 5982, 9, 272, 870, 360, 53, 678, 13659, 12, 314, 2058, 911, 506, 6290, 370, 450, 83, 3530, 450, 943, 9, 272, 870, 360, 1918, 4772, 3414, 365, 7167, 35, 2659, 339, 2808, 275, 942, 272, 302, 275, 378, 272, 367, 302, 315, 1425, 8, 552, 8, 3148, 2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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 ]
carlosb1/examples-python
ideas/forecast-example/forecast.py
1
6733
"""Docstring for MyClass.""" import datetime import requests from sqlalchemy import Column, Integer, String , create_engine from celery import Celery from sqlalchemy.sql import exists from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() # define object class InfoSpot(Base): """Docstring for MyClass.""" __tablename__ = 'infospot' id = Column(Integer, primary_key=True) solid_rating = Column(Integer) faded_rating = Column(Integer) chart_wind_url = Column(String) chart_period_url = Column(String) wind_direction = Column(Integer) wind_compass_direction = Column(String) wind_speed = Column(Integer) #wind_type_speed = Column(String) wind_chill = Column(Integer) wind_unit = Column(String) local_timestamp = Column(Integer) id_spot = Column(Integer) def __str__(self): """testing function.""" result = 'id='+str(id) +' id_spot='+str(self.id_spot) +' solid_rating='+str(self.solid_rating) +' faded_rating='+str(self.faded_rating) +' chart_wind_url='+str(self.chart_wind_url) +' chart_period_url='+str(self.chart_period_url) +' wind_direction='+str(self.wind_direction) +' wind_compass_direction='+str(self.wind_compass_direction) +' wind_speed='+str(self.wind_speed) +' wind_chill='+str(self.wind_chill) +' wind_unit='+str(self.wind_unit) +' local_timestamp='+str(self.local_timestamp) return result def timestamp_to_string(timestamp): """testing function.""" return datetime.datetime.fromtimestamp(int(timestamp)).strftime('%Y-%m-%d %H:%M:%S') def set_up_msg(id_spot,local_timestamp, wind_speed, wind_unit, wind_compass_direction, solid_rating, faded_rating, chart_wind_url, chart_period_url): """Set up message email.""" msg = "ID_SPOT: "+str(id_spot)+" SOLID RATE: "+str(solid_rating)+" FADED RATE: "+str(faded_rating)+"<br/>"+"TIMESTAMP: "+timestamp_to_string(local_timestamp)+"<br/>"+"WIND: "+str(wind_speed)+" "+str(wind_unit)+"<br/>"+"MAP WIND: "+"<img src=\""+str(chart_wind_url)+"\"/><br/> MAP PERIOD: "+str(chart_period_url)+"<br/>" if solid_rating > 0 or faded_rating > 0: msg = "<b>"+msg+"</b>" return msg # API Reader class ApiReader(object): """Docstring for MyClass.""" def __init__(self, key, id_spot, session,user,passwd,dest): """testing function.""" self.id_spot = id_spot self.user = user self.passwd = passwd self.dest = dest self.key = key self.url = 'http://magicseaweed.com/api/'+str(self.key)+'/forecast/?spot_id='+str(self.id_spot)+'&units=eu&fields=timestamp,localTimestamp,fadedRating,solidRating,threeHourTimeText,wind.*,condition.temperature,charts.*' self.session = session def update(self): """testing function.""" r = requests.get(self.url) json_values = r.json() msgs = "" for value in json_values: #Parse times local_timestamp = value['localTimestamp'] solid_rating = value['solidRating'] faded_rating = value['fadedRating'] chart_wind_url = value['charts']['wind'] chart_period_url = value['charts']['period'] # chart_sst = value['charts']['sst'] #Honda wind_direction = value['wind']['direction'] wind_compass_direction = value['wind']['compassDirection'] #Brujula wind_speed = value['wind']['speed'] wind_unit = value['wind']['unit'] wind_chill = value['wind']['chill'] #Frio print 'time: '+timestamp_to_string(local_timestamp)+' solidRating='+str(solid_rating)+' fadedRating='+str(faded_rating) print 'chart_wind: '+str(chart_wind_url) print 'chart_period: '+str(chart_period_url) print 'wind_direction: '+str(wind_direction)+' wind_compass_direction: '+wind_compass_direction print 'wind_speed: '+str(wind_speed)+' '+str(wind_unit) print 'wind_chill: '+str(wind_chill) spot = InfoSpot(solid_rating=solid_rating, faded_rating=faded_rating, chart_wind_url=chart_wind_url, chart_period_url=chart_period_url, wind_direction=wind_direction, wind_compass_direction=wind_compass_direction, wind_speed=wind_speed, wind_chill=wind_chill, wind_unit=wind_unit, local_timestamp=local_timestamp, id_spot=self.id_spot ) msg = set_up_msg(self.id_spot,local_timestamp,wind_speed,wind_unit,wind_compass_direction,solid_rating,faded_rating,chart_wind_url,chart_period_url) msgs = msgs+msg+'\n' if not self.session.query(exists().where(InfoSpot.local_timestamp == local_timestamp).where(InfoSpot.id_spot == self.id_spot)).scalar(): self.session.add(spot) self.session.commit() #TODO parametr. parameters send_email(self.user,self.dest,"Wave report",msgs,self.passwd) def send_email(fromaddr, toaddr, subject, msg,passwd): """Send email via gmail.""" import smtplib server = smtplib.SMTP_SSL('smtp.gmail.com:465') server.ehlo() server.login(fromaddr,passwd) headers = "\r\n".join(["From: " + fromaddr, "To: " + toaddr, "subject: "+ subject, "mime-version: 1.0", "content-type: text/html"]) content = headers + "\r\n\r\n" + msg print content server.sendmail(fromaddr,toaddr,content) server.close() #Read file configuration fname = 'secret_forecast' with open(fname) as f: content = f.readlines() #TODO get content correctly (via dict) key = content[0].split(':')[1].rstrip().lstrip().strip() secret = content[1].split(':')[1].rstrip().lstrip().strip() username = content[2].split(":")[1].rstrip().lstrip().strip() password = content[3].split(":")[1].rstrip().lstrip().strip() dest = content[4].split(":")[1].rstrip().lstrip().strip() #SQL alchemy engine = create_engine('sqlite:///spots3.db') Base.metadata.create_all(engine) Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() celery = Celery('forecast') celery.config_from_object('celeryconfig') #Defined spots #TODO add waves idBarceloneta = 3535 reader = ApiReader(key,idBarceloneta,session,username,password,dest) @celery.task def search_spot(): """testing function.""" print 'Calling searching spot' reader.update()
gpl-2.0
[ 624, 3768, 875, 367, 4932, 2543, 1041, 199, 199, 646, 2197, 199, 646, 4145, 199, 504, 8335, 492, 4996, 12, 7225, 12, 2624, 2360, 1218, 63, 3908, 199, 504, 22748, 492, 445, 19028, 199, 504, 8335, 14, 3009, 492, 3495, 199, 504, 8335, 14, 1025, 492, 2351, 14367, 199, 504, 8335, 14, 832, 14, 12164, 1905, 492, 30191, 63, 1095, 421, 199, 1563, 275, 30191, 63, 1095, 342, 199, 199, 3, 5627, 909, 199, 533, 10332, 5058, 357, 8, 1563, 304, 272, 408, 3768, 875, 367, 4932, 2543, 1041, 339, 636, 10983, 363, 275, 283, 815, 15185, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 18609, 63, 10417, 275, 4996, 8, 2674, 9, 272, 1433, 770, 63, 10417, 275, 4996, 8, 2674, 9, 272, 10943, 63, 11530, 63, 633, 275, 4996, 8, 1558, 9, 272, 10943, 63, 5191, 63, 633, 275, 4996, 8, 1558, 9, 272, 15417, 63, 6874, 275, 4996, 8, 2674, 9, 272, 15417, 63, 863, 405, 63, 6874, 275, 4996, 8, 1558, 9, 272, 15417, 63, 7625, 275, 4996, 8, 2674, 9, 272, 327, 11530, 63, 466, 63, 7625, 275, 4996, 8, 1558, 9, 272, 15417, 63, 335, 778, 275, 4996, 8, 2674, 9, 272, 15417, 63, 3248, 275, 4996, 8, 1558, 9, 272, 2257, 63, 3954, 275, 4996, 8, 2674, 9, 272, 1305, 63, 15185, 275, 4996, 8, 2674, 9, 339, 347, 636, 495, 721, 277, 304, 267, 408, 4776, 805, 1041, 267, 754, 275, 283, 344, 22078, 495, 8, 344, 9, 267, 435, 7, 1305, 63, 15185, 22078, 495, 8, 277, 14, 344, 63, 15185, 9, 267, 435, 7, 18609, 63, 10417, 22078, 495, 8, 277, 14, 18533, 63, 10417, 9, 267, 435, 7, 1433, 770, 63, 10417, 22078, 495, 8, 277, 14, 667, 770, 63, 10417, 9, 267, 435, 7, 10943, 63, 11530, 63, 633, 22078, 495, 8, 277, 14, 9019, 63, 11530, 63, 633, 9, 267, 435, 7, 10943, 63, 5191, 63, 633, 22078, 495, 8, 277, 14, 9019, 63, 5191, 63, 633, 9, 267, 435, 7, 15417, 63, 6874, 22078, 495, 8, 277, 14, 11530, 63, 6874, 9, 267, 435, 7, 15417, 63, 863, 405, 63, 6874, 22078, 495, 8, 277, 14, 11530, 63, 863, 405, 63, 6874, 9, 267, 435, 7, 15417, 63, 7625, 22078, 495, 8, 277, 14, 11530, 63, 7625, 9, 267, 435, 7, 15417, 63, 335, 778, 22078, 495, 8, 277, 14, 11530, 63, 335, 778, 9, 267, 435, 7, 15417, 63, 3248, 22078, 495, 8, 277, 14, 11530, 63, 3248, 9, 267, 435, 7, 2257, 63, 3954, 22078, 495, 8, 277, 14, 1832, 63, 3954, 9, 267, 372, 754, 199, 199, 318, 4913, 63, 475, 63, 875, 8, 3954, 304, 272, 408, 4776, 805, 1041, 272, 372, 2197, 14, 2083, 14, 18531, 8, 442, 8, 3954, 4992, 6205, 3508, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 358, 199, 199, 318, 663, 63, 384, 63, 1328, 8, 344, 63, 15185, 12, 1832, 63, 3954, 12, 15417, 63, 7625, 12, 15417, 63, 3248, 12, 221, 15417, 63, 863, 405, 63, 6874, 12, 18609, 63, 10417, 12, 1433, 770, 63, 10417, 12, 10943, 63, 11530, 63, 633, 12, 10943, 63, 5191, 63, 633, 304, 272, 408, 1084, 1536, 1245, 3031, 1041, 339, 1499, 275, 298, 998, 63, 5763, 1387, 26, 7210, 495, 8, 344, 63, 15185, 18663, 20479, 820, 1951, 26, 7210, 495, 8, 18533, 63, 10417, 18663, 481, 33, 8280, 820, 1951, 26, 7210, 495, 8, 667, 770, 63, 10417, 18663, 28, 3289, 25552, 5207, 20277, 26, 7210, 3954, 63, 475, 63, 875, 8, 1832, 63, 3954, 18663, 28, 3289, 25552, 5207, 55, 3192, 26, 7210, 495, 8, 11530, 63, 7625, 18663, 7210, 495, 8, 11530, 63, 3248, 18663, 28, 3289, 25552, 5207, 5443, 644, 3192, 26, 298, 5207, 28, 4060, 2928, 9529, 341, 11, 495, 8, 9019, 63, 11530, 63, 633, 6393, 3212, 15313, 2535, 3289, 3133, 603, 1282, 13873, 25705, 26, 7210, 495, 8, 9019, 63, 5191, 63, 633, 18663, 28, 3289, 25552, 272, 340, 18609, 63, 10417, 690, 378, 503, 1433, 770, 63, 10417, 690, 378, 26, 267, 1499, 275, 3886, 66, 4335, 11, 1328, 5207, 1108, 66, 4335, 272, 372, 1499, 199, 199, 3, 3261, 23099, 199, 533, 13986, 5929, 8, 785, 304, 272, 408, 3768, 875, 367, 4932, 2543, 1041, 339, 347, 636, 826, 721, 277, 12, 790, 12, 1305, 63, 15185, 12, 2351, 12, 751, 12, 12671, 12, 2614, 304, 267, 408, 4776, 805, 1041, 267, 291, 14, 344, 63, 15185, 275, 1305, 63, 15185, 267, 291, 14, 751, 275, 922, 267, 291, 14, 12671, 275, 15081, 267, 291, 14, 2614, 275, 2053, 267, 291, 14, 498, 275, 790, 267, 291, 14, 633, 275, 283, 1014, 921, 11523, 27590, 1129, 379, 14, 957, 15, 1246, 19047, 495, 8, 277, 14, 498, 20731, 15, 29693, 10197, 15185, 63, 344, 22078, 495, 8, 277, 14, 344, 63, 15185, 20731, 6, 5260, 29, 16913, 6, 955, 29, 3954, 12, 1832, 10239, 12, 667, 770, 32533, 12, 18533, 32533, 12, 10480, 24246, 1366, 1872, 12, 11530, 2795, 12, 5394, 14, 12954, 12, 31522, 25737, 267, 291, 14, 1730, 275, 2351, 339, 347, 1678, 8, 277, 304, 267, 408, 4776, 805, 1041, 267, 519, 275, 4145, 14, 362, 8, 277, 14, 633, 9, 267, 2022, 63, 1459, 275, 519, 14, 1001, 342, 267, 17599, 275, 3087, 267, 367, 574, 315, 2022, 63, 1459, 26, 288, 327, 4003, 5431, 288, 2257, 63, 3954, 275, 574, 459, 1832, 10239, 418, 288, 18609, 63, 10417, 275, 574, 459, 18533, 32533, 418, 288, 1433, 770, 63, 10417, 275, 574, 459, 667, 770, 32533, 418, 288, 10943, 63, 11530, 63, 633, 275, 574, 459, 31522, 2545, 11530, 418, 288, 10943, 63, 5191, 63, 633, 275, 574, 459, 31522, 2545, 5191, 418, 1779, 327, 10943, 63, 83, 270, 275, 221, 574, 459, 31522, 2545, 83, 270, 418, 327, 40, 265, 983, 288, 15417, 63, 6874, 275, 574, 459, 11530, 2545, 6874, 418, 288, 15417, 63, 863, 405, 63, 6874, 275, 574, 459, 11530, 2545, 863, 405, 17015, 418, 327, 34, 6558, 74, 7586, 288, 15417, 63, 7625, 275, 574, 459, 11530, 2545, 7625, 418, 288, 15417, 63 ]
[ 3768, 875, 367, 4932, 2543, 1041, 199, 199, 646, 2197, 199, 646, 4145, 199, 504, 8335, 492, 4996, 12, 7225, 12, 2624, 2360, 1218, 63, 3908, 199, 504, 22748, 492, 445, 19028, 199, 504, 8335, 14, 3009, 492, 3495, 199, 504, 8335, 14, 1025, 492, 2351, 14367, 199, 504, 8335, 14, 832, 14, 12164, 1905, 492, 30191, 63, 1095, 421, 199, 1563, 275, 30191, 63, 1095, 342, 199, 199, 3, 5627, 909, 199, 533, 10332, 5058, 357, 8, 1563, 304, 272, 408, 3768, 875, 367, 4932, 2543, 1041, 339, 636, 10983, 363, 275, 283, 815, 15185, 7, 272, 1305, 275, 4996, 8, 2674, 12, 5062, 63, 498, 29, 549, 9, 272, 18609, 63, 10417, 275, 4996, 8, 2674, 9, 272, 1433, 770, 63, 10417, 275, 4996, 8, 2674, 9, 272, 10943, 63, 11530, 63, 633, 275, 4996, 8, 1558, 9, 272, 10943, 63, 5191, 63, 633, 275, 4996, 8, 1558, 9, 272, 15417, 63, 6874, 275, 4996, 8, 2674, 9, 272, 15417, 63, 863, 405, 63, 6874, 275, 4996, 8, 1558, 9, 272, 15417, 63, 7625, 275, 4996, 8, 2674, 9, 272, 327, 11530, 63, 466, 63, 7625, 275, 4996, 8, 1558, 9, 272, 15417, 63, 335, 778, 275, 4996, 8, 2674, 9, 272, 15417, 63, 3248, 275, 4996, 8, 1558, 9, 272, 2257, 63, 3954, 275, 4996, 8, 2674, 9, 272, 1305, 63, 15185, 275, 4996, 8, 2674, 9, 339, 347, 636, 495, 721, 277, 304, 267, 408, 4776, 805, 1041, 267, 754, 275, 283, 344, 22078, 495, 8, 344, 9, 267, 435, 7, 1305, 63, 15185, 22078, 495, 8, 277, 14, 344, 63, 15185, 9, 267, 435, 7, 18609, 63, 10417, 22078, 495, 8, 277, 14, 18533, 63, 10417, 9, 267, 435, 7, 1433, 770, 63, 10417, 22078, 495, 8, 277, 14, 667, 770, 63, 10417, 9, 267, 435, 7, 10943, 63, 11530, 63, 633, 22078, 495, 8, 277, 14, 9019, 63, 11530, 63, 633, 9, 267, 435, 7, 10943, 63, 5191, 63, 633, 22078, 495, 8, 277, 14, 9019, 63, 5191, 63, 633, 9, 267, 435, 7, 15417, 63, 6874, 22078, 495, 8, 277, 14, 11530, 63, 6874, 9, 267, 435, 7, 15417, 63, 863, 405, 63, 6874, 22078, 495, 8, 277, 14, 11530, 63, 863, 405, 63, 6874, 9, 267, 435, 7, 15417, 63, 7625, 22078, 495, 8, 277, 14, 11530, 63, 7625, 9, 267, 435, 7, 15417, 63, 335, 778, 22078, 495, 8, 277, 14, 11530, 63, 335, 778, 9, 267, 435, 7, 15417, 63, 3248, 22078, 495, 8, 277, 14, 11530, 63, 3248, 9, 267, 435, 7, 2257, 63, 3954, 22078, 495, 8, 277, 14, 1832, 63, 3954, 9, 267, 372, 754, 199, 199, 318, 4913, 63, 475, 63, 875, 8, 3954, 304, 272, 408, 4776, 805, 1041, 272, 372, 2197, 14, 2083, 14, 18531, 8, 442, 8, 3954, 4992, 6205, 3508, 57, 3295, 77, 3295, 68, 450, 40, 2689, 45, 2689, 51, 358, 199, 199, 318, 663, 63, 384, 63, 1328, 8, 344, 63, 15185, 12, 1832, 63, 3954, 12, 15417, 63, 7625, 12, 15417, 63, 3248, 12, 221, 15417, 63, 863, 405, 63, 6874, 12, 18609, 63, 10417, 12, 1433, 770, 63, 10417, 12, 10943, 63, 11530, 63, 633, 12, 10943, 63, 5191, 63, 633, 304, 272, 408, 1084, 1536, 1245, 3031, 1041, 339, 1499, 275, 298, 998, 63, 5763, 1387, 26, 7210, 495, 8, 344, 63, 15185, 18663, 20479, 820, 1951, 26, 7210, 495, 8, 18533, 63, 10417, 18663, 481, 33, 8280, 820, 1951, 26, 7210, 495, 8, 667, 770, 63, 10417, 18663, 28, 3289, 25552, 5207, 20277, 26, 7210, 3954, 63, 475, 63, 875, 8, 1832, 63, 3954, 18663, 28, 3289, 25552, 5207, 55, 3192, 26, 7210, 495, 8, 11530, 63, 7625, 18663, 7210, 495, 8, 11530, 63, 3248, 18663, 28, 3289, 25552, 5207, 5443, 644, 3192, 26, 298, 5207, 28, 4060, 2928, 9529, 341, 11, 495, 8, 9019, 63, 11530, 63, 633, 6393, 3212, 15313, 2535, 3289, 3133, 603, 1282, 13873, 25705, 26, 7210, 495, 8, 9019, 63, 5191, 63, 633, 18663, 28, 3289, 25552, 272, 340, 18609, 63, 10417, 690, 378, 503, 1433, 770, 63, 10417, 690, 378, 26, 267, 1499, 275, 3886, 66, 4335, 11, 1328, 5207, 1108, 66, 4335, 272, 372, 1499, 199, 199, 3, 3261, 23099, 199, 533, 13986, 5929, 8, 785, 304, 272, 408, 3768, 875, 367, 4932, 2543, 1041, 339, 347, 636, 826, 721, 277, 12, 790, 12, 1305, 63, 15185, 12, 2351, 12, 751, 12, 12671, 12, 2614, 304, 267, 408, 4776, 805, 1041, 267, 291, 14, 344, 63, 15185, 275, 1305, 63, 15185, 267, 291, 14, 751, 275, 922, 267, 291, 14, 12671, 275, 15081, 267, 291, 14, 2614, 275, 2053, 267, 291, 14, 498, 275, 790, 267, 291, 14, 633, 275, 283, 1014, 921, 11523, 27590, 1129, 379, 14, 957, 15, 1246, 19047, 495, 8, 277, 14, 498, 20731, 15, 29693, 10197, 15185, 63, 344, 22078, 495, 8, 277, 14, 344, 63, 15185, 20731, 6, 5260, 29, 16913, 6, 955, 29, 3954, 12, 1832, 10239, 12, 667, 770, 32533, 12, 18533, 32533, 12, 10480, 24246, 1366, 1872, 12, 11530, 2795, 12, 5394, 14, 12954, 12, 31522, 25737, 267, 291, 14, 1730, 275, 2351, 339, 347, 1678, 8, 277, 304, 267, 408, 4776, 805, 1041, 267, 519, 275, 4145, 14, 362, 8, 277, 14, 633, 9, 267, 2022, 63, 1459, 275, 519, 14, 1001, 342, 267, 17599, 275, 3087, 267, 367, 574, 315, 2022, 63, 1459, 26, 288, 327, 4003, 5431, 288, 2257, 63, 3954, 275, 574, 459, 1832, 10239, 418, 288, 18609, 63, 10417, 275, 574, 459, 18533, 32533, 418, 288, 1433, 770, 63, 10417, 275, 574, 459, 667, 770, 32533, 418, 288, 10943, 63, 11530, 63, 633, 275, 574, 459, 31522, 2545, 11530, 418, 288, 10943, 63, 5191, 63, 633, 275, 574, 459, 31522, 2545, 5191, 418, 1779, 327, 10943, 63, 83, 270, 275, 221, 574, 459, 31522, 2545, 83, 270, 418, 327, 40, 265, 983, 288, 15417, 63, 6874, 275, 574, 459, 11530, 2545, 6874, 418, 288, 15417, 63, 863, 405, 63, 6874, 275, 574, 459, 11530, 2545, 863, 405, 17015, 418, 327, 34, 6558, 74, 7586, 288, 15417, 63, 7625, 275, 574, 459, 11530, 2545, 7625, 418, 288, 15417, 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,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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 ]
rrrene/django
django/contrib/admin/templatetags/admin_list.py
173
17480
from __future__ import unicode_literals import datetime import warnings from django.contrib.admin.templatetags.admin_static import static from django.contrib.admin.templatetags.admin_urls import add_preserved_filters from django.contrib.admin.utils import ( display_for_field, display_for_value, label_for_field, lookup_field, ) from django.contrib.admin.views.main import ( ALL_VAR, ORDER_VAR, PAGE_VAR, SEARCH_VAR, ) from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import NoReverseMatch from django.db import models from django.template import Library from django.template.loader import get_template from django.utils import formats from django.utils.deprecation import RemovedInDjango20Warning from django.utils.encoding import force_text from django.utils.html import escapejs, format_html from django.utils.safestring import mark_safe from django.utils.text import capfirst from django.utils.translation import ugettext as _ register = Library() DOT = '.' @register.simple_tag def paginator_number(cl, i): """ Generates an individual page index link in a paginated list. """ if i == DOT: return '... ' elif i == cl.page_num: return format_html('<span class="this-page">{}</span> ', i + 1) else: return format_html('<a href="{}"{}>{}</a> ', cl.get_query_string({PAGE_VAR: i}), mark_safe(' class="end"' if i == cl.paginator.num_pages - 1 else ''), i + 1) @register.inclusion_tag('admin/pagination.html') def pagination(cl): """ Generates the series of links to the pages in a paginated list. """ paginator, page_num = cl.paginator, cl.page_num pagination_required = (not cl.show_all or not cl.can_show_all) and cl.multi_page if not pagination_required: page_range = [] else: ON_EACH_SIDE = 3 ON_ENDS = 2 # If there are 10 or fewer pages, display links to every page. # Otherwise, do some fancy if paginator.num_pages <= 10: page_range = range(paginator.num_pages) else: # Insert "smart" pagination links, so that there are always ON_ENDS # links at either end of the list of pages, and there are always # ON_EACH_SIDE links at either end of the "current page" link. page_range = [] if page_num > (ON_EACH_SIDE + ON_ENDS): page_range.extend(range(0, ON_ENDS)) page_range.append(DOT) page_range.extend(range(page_num - ON_EACH_SIDE, page_num + 1)) else: page_range.extend(range(0, page_num + 1)) if page_num < (paginator.num_pages - ON_EACH_SIDE - ON_ENDS - 1): page_range.extend(range(page_num + 1, page_num + ON_EACH_SIDE + 1)) page_range.append(DOT) page_range.extend(range(paginator.num_pages - ON_ENDS, paginator.num_pages)) else: page_range.extend(range(page_num + 1, paginator.num_pages)) need_show_all_link = cl.can_show_all and not cl.show_all and cl.multi_page return { 'cl': cl, 'pagination_required': pagination_required, 'show_all_url': need_show_all_link and cl.get_query_string({ALL_VAR: ''}), 'page_range': page_range, 'ALL_VAR': ALL_VAR, '1': 1, } def result_headers(cl): """ Generates the list column headers. """ ordering_field_columns = cl.get_ordering_field_columns() for i, field_name in enumerate(cl.list_display): text, attr = label_for_field( field_name, cl.model, model_admin=cl.model_admin, return_attr=True ) if attr: # Potentially not sortable # if the field is the action checkbox: no sorting and special class if field_name == 'action_checkbox': yield { "text": text, "class_attrib": mark_safe(' class="action-checkbox-column"'), "sortable": False, } continue admin_order_field = getattr(attr, "admin_order_field", None) if not admin_order_field: # Not sortable yield { "text": text, "class_attrib": format_html(' class="column-{}"', field_name), "sortable": False, } continue # OK, it is sortable if we got this far th_classes = ['sortable', 'column-{}'.format(field_name)] order_type = '' new_order_type = 'asc' sort_priority = 0 sorted = False # Is it currently being sorted on? if i in ordering_field_columns: sorted = True order_type = ordering_field_columns.get(i).lower() sort_priority = list(ordering_field_columns).index(i) + 1 th_classes.append('sorted %sending' % order_type) new_order_type = {'asc': 'desc', 'desc': 'asc'}[order_type] # build new ordering param o_list_primary = [] # URL for making this field the primary sort o_list_remove = [] # URL for removing this field from sort o_list_toggle = [] # URL for toggling order type for this field make_qs_param = lambda t, n: ('-' if t == 'desc' else '') + str(n) for j, ot in ordering_field_columns.items(): if j == i: # Same column param = make_qs_param(new_order_type, j) # We want clicking on this header to bring the ordering to the # front o_list_primary.insert(0, param) o_list_toggle.append(param) # o_list_remove - omit else: param = make_qs_param(ot, j) o_list_primary.append(param) o_list_toggle.append(param) o_list_remove.append(param) if i not in ordering_field_columns: o_list_primary.insert(0, make_qs_param(new_order_type, i)) yield { "text": text, "sortable": True, "sorted": sorted, "ascending": order_type == "asc", "sort_priority": sort_priority, "url_primary": cl.get_query_string({ORDER_VAR: '.'.join(o_list_primary)}), "url_remove": cl.get_query_string({ORDER_VAR: '.'.join(o_list_remove)}), "url_toggle": cl.get_query_string({ORDER_VAR: '.'.join(o_list_toggle)}), "class_attrib": format_html(' class="{}"', ' '.join(th_classes)) if th_classes else '', } def _boolean_icon(field_val): icon_url = static('admin/img/icon-%s.svg' % {True: 'yes', False: 'no', None: 'unknown'}[field_val]) return format_html('<img src="{}" alt="{}" />', icon_url, field_val) def items_for_result(cl, result, form): """ Generates the actual list of data. """ def link_in_col(is_first, field_name, cl): if cl.list_display_links is None: return False if is_first and not cl.list_display_links: return True return field_name in cl.list_display_links first = True pk = cl.lookup_opts.pk.attname for field_name in cl.list_display: empty_value_display = cl.model_admin.get_empty_value_display() row_classes = ['field-%s' % field_name] try: f, attr, value = lookup_field(field_name, result, cl.model_admin) except ObjectDoesNotExist: result_repr = empty_value_display else: empty_value_display = getattr(attr, 'empty_value_display', empty_value_display) if f is None or f.auto_created: if field_name == 'action_checkbox': row_classes = ['action-checkbox'] allow_tags = getattr(attr, 'allow_tags', False) boolean = getattr(attr, 'boolean', False) result_repr = display_for_value(value, empty_value_display, boolean) if allow_tags: warnings.warn( "Deprecated allow_tags attribute used on field {}. " "Use django.utils.safestring.format_html(), " "format_html_join(), or mark_safe() instead.".format(field_name), RemovedInDjango20Warning ) result_repr = mark_safe(result_repr) if isinstance(value, (datetime.date, datetime.time)): row_classes.append('nowrap') else: if isinstance(f.remote_field, models.ManyToOneRel): field_val = getattr(result, f.name) if field_val is None: result_repr = empty_value_display else: result_repr = field_val else: result_repr = display_for_field(value, f, empty_value_display) if isinstance(f, (models.DateField, models.TimeField, models.ForeignKey)): row_classes.append('nowrap') if force_text(result_repr) == '': result_repr = mark_safe('&nbsp;') row_class = mark_safe(' class="%s"' % ' '.join(row_classes)) # If list_display_links not defined, add the link tag to the first field if link_in_col(first, field_name, cl): table_tag = 'th' if first else 'td' first = False # Display link to the result's change_view if the url exists, else # display just the result's representation. try: url = cl.url_for_result(result) except NoReverseMatch: link_or_text = result_repr else: url = add_preserved_filters({'preserved_filters': cl.preserved_filters, 'opts': cl.opts}, url) # Convert the pk to something that can be used in Javascript. # Problem cases are long ints (23L) and non-ASCII strings. if cl.to_field: attr = str(cl.to_field) else: attr = pk value = result.serializable_value(attr) result_id = escapejs(value) link_or_text = format_html( '<a href="{}"{}>{}</a>', url, format_html( ' onclick="opener.dismissRelatedLookupPopup(window, ' '&#39;{}&#39;); return false;"', result_id ) if cl.is_popup else '', result_repr) yield format_html('<{}{}>{}</{}>', table_tag, row_class, link_or_text, table_tag) else: # By default the fields come from ModelAdmin.list_editable, but if we pull # the fields out of the form instead of list_editable custom admins # can provide fields on a per request basis if (form and field_name in form.fields and not ( field_name == cl.model._meta.pk.name and form[cl.model._meta.pk.name].is_hidden)): bf = form[field_name] result_repr = mark_safe(force_text(bf.errors) + force_text(bf)) yield format_html('<td{}>{}</td>', row_class, result_repr) if form and not form[cl.model._meta.pk.name].is_hidden: yield format_html('<td>{}</td>', force_text(form[cl.model._meta.pk.name])) class ResultList(list): # Wrapper class used to return items in a list_editable # changelist, annotated with the form object for error # reporting purposes. Needed to maintain backwards # compatibility with existing admin templates. def __init__(self, form, *items): self.form = form super(ResultList, self).__init__(*items) def results(cl): if cl.formset: for res, form in zip(cl.result_list, cl.formset.forms): yield ResultList(form, items_for_result(cl, res, form)) else: for res in cl.result_list: yield ResultList(None, items_for_result(cl, res, None)) def result_hidden_fields(cl): if cl.formset: for res, form in zip(cl.result_list, cl.formset.forms): if form[cl.model._meta.pk.name].is_hidden: yield mark_safe(force_text(form[cl.model._meta.pk.name])) @register.inclusion_tag("admin/change_list_results.html") def result_list(cl): """ Displays the headers and data list together """ headers = list(result_headers(cl)) num_sorted_fields = 0 for h in headers: if h['sortable'] and h['sorted']: num_sorted_fields += 1 return {'cl': cl, 'result_hidden_fields': list(result_hidden_fields(cl)), 'result_headers': headers, 'num_sorted_fields': num_sorted_fields, 'results': list(results(cl))} @register.inclusion_tag('admin/date_hierarchy.html') def date_hierarchy(cl): """ Displays the date hierarchy for date drill-down functionality. """ if cl.date_hierarchy: field_name = cl.date_hierarchy field = cl.opts.get_field(field_name) dates_or_datetimes = 'datetimes' if isinstance(field, models.DateTimeField) else 'dates' year_field = '%s__year' % field_name month_field = '%s__month' % field_name day_field = '%s__day' % field_name field_generic = '%s__' % field_name year_lookup = cl.params.get(year_field) month_lookup = cl.params.get(month_field) day_lookup = cl.params.get(day_field) link = lambda filters: cl.get_query_string(filters, [field_generic]) if not (year_lookup or month_lookup or day_lookup): # select appropriate start level date_range = cl.queryset.aggregate(first=models.Min(field_name), last=models.Max(field_name)) if date_range['first'] and date_range['last']: if date_range['first'].year == date_range['last'].year: year_lookup = date_range['first'].year if date_range['first'].month == date_range['last'].month: month_lookup = date_range['first'].month if year_lookup and month_lookup and day_lookup: day = datetime.date(int(year_lookup), int(month_lookup), int(day_lookup)) return { 'show': True, 'back': { 'link': link({year_field: year_lookup, month_field: month_lookup}), 'title': capfirst(formats.date_format(day, 'YEAR_MONTH_FORMAT')) }, 'choices': [{'title': capfirst(formats.date_format(day, 'MONTH_DAY_FORMAT'))}] } elif year_lookup and month_lookup: days = cl.queryset.filter(**{year_field: year_lookup, month_field: month_lookup}) days = getattr(days, dates_or_datetimes)(field_name, 'day') return { 'show': True, 'back': { 'link': link({year_field: year_lookup}), 'title': str(year_lookup) }, 'choices': [{ 'link': link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}), 'title': capfirst(formats.date_format(day, 'MONTH_DAY_FORMAT')) } for day in days] } elif year_lookup: months = cl.queryset.filter(**{year_field: year_lookup}) months = getattr(months, dates_or_datetimes)(field_name, 'month') return { 'show': True, 'back': { 'link': link({}), 'title': _('All dates') }, 'choices': [{ 'link': link({year_field: year_lookup, month_field: month.month}), 'title': capfirst(formats.date_format(month, 'YEAR_MONTH_FORMAT')) } for month in months] } else: years = getattr(cl.queryset, dates_or_datetimes)(field_name, 'year') return { 'show': True, 'choices': [{ 'link': link({year_field: str(year.year)}), 'title': str(year.year), } for year in years] } @register.inclusion_tag('admin/search_form.html') def search_form(cl): """ Displays a search form for searching the list. """ return { 'cl': cl, 'show_result_count': cl.result_count != cl.full_result_count, 'search_var': SEARCH_VAR } @register.simple_tag def admin_list_filter(cl, spec): tpl = get_template(spec.template) return tpl.render({ 'title': spec.title, 'choices': list(spec.choices(cl)), 'spec': spec, }) @register.inclusion_tag('admin/actions.html', takes_context=True) def admin_actions(context): """ Track the number of times the action field has been rendered on the page, so we know which value to use. """ context['action_index'] = context.get('action_index', -1) + 1 return context
bsd-3-clause
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 2197, 199, 646, 3598, 199, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1160, 2969, 14, 2113, 63, 1986, 492, 2955, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1160, 2969, 14, 2113, 63, 3603, 492, 1050, 63, 32104, 63, 4273, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1208, 492, 334, 272, 2929, 63, 509, 63, 698, 12, 2929, 63, 509, 63, 585, 12, 1768, 63, 509, 63, 698, 12, 4237, 63, 698, 12, 199, 9, 199, 504, 1639, 14, 2828, 14, 2113, 14, 4196, 14, 973, 492, 334, 272, 11727, 63, 5568, 12, 16044, 63, 5568, 12, 510, 2962, 63, 5568, 12, 5795, 7762, 63, 5568, 12, 199, 9, 199, 504, 1639, 14, 1018, 14, 3924, 492, 24803, 199, 504, 1639, 14, 1018, 14, 16522, 492, 32036, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 1160, 492, 11243, 199, 504, 1639, 14, 1160, 14, 3422, 492, 664, 63, 1160, 199, 504, 1639, 14, 1208, 492, 6752, 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, 1360, 492, 4772, 3596, 12, 1475, 63, 1360, 199, 504, 1639, 14, 1208, 14, 28389, 492, 2216, 63, 3489, 199, 504, 1639, 14, 1208, 14, 505, 492, 4021, 2246, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 465, 485, 199, 199, 2683, 275, 11243, 342, 199, 199, 13203, 275, 7815, 421, 199, 32, 2683, 14, 4129, 63, 1450, 199, 318, 21398, 63, 1955, 8, 429, 12, 284, 304, 272, 408, 272, 21687, 376, 8212, 2034, 1478, 2142, 315, 282, 9881, 23831, 769, 14, 272, 408, 272, 340, 284, 508, 15854, 26, 267, 372, 24352, 283, 272, 916, 284, 508, 824, 14, 1606, 63, 1507, 26, 267, 372, 1475, 63, 1360, 4827, 3751, 1021, 628, 3749, 13, 1606, 1743, 2440, 1108, 3751, 30, 1656, 284, 435, 413, 9, 272, 587, 26, 267, 372, 1475, 63, 1360, 4827, 65, 4369, 32053, 2, 2440, 30, 2440, 1108, 65, 30, 1656, 2574, 824, 14, 362, 63, 1131, 63, 875, 2561, 12898, 63, 5568, 26, 284, 8688, 2574, 2216, 63, 3489, 360, 1021, 628, 500, 4507, 340, 284, 508, 824, 14, 22073, 14, 1507, 63, 5856, 446, 413, 587, 9929, 2574, 284, 435, 413, 9, 421, 199, 32, 2683, 14, 24265, 63, 1450, 360, 2113, 15, 22793, 14, 1360, 358, 199, 318, 21192, 8, 429, 304, 272, 408, 272, 21687, 314, 6779, 402, 6220, 370, 314, 6497, 315, 282, 9881, 23831, 769, 14, 272, 408, 272, 21398, 12, 2034, 63, 1507, 275, 824, 14, 22073, 12, 824, 14, 1606, 63, 1507, 339, 21192, 63, 2427, 275, 334, 1397, 824, 14, 2384, 63, 452, 503, 440, 824, 14, 2425, 63, 2384, 63, 452, 9, 436, 824, 14, 3029, 63, 1606, 272, 340, 440, 21192, 63, 2427, 26, 267, 2034, 63, 1842, 275, 942, 272, 587, 26, 267, 5258, 63, 11765, 1244, 63, 28035, 275, 650, 267, 5258, 63, 20853, 275, 499, 398, 327, 982, 2337, 787, 1616, 503, 27392, 6497, 12, 2929, 6220, 370, 4036, 2034, 14, 267, 327, 6630, 12, 886, 2005, 27571, 267, 340, 21398, 14, 1507, 63, 5856, 2695, 1616, 26, 288, 2034, 63, 1842, 275, 1425, 8, 22073, 14, 1507, 63, 5856, 9, 267, 587, 26, 288, 327, 15496, 298, 7853, 2, 21192, 6220, 12, 880, 626, 2337, 787, 3544, 5258, 63, 20853, 288, 327, 6220, 737, 1902, 1284, 402, 314, 769, 402, 6497, 12, 436, 2337, 787, 3544, 288, 327, 5258, 63, 11765, 1244, 63, 28035, 6220, 737, 1902, 1284, 402, 314, 298, 1818, 2034, 2, 2142, 14, 288, 2034, 63, 1842, 275, 942, 288, 340, 2034, 63, 1507, 690, 334, 615, 63, 11765, 1244, 63, 28035, 435, 5258, 63, 20853, 304, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 16, 12, 5258, 63, 20853, 430, 355, 2034, 63, 1842, 14, 740, 8, 13203, 9, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 446, 5258, 63, 11765, 1244, 63, 28035, 12, 2034, 63, 1507, 435, 413, 430, 288, 587, 26, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 16, 12, 2034, 63, 1507, 435, 413, 430, 288, 340, 2034, 63, 1507, 665, 334, 22073, 14, 1507, 63, 5856, 446, 5258, 63, 11765, 1244, 63, 28035, 446, 5258, 63, 20853, 446, 413, 304, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 435, 413, 12, 2034, 63, 1507, 435, 5258, 63, 11765, 1244, 63, 28035, 435, 413, 430, 355, 2034, 63, 1842, 14, 740, 8, 13203, 9, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 22073, 14, 1507, 63, 5856, 446, 5258, 63, 20853, 12, 21398, 14, 1507, 63, 5856, 430, 288, 587, 26, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 435, 413, 12, 21398, 14, 1507, 63, 5856, 430, 339, 1929, 63, 2384, 63, 452, 63, 1073, 275, 824, 14, 2425, 63, 2384, 63, 452, 436, 440, 824, 14, 2384, 63, 452, 436, 824, 14, 3029, 63, 1606, 272, 372, 469, 267, 283, 429, 356, 824, 12, 267, 283, 22793, 63, 2427, 356, 21192, 63, 2427, 12, 267, 283, 2384, 63, 452, 63, 633, 356, 1929, 63, 2384, 63, 452, 63, 1073, 436, 824, 14, 362, 63, 1131, 63, 875, 2561, 1761, 63, 5568, 26, 283, 1604, 267, 283, 1606, 63, 1842, 356, 2034, 63, 1842, 12, 267, 283, 1761, 63, 5568, 356, 11727, 63, 5568, 12, 267, 283, 17, 356, 413, 12, 272, 789, 421, 199, 318, 754, 63, 2139, 8, 429, 304, 272, 408, 272, 21687, 314, 769, 2763, 2323, 14, 272, 408, 272, 7794, 63, 698, 63, 3406, 275, 824, 14, 362, 63, 7128, 63, 698, 63, 3406, 342, 272, 367, 284, 12, 901, 63, 354, 315, 3874, 8, 429, 14, 513, 63, 2918, 304, 267, 1318, 12, 1921, 275, 1768, 63, 509, 63, 698, 8, 288, 901, 63, 354, 12, 824, 14, 1238, 12, 288, 1402, 63, 2113, 29, 429, 14, 1238, 63, 2113, 12, 288, 372, 63, 962, 29, 549, 267, 776, 267, 340, 1921, 26, 288, 327, 4376, 17690, 440, 4069, 461, 953 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 2197, 199, 646, 3598, 199, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1160, 2969, 14, 2113, 63, 1986, 492, 2955, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1160, 2969, 14, 2113, 63, 3603, 492, 1050, 63, 32104, 63, 4273, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1208, 492, 334, 272, 2929, 63, 509, 63, 698, 12, 2929, 63, 509, 63, 585, 12, 1768, 63, 509, 63, 698, 12, 4237, 63, 698, 12, 199, 9, 199, 504, 1639, 14, 2828, 14, 2113, 14, 4196, 14, 973, 492, 334, 272, 11727, 63, 5568, 12, 16044, 63, 5568, 12, 510, 2962, 63, 5568, 12, 5795, 7762, 63, 5568, 12, 199, 9, 199, 504, 1639, 14, 1018, 14, 3924, 492, 24803, 199, 504, 1639, 14, 1018, 14, 16522, 492, 32036, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 1160, 492, 11243, 199, 504, 1639, 14, 1160, 14, 3422, 492, 664, 63, 1160, 199, 504, 1639, 14, 1208, 492, 6752, 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, 1360, 492, 4772, 3596, 12, 1475, 63, 1360, 199, 504, 1639, 14, 1208, 14, 28389, 492, 2216, 63, 3489, 199, 504, 1639, 14, 1208, 14, 505, 492, 4021, 2246, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 465, 485, 199, 199, 2683, 275, 11243, 342, 199, 199, 13203, 275, 7815, 421, 199, 32, 2683, 14, 4129, 63, 1450, 199, 318, 21398, 63, 1955, 8, 429, 12, 284, 304, 272, 408, 272, 21687, 376, 8212, 2034, 1478, 2142, 315, 282, 9881, 23831, 769, 14, 272, 408, 272, 340, 284, 508, 15854, 26, 267, 372, 24352, 283, 272, 916, 284, 508, 824, 14, 1606, 63, 1507, 26, 267, 372, 1475, 63, 1360, 4827, 3751, 1021, 628, 3749, 13, 1606, 1743, 2440, 1108, 3751, 30, 1656, 284, 435, 413, 9, 272, 587, 26, 267, 372, 1475, 63, 1360, 4827, 65, 4369, 32053, 2, 2440, 30, 2440, 1108, 65, 30, 1656, 2574, 824, 14, 362, 63, 1131, 63, 875, 2561, 12898, 63, 5568, 26, 284, 8688, 2574, 2216, 63, 3489, 360, 1021, 628, 500, 4507, 340, 284, 508, 824, 14, 22073, 14, 1507, 63, 5856, 446, 413, 587, 9929, 2574, 284, 435, 413, 9, 421, 199, 32, 2683, 14, 24265, 63, 1450, 360, 2113, 15, 22793, 14, 1360, 358, 199, 318, 21192, 8, 429, 304, 272, 408, 272, 21687, 314, 6779, 402, 6220, 370, 314, 6497, 315, 282, 9881, 23831, 769, 14, 272, 408, 272, 21398, 12, 2034, 63, 1507, 275, 824, 14, 22073, 12, 824, 14, 1606, 63, 1507, 339, 21192, 63, 2427, 275, 334, 1397, 824, 14, 2384, 63, 452, 503, 440, 824, 14, 2425, 63, 2384, 63, 452, 9, 436, 824, 14, 3029, 63, 1606, 272, 340, 440, 21192, 63, 2427, 26, 267, 2034, 63, 1842, 275, 942, 272, 587, 26, 267, 5258, 63, 11765, 1244, 63, 28035, 275, 650, 267, 5258, 63, 20853, 275, 499, 398, 327, 982, 2337, 787, 1616, 503, 27392, 6497, 12, 2929, 6220, 370, 4036, 2034, 14, 267, 327, 6630, 12, 886, 2005, 27571, 267, 340, 21398, 14, 1507, 63, 5856, 2695, 1616, 26, 288, 2034, 63, 1842, 275, 1425, 8, 22073, 14, 1507, 63, 5856, 9, 267, 587, 26, 288, 327, 15496, 298, 7853, 2, 21192, 6220, 12, 880, 626, 2337, 787, 3544, 5258, 63, 20853, 288, 327, 6220, 737, 1902, 1284, 402, 314, 769, 402, 6497, 12, 436, 2337, 787, 3544, 288, 327, 5258, 63, 11765, 1244, 63, 28035, 6220, 737, 1902, 1284, 402, 314, 298, 1818, 2034, 2, 2142, 14, 288, 2034, 63, 1842, 275, 942, 288, 340, 2034, 63, 1507, 690, 334, 615, 63, 11765, 1244, 63, 28035, 435, 5258, 63, 20853, 304, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 16, 12, 5258, 63, 20853, 430, 355, 2034, 63, 1842, 14, 740, 8, 13203, 9, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 446, 5258, 63, 11765, 1244, 63, 28035, 12, 2034, 63, 1507, 435, 413, 430, 288, 587, 26, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 16, 12, 2034, 63, 1507, 435, 413, 430, 288, 340, 2034, 63, 1507, 665, 334, 22073, 14, 1507, 63, 5856, 446, 5258, 63, 11765, 1244, 63, 28035, 446, 5258, 63, 20853, 446, 413, 304, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 435, 413, 12, 2034, 63, 1507, 435, 5258, 63, 11765, 1244, 63, 28035, 435, 413, 430, 355, 2034, 63, 1842, 14, 740, 8, 13203, 9, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 22073, 14, 1507, 63, 5856, 446, 5258, 63, 20853, 12, 21398, 14, 1507, 63, 5856, 430, 288, 587, 26, 355, 2034, 63, 1842, 14, 2880, 8, 1842, 8, 1606, 63, 1507, 435, 413, 12, 21398, 14, 1507, 63, 5856, 430, 339, 1929, 63, 2384, 63, 452, 63, 1073, 275, 824, 14, 2425, 63, 2384, 63, 452, 436, 440, 824, 14, 2384, 63, 452, 436, 824, 14, 3029, 63, 1606, 272, 372, 469, 267, 283, 429, 356, 824, 12, 267, 283, 22793, 63, 2427, 356, 21192, 63, 2427, 12, 267, 283, 2384, 63, 452, 63, 633, 356, 1929, 63, 2384, 63, 452, 63, 1073, 436, 824, 14, 362, 63, 1131, 63, 875, 2561, 1761, 63, 5568, 26, 283, 1604, 267, 283, 1606, 63, 1842, 356, 2034, 63, 1842, 12, 267, 283, 1761, 63, 5568, 356, 11727, 63, 5568, 12, 267, 283, 17, 356, 413, 12, 272, 789, 421, 199, 318, 754, 63, 2139, 8, 429, 304, 272, 408, 272, 21687, 314, 769, 2763, 2323, 14, 272, 408, 272, 7794, 63, 698, 63, 3406, 275, 824, 14, 362, 63, 7128, 63, 698, 63, 3406, 342, 272, 367, 284, 12, 901, 63, 354, 315, 3874, 8, 429, 14, 513, 63, 2918, 304, 267, 1318, 12, 1921, 275, 1768, 63, 509, 63, 698, 8, 288, 901, 63, 354, 12, 824, 14, 1238, 12, 288, 1402, 63, 2113, 29, 429, 14, 1238, 63, 2113, 12, 288, 372, 63, 962, 29, 549, 267, 776, 267, 340, 1921, 26, 288, 327, 4376, 17690, 440, 4069, 461, 953, 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, 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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 ]
alexzatsepin/omim
tools/unix/diff_size.py
25
1026
#!/usr/bin/python import os, sys if len(sys.argv) < 3: print('This tool shows very different file sizes') print('Usage: {0} <newdir> <olddir> [threshold_in_%]'.format(sys.argv[0])) sys.exit(0) new_path = sys.argv[1] old_path = sys.argv[2] threshold = (int(sys.argv[3]) if len(sys.argv) > 3 else 10) / 100.0 + 1 min_diff = 1024 * 1024 for f in sorted(os.listdir(old_path)): new_file = os.path.join(new_path, f) old_file = os.path.join(old_path, f) if '.mwm' not in new_file: continue if os.path.isfile(new_file) and os.path.isfile(old_file): new_size = os.path.getsize(new_file) old_size = os.path.getsize(old_file) if new_size + old_size > 0: if new_size == 0 or old_size == 0 or max(new_size, old_size) / float(min(new_size, old_size)) > threshold and abs(new_size - old_size) > min_diff: print('{0}: {1} {2} to {3} MB'.format(f, old_size / 1024 / 1024, 'up' if new_size > old_size else 'down', new_size / 1024 / 1024)) else: print('Not found a mirror for {0}'.format(f))
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 646, 747, 12, 984, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 665, 650, 26, 523, 870, 360, 2765, 4744, 13703, 7437, 3365, 570, 10627, 358, 523, 870, 360, 7692, 26, 469, 16, 93, 665, 1222, 694, 30, 665, 1753, 694, 30, 359, 7227, 63, 262, 4970, 61, 1370, 908, 8, 1274, 14, 3020, 59, 16, 2459, 523, 984, 14, 2224, 8, 16, 9, 199, 199, 1222, 63, 515, 275, 984, 14, 3020, 59, 17, 61, 199, 1753, 63, 515, 275, 984, 14, 3020, 59, 18, 61, 199, 7227, 275, 334, 442, 8, 1274, 14, 3020, 59, 19, 566, 340, 822, 8, 1274, 14, 3020, 9, 690, 650, 587, 1616, 9, 1182, 2948, 14, 16, 435, 413, 199, 827, 63, 3028, 275, 6619, 627, 6619, 199, 199, 509, 289, 315, 3355, 8, 736, 14, 7374, 8, 1753, 63, 515, 2298, 523, 892, 63, 493, 275, 747, 14, 515, 14, 904, 8, 1222, 63, 515, 12, 289, 9, 523, 2269, 63, 493, 275, 747, 14, 515, 14, 904, 8, 1753, 63, 515, 12, 289, 9, 523, 340, 1987, 14716, 77, 7, 440, 315, 892, 63, 493, 26, 272, 1980, 523, 340, 747, 14, 515, 14, 6292, 8, 1222, 63, 493, 9, 436, 747, 14, 515, 14, 6292, 8, 1753, 63, 493, 304, 272, 892, 63, 890, 275, 747, 14, 515, 14, 20733, 8, 1222, 63, 493, 9, 272, 2269, 63, 890, 275, 747, 14, 515, 14, 20733, 8, 1753, 63, 493, 9, 272, 340, 892, 63, 890, 435, 2269, 63, 890, 690, 378, 26, 489, 340, 892, 63, 890, 508, 378, 503, 2269, 63, 890, 508, 378, 503, 1390, 8, 1222, 63, 890, 12, 2269, 63, 890, 9, 1182, 2069, 8, 827, 8, 1222, 63, 890, 12, 2269, 63, 890, 430, 690, 8765, 436, 2853, 8, 1222, 63, 890, 446, 2269, 63, 890, 9, 690, 1748, 63, 3028, 26, 267, 870, 11117, 16, 9160, 469, 17, 93, 469, 18, 93, 370, 469, 19, 93, 19487, 1370, 908, 8, 70, 12, 2269, 63, 890, 1182, 6619, 1182, 6619, 12, 283, 384, 7, 340, 892, 63, 890, 690, 2269, 63, 890, 587, 283, 2110, 297, 892, 63, 890, 1182, 6619, 1182, 6619, 430, 523, 587, 26, 272, 870, 360, 1763, 1911, 282, 15216, 367, 469, 16, 5285, 908, 8, 70, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 199, 646, 747, 12, 984, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 665, 650, 26, 523, 870, 360, 2765, 4744, 13703, 7437, 3365, 570, 10627, 358, 523, 870, 360, 7692, 26, 469, 16, 93, 665, 1222, 694, 30, 665, 1753, 694, 30, 359, 7227, 63, 262, 4970, 61, 1370, 908, 8, 1274, 14, 3020, 59, 16, 2459, 523, 984, 14, 2224, 8, 16, 9, 199, 199, 1222, 63, 515, 275, 984, 14, 3020, 59, 17, 61, 199, 1753, 63, 515, 275, 984, 14, 3020, 59, 18, 61, 199, 7227, 275, 334, 442, 8, 1274, 14, 3020, 59, 19, 566, 340, 822, 8, 1274, 14, 3020, 9, 690, 650, 587, 1616, 9, 1182, 2948, 14, 16, 435, 413, 199, 827, 63, 3028, 275, 6619, 627, 6619, 199, 199, 509, 289, 315, 3355, 8, 736, 14, 7374, 8, 1753, 63, 515, 2298, 523, 892, 63, 493, 275, 747, 14, 515, 14, 904, 8, 1222, 63, 515, 12, 289, 9, 523, 2269, 63, 493, 275, 747, 14, 515, 14, 904, 8, 1753, 63, 515, 12, 289, 9, 523, 340, 1987, 14716, 77, 7, 440, 315, 892, 63, 493, 26, 272, 1980, 523, 340, 747, 14, 515, 14, 6292, 8, 1222, 63, 493, 9, 436, 747, 14, 515, 14, 6292, 8, 1753, 63, 493, 304, 272, 892, 63, 890, 275, 747, 14, 515, 14, 20733, 8, 1222, 63, 493, 9, 272, 2269, 63, 890, 275, 747, 14, 515, 14, 20733, 8, 1753, 63, 493, 9, 272, 340, 892, 63, 890, 435, 2269, 63, 890, 690, 378, 26, 489, 340, 892, 63, 890, 508, 378, 503, 2269, 63, 890, 508, 378, 503, 1390, 8, 1222, 63, 890, 12, 2269, 63, 890, 9, 1182, 2069, 8, 827, 8, 1222, 63, 890, 12, 2269, 63, 890, 430, 690, 8765, 436, 2853, 8, 1222, 63, 890, 446, 2269, 63, 890, 9, 690, 1748, 63, 3028, 26, 267, 870, 11117, 16, 9160, 469, 17, 93, 469, 18, 93, 370, 469, 19, 93, 19487, 1370, 908, 8, 70, 12, 2269, 63, 890, 1182, 6619, 1182, 6619, 12, 283, 384, 7, 340, 892, 63, 890, 690, 2269, 63, 890, 587, 283, 2110, 297, 892, 63, 890, 1182, 6619, 1182, 6619, 430, 523, 587, 26, 272, 870, 360, 1763, 1911, 282, 15216, 367, 469, 16, 5285, 908, 8, 70, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 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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 ]
nwjs/chromium.src
tools/json_schema_compiler/model_test.py
4
5834
#!/usr/bin/env python # Copyright (c) 2012 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. from json_schema import CachedLoad from idl_schema import Load from model import Platforms import model import unittest class ModelTest(unittest.TestCase): def setUp(self): self.model = model.Model() self.permissions_json = CachedLoad('test/permissions.json') self.model.AddNamespace(self.permissions_json[0], 'path/to/permissions.json') self.permissions = self.model.namespaces.get('permissions') self.windows_json = CachedLoad('test/windows.json') self.model.AddNamespace(self.windows_json[0], 'path/to/window.json') self.windows = self.model.namespaces.get('windows') self.tabs_json = CachedLoad('test/tabs.json') self.model.AddNamespace(self.tabs_json[0], 'path/to/tabs.json') self.tabs = self.model.namespaces.get('tabs') self.idl_chromeos = Load('test/idl_namespace_chromeos.idl') self.model.AddNamespace(self.idl_chromeos[0], 'path/to/idl_namespace_chromeos.idl') self.idl_namespace_chromeos = self.model.namespaces.get( 'idl_namespace_chromeos') self.idl_all_platforms = Load('test/idl_namespace_all_platforms.idl') self.model.AddNamespace(self.idl_all_platforms[0], 'path/to/idl_namespace_all_platforms.idl') self.idl_namespace_all_platforms = self.model.namespaces.get( 'idl_namespace_all_platforms') self.idl_non_specific_platforms = Load( 'test/idl_namespace_non_specific_platforms.idl') self.model.AddNamespace(self.idl_non_specific_platforms[0], 'path/to/idl_namespace_non_specific_platforms.idl') self.idl_namespace_non_specific_platforms = self.model.namespaces.get( 'idl_namespace_non_specific_platforms') def testNamespaces(self): self.assertEquals(6, len(self.model.namespaces)) self.assertTrue(self.permissions) def testHasFunctions(self): self.assertEquals(["contains", "getAll", "remove", "request"], sorted(self.permissions.functions.keys())) def testHasTypes(self): self.assertEquals(['Tab'], self.tabs.types.keys()) self.assertEquals(['Permissions'], self.permissions.types.keys()) self.assertEquals(['Window'], self.windows.types.keys()) def testHasProperties(self): self.assertEquals(["active", "favIconUrl", "highlighted", "id", "incognito", "index", "pinned", "selected", "status", "title", "url", "windowId"], sorted(self.tabs.types['Tab'].properties.keys())) def testProperties(self): string_prop = self.tabs.types['Tab'].properties['status'] self.assertEquals(model.PropertyType.STRING, string_prop.type_.property_type) integer_prop = self.tabs.types['Tab'].properties['id'] self.assertEquals(model.PropertyType.INTEGER, integer_prop.type_.property_type) array_prop = self.windows.types['Window'].properties['tabs'] self.assertEquals(model.PropertyType.ARRAY, array_prop.type_.property_type) self.assertEquals(model.PropertyType.REF, array_prop.type_.item_type.property_type) self.assertEquals('tabs.Tab', array_prop.type_.item_type.ref_type) object_prop = self.tabs.functions['query'].params[0] self.assertEquals(model.PropertyType.OBJECT, object_prop.type_.property_type) self.assertEquals( ["active", "highlighted", "pinned", "status", "title", "url", "windowId", "windowType"], sorted(object_prop.type_.properties.keys())) def testChoices(self): self.assertEquals(model.PropertyType.CHOICES, self.tabs.functions['move'].params[0].type_.property_type) def testPropertyNotImplemented(self): (self.permissions_json[0]['types'][0] ['properties']['permissions']['type']) = 'something' self.assertRaises(model.ParseException, self.model.AddNamespace, self.permissions_json[0], 'path/to/something.json') def testDescription(self): self.assertFalse( self.permissions.functions['contains'].params[0].description) self.assertEquals('True if the extension has the specified permissions.', self.permissions.functions['contains'].callback.params[0].description) def testPropertyUnixName(self): param = self.tabs.functions['move'].params[0] self.assertEquals('tab_ids', param.unix_name) def testUnixName(self): expectations = { 'foo': 'foo', 'fooBar': 'foo_bar', 'fooBarBaz': 'foo_bar_baz', 'fooBARBaz': 'foo_bar_baz', 'fooBAR': 'foo_bar', 'FOO': 'foo', 'FOOBar': 'foo_bar', 'foo.bar': 'foo_bar', 'foo.BAR': 'foo_bar', 'foo.barBAZ': 'foo_bar_baz', 'foo_Bar_Baz_box': 'foo_bar_baz_box', } for name in expectations: self.assertEquals(expectations[name], model.UnixName(name)) def testCamelName(self): expectations = { 'foo': 'foo', 'fooBar': 'fooBar', 'foo_bar_baz': 'fooBarBaz', 'FOO_BAR': 'FOOBar', 'FOO_bar': 'FOOBar', '_bar': 'Bar', '_bar_baz': 'BarBaz', 'bar_': 'bar', 'bar_baz_': 'barBaz', } for testcase, expected in expectations.items(): self.assertEquals(expected, model.CamelName(testcase)) def testPlatforms(self): self.assertEqual([Platforms.CHROMEOS], self.idl_namespace_chromeos.platforms) self.assertEqual( [Platforms.CHROMEOS, Platforms.CHROMEOS_TOUCH, Platforms.LINUX, Platforms.MAC, Platforms.WIN], self.idl_namespace_all_platforms.platforms) self.assertEqual(None, self.idl_namespace_non_specific_platforms.platforms) if __name__ == '__main__': unittest.main()
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 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, 504, 2022, 63, 3629, 492, 445, 4583, 6200, 199, 504, 20365, 63, 3629, 492, 7190, 199, 504, 1402, 492, 510, 4452, 3351, 199, 646, 1402, 199, 646, 2882, 199, 199, 533, 5822, 774, 8, 2796, 14, 1746, 304, 523, 347, 3613, 8, 277, 304, 272, 291, 14, 1238, 275, 1402, 14, 1685, 342, 272, 291, 14, 6060, 63, 1001, 275, 445, 4583, 6200, 360, 396, 15, 6060, 14, 1001, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 6060, 63, 1001, 59, 16, 467, 267, 283, 515, 15, 475, 15, 6060, 14, 1001, 358, 272, 291, 14, 6060, 275, 291, 14, 1238, 14, 9247, 14, 362, 360, 6060, 358, 272, 291, 14, 8258, 63, 1001, 275, 445, 4583, 6200, 360, 396, 15, 8258, 14, 1001, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 8258, 63, 1001, 59, 16, 467, 267, 283, 515, 15, 475, 15, 3806, 14, 1001, 358, 272, 291, 14, 8258, 275, 291, 14, 1238, 14, 9247, 14, 362, 360, 8258, 358, 272, 291, 14, 8741, 63, 1001, 275, 445, 4583, 6200, 360, 396, 15, 8741, 14, 1001, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 8741, 63, 1001, 59, 16, 467, 267, 283, 515, 15, 475, 15, 8741, 14, 1001, 358, 272, 291, 14, 8741, 275, 291, 14, 1238, 14, 9247, 14, 362, 360, 8741, 358, 272, 291, 14, 13398, 63, 9887, 736, 275, 7190, 360, 396, 15, 13398, 63, 3251, 63, 9887, 736, 14, 13398, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 13398, 63, 9887, 736, 59, 16, 467, 267, 283, 515, 15, 475, 15, 13398, 63, 3251, 63, 9887, 736, 14, 13398, 358, 272, 291, 14, 13398, 63, 3251, 63, 9887, 736, 275, 291, 14, 1238, 14, 9247, 14, 362, 8, 267, 283, 13398, 63, 3251, 63, 9887, 736, 358, 272, 291, 14, 13398, 63, 452, 63, 19601, 275, 7190, 360, 396, 15, 13398, 63, 3251, 63, 452, 63, 19601, 14, 13398, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 13398, 63, 452, 63, 19601, 59, 16, 467, 267, 283, 515, 15, 475, 15, 13398, 63, 3251, 63, 452, 63, 19601, 14, 13398, 358, 272, 291, 14, 13398, 63, 3251, 63, 452, 63, 19601, 275, 291, 14, 1238, 14, 9247, 14, 362, 8, 267, 283, 13398, 63, 3251, 63, 452, 63, 19601, 358, 272, 291, 14, 13398, 63, 2865, 63, 6100, 63, 19601, 275, 7190, 8, 267, 283, 396, 15, 13398, 63, 3251, 63, 2865, 63, 6100, 63, 19601, 14, 13398, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 13398, 63, 2865, 63, 6100, 63, 19601, 59, 16, 467, 267, 283, 515, 15, 475, 15, 13398, 63, 3251, 63, 2865, 63, 6100, 63, 19601, 14, 13398, 358, 272, 291, 14, 13398, 63, 3251, 63, 2865, 63, 6100, 63, 19601, 275, 291, 14, 1238, 14, 9247, 14, 362, 8, 267, 283, 13398, 63, 3251, 63, 2865, 63, 6100, 63, 19601, 358, 819, 347, 511, 985, 10749, 8, 277, 304, 272, 291, 14, 2947, 8, 22, 12, 822, 8, 277, 14, 1238, 14, 9247, 430, 272, 291, 14, 1815, 8, 277, 14, 6060, 9, 819, 347, 511, 6362, 13967, 8, 277, 304, 272, 291, 14, 2947, 5234, 6134, 401, 298, 31359, 401, 298, 2168, 401, 298, 1069, 2255, 267, 3355, 8, 277, 14, 6060, 14, 5777, 14, 1612, 4059, 819, 347, 511, 6362, 4100, 8, 277, 304, 272, 291, 14, 2947, 2941, 7690, 995, 291, 14, 8741, 14, 1313, 14, 1612, 1012, 272, 291, 14, 2947, 2941, 17004, 995, 291, 14, 6060, 14, 1313, 14, 1612, 1012, 272, 291, 14, 2947, 2941, 4301, 995, 291, 14, 8258, 14, 1313, 14, 1612, 1012, 819, 347, 511, 6362, 8516, 8, 277, 304, 272, 291, 14, 2947, 5234, 2682, 401, 298, 30763, 8954, 6417, 401, 298, 6260, 27883, 401, 298, 344, 401, 267, 298, 262, 6862, 24308, 401, 298, 1080, 401, 298, 7751, 7439, 401, 298, 5511, 401, 298, 1205, 401, 298, 1213, 401, 298, 633, 401, 267, 298, 3806, 1304, 2255, 267, 3355, 8, 277, 14, 8741, 14, 1313, 459, 7690, 2278, 3282, 14, 1612, 4059, 819, 347, 511, 8516, 8, 277, 304, 272, 1059, 63, 4469, 275, 291, 14, 8741, 14, 1313, 459, 7690, 2278, 3282, 459, 1205, 418, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 5353, 12, 1993, 1059, 63, 4469, 14, 466, 3754, 1829, 63, 466, 9, 272, 3000, 63, 4469, 275, 291, 14, 8741, 14, 1313, 459, 7690, 2278, 3282, 459, 344, 418, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 9596, 12, 1993, 3000, 63, 4469, 14, 466, 3754, 1829, 63, 466, 9, 272, 1625, 63, 4469, 275, 291, 14, 8258, 14, 1313, 459, 4301, 2278, 3282, 459, 8741, 418, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 12322, 12, 1993, 1625, 63, 4469, 14, 466, 3754, 1829, 63, 466, 9, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 8279, 12, 1993, 1625, 63, 4469, 14, 466, 3754, 1053, 63, 466, 14, 1829, 63, 466, 9, 272, 291, 14, 2947, 360, 8741, 14, 7690, 297, 1625, 63, 4469, 14, 466, 3754, 1053, 63, 466, 14, 1121, 63, 466, 9, 272, 909, 63, 4469, 275, 291, 14, 8741, 14, 5777, 459, 1131, 2278, 1162, 59, 16, 61, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 9868, 12, 1993, 909, 63, 4469, 14, 466, 3754, 1829, 63, 466, 9, 272, 291, 14, 2947, 8, 267, 2097, 2682, 401, 298, 6260, 27883, 401, 298, 7751, 7439, 401, 298, 1205, 401, 298, 1213, 401, 298, 633, 401, 268, 298, 3806, 1304, 401, 298, 3806, 804, 2255, 267, 3355, 8, 785, 63, 4469, 14, 466, 3754, 3282, 14, 1612, 4059, 819, 347, 511, 30806, 8, 277, 304, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 16236, 12, 1993, 291, 14, 8741, 14 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 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, 504, 2022, 63, 3629, 492, 445, 4583, 6200, 199, 504, 20365, 63, 3629, 492, 7190, 199, 504, 1402, 492, 510, 4452, 3351, 199, 646, 1402, 199, 646, 2882, 199, 199, 533, 5822, 774, 8, 2796, 14, 1746, 304, 523, 347, 3613, 8, 277, 304, 272, 291, 14, 1238, 275, 1402, 14, 1685, 342, 272, 291, 14, 6060, 63, 1001, 275, 445, 4583, 6200, 360, 396, 15, 6060, 14, 1001, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 6060, 63, 1001, 59, 16, 467, 267, 283, 515, 15, 475, 15, 6060, 14, 1001, 358, 272, 291, 14, 6060, 275, 291, 14, 1238, 14, 9247, 14, 362, 360, 6060, 358, 272, 291, 14, 8258, 63, 1001, 275, 445, 4583, 6200, 360, 396, 15, 8258, 14, 1001, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 8258, 63, 1001, 59, 16, 467, 267, 283, 515, 15, 475, 15, 3806, 14, 1001, 358, 272, 291, 14, 8258, 275, 291, 14, 1238, 14, 9247, 14, 362, 360, 8258, 358, 272, 291, 14, 8741, 63, 1001, 275, 445, 4583, 6200, 360, 396, 15, 8741, 14, 1001, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 8741, 63, 1001, 59, 16, 467, 267, 283, 515, 15, 475, 15, 8741, 14, 1001, 358, 272, 291, 14, 8741, 275, 291, 14, 1238, 14, 9247, 14, 362, 360, 8741, 358, 272, 291, 14, 13398, 63, 9887, 736, 275, 7190, 360, 396, 15, 13398, 63, 3251, 63, 9887, 736, 14, 13398, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 13398, 63, 9887, 736, 59, 16, 467, 267, 283, 515, 15, 475, 15, 13398, 63, 3251, 63, 9887, 736, 14, 13398, 358, 272, 291, 14, 13398, 63, 3251, 63, 9887, 736, 275, 291, 14, 1238, 14, 9247, 14, 362, 8, 267, 283, 13398, 63, 3251, 63, 9887, 736, 358, 272, 291, 14, 13398, 63, 452, 63, 19601, 275, 7190, 360, 396, 15, 13398, 63, 3251, 63, 452, 63, 19601, 14, 13398, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 13398, 63, 452, 63, 19601, 59, 16, 467, 267, 283, 515, 15, 475, 15, 13398, 63, 3251, 63, 452, 63, 19601, 14, 13398, 358, 272, 291, 14, 13398, 63, 3251, 63, 452, 63, 19601, 275, 291, 14, 1238, 14, 9247, 14, 362, 8, 267, 283, 13398, 63, 3251, 63, 452, 63, 19601, 358, 272, 291, 14, 13398, 63, 2865, 63, 6100, 63, 19601, 275, 7190, 8, 267, 283, 396, 15, 13398, 63, 3251, 63, 2865, 63, 6100, 63, 19601, 14, 13398, 358, 272, 291, 14, 1238, 14, 1123, 8814, 8, 277, 14, 13398, 63, 2865, 63, 6100, 63, 19601, 59, 16, 467, 267, 283, 515, 15, 475, 15, 13398, 63, 3251, 63, 2865, 63, 6100, 63, 19601, 14, 13398, 358, 272, 291, 14, 13398, 63, 3251, 63, 2865, 63, 6100, 63, 19601, 275, 291, 14, 1238, 14, 9247, 14, 362, 8, 267, 283, 13398, 63, 3251, 63, 2865, 63, 6100, 63, 19601, 358, 819, 347, 511, 985, 10749, 8, 277, 304, 272, 291, 14, 2947, 8, 22, 12, 822, 8, 277, 14, 1238, 14, 9247, 430, 272, 291, 14, 1815, 8, 277, 14, 6060, 9, 819, 347, 511, 6362, 13967, 8, 277, 304, 272, 291, 14, 2947, 5234, 6134, 401, 298, 31359, 401, 298, 2168, 401, 298, 1069, 2255, 267, 3355, 8, 277, 14, 6060, 14, 5777, 14, 1612, 4059, 819, 347, 511, 6362, 4100, 8, 277, 304, 272, 291, 14, 2947, 2941, 7690, 995, 291, 14, 8741, 14, 1313, 14, 1612, 1012, 272, 291, 14, 2947, 2941, 17004, 995, 291, 14, 6060, 14, 1313, 14, 1612, 1012, 272, 291, 14, 2947, 2941, 4301, 995, 291, 14, 8258, 14, 1313, 14, 1612, 1012, 819, 347, 511, 6362, 8516, 8, 277, 304, 272, 291, 14, 2947, 5234, 2682, 401, 298, 30763, 8954, 6417, 401, 298, 6260, 27883, 401, 298, 344, 401, 267, 298, 262, 6862, 24308, 401, 298, 1080, 401, 298, 7751, 7439, 401, 298, 5511, 401, 298, 1205, 401, 298, 1213, 401, 298, 633, 401, 267, 298, 3806, 1304, 2255, 267, 3355, 8, 277, 14, 8741, 14, 1313, 459, 7690, 2278, 3282, 14, 1612, 4059, 819, 347, 511, 8516, 8, 277, 304, 272, 1059, 63, 4469, 275, 291, 14, 8741, 14, 1313, 459, 7690, 2278, 3282, 459, 1205, 418, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 5353, 12, 1993, 1059, 63, 4469, 14, 466, 3754, 1829, 63, 466, 9, 272, 3000, 63, 4469, 275, 291, 14, 8741, 14, 1313, 459, 7690, 2278, 3282, 459, 344, 418, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 9596, 12, 1993, 3000, 63, 4469, 14, 466, 3754, 1829, 63, 466, 9, 272, 1625, 63, 4469, 275, 291, 14, 8258, 14, 1313, 459, 4301, 2278, 3282, 459, 8741, 418, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 12322, 12, 1993, 1625, 63, 4469, 14, 466, 3754, 1829, 63, 466, 9, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 8279, 12, 1993, 1625, 63, 4469, 14, 466, 3754, 1053, 63, 466, 14, 1829, 63, 466, 9, 272, 291, 14, 2947, 360, 8741, 14, 7690, 297, 1625, 63, 4469, 14, 466, 3754, 1053, 63, 466, 14, 1121, 63, 466, 9, 272, 909, 63, 4469, 275, 291, 14, 8741, 14, 5777, 459, 1131, 2278, 1162, 59, 16, 61, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 9868, 12, 1993, 909, 63, 4469, 14, 466, 3754, 1829, 63, 466, 9, 272, 291, 14, 2947, 8, 267, 2097, 2682, 401, 298, 6260, 27883, 401, 298, 7751, 7439, 401, 298, 1205, 401, 298, 1213, 401, 298, 633, 401, 268, 298, 3806, 1304, 401, 298, 3806, 804, 2255, 267, 3355, 8, 785, 63, 4469, 14, 466, 3754, 3282, 14, 1612, 4059, 819, 347, 511, 30806, 8, 277, 304, 272, 291, 14, 2947, 8, 1238, 14, 3697, 804, 14, 16236, 12, 1993, 291, 14, 8741, 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, 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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 ]
panpan0000/RackHD
test/tests/api/redfish_1_0/account_service_tests.py
15
5546
from config.redfish1_0_config import * from modules.logger import Log from modules.redfish_auth import Auth from on_http_redfish_1_0 import RedfishvApi as redfish from on_http_redfish_1_0 import rest from datetime import datetime from proboscis.asserts import assert_equal from proboscis.asserts import assert_false from proboscis.asserts import assert_raises from proboscis.asserts import assert_not_equal from proboscis.asserts import assert_true from proboscis.asserts import fail from proboscis import SkipTest from proboscis import test from json import loads,dumps from proboscis import before_class from proboscis import after_class LOG = Log(__name__) @test(groups=['redfish.account_service.tests'], depends_on_groups=['obm.tests']) class AccountServiceTests(object): def __init__(self): self.__client = config.api_client self.__accounts = None self.__roles = None @before_class() def setup(self): """setup test environment""" Auth.enable() @after_class(always_run=True) def teardown(self): """ restore test environment """ Auth.disable() def __get_data(self): return loads(self.__client.last_response.data) @test(groups=['redfish.get_account_service']) def test_get_account_service(self): """ Testing GET /AccountService """ redfish().get_account_service() service = self.__get_data() LOG.debug(service,json=True) id = service.get('Id') assert_equal('AccountService', id, message='unexpected id {0}, expected {1}'.format(id,'AccountService')) accounts = service.get('Accounts') roles = service.get('Roles') assert_not_equal(None, accounts, message='Failed to get accounts') assert_not_equal(None, roles, message='Failed to get roles') @test(groups=['redfish.list_roles'], depends_on_groups=['redfish.get_account_service']) def test_list_roles(self): """ Testing GET /AcountService/Roles """ redfish().list_roles() roles = self.__get_data() LOG.debug(roles,json=True) self.__roles = roles.get('Members') assert_equal(len(self.__roles), 3, message='expected role length to be 3') for member in self.__roles: dataId = member.get('@odata.id') assert_not_equal(None,dataId) dataId = dataId.split('/redfish/v1/AccountService/Roles/')[1] redfish().get_role(dataId) role = self.__get_data() LOG.debug(role,json=True) name = role.get('Name') assert_equal(dataId, name, message='unexpected name {0}, expected {1}'.format(name,dataId)) @test(groups=['redfish.get_accounts'], depends_on_groups=['redfish.get_account_service']) def test_get_accounts(self): """ Testing GET /AcountService/Accounts """ redfish().get_accounts() accounts = self.__get_data() LOG.debug(accounts,json=True) self.__accounts = accounts.get('Members') for member in self.__accounts: dataId = member.get('@odata.id') assert_not_equal(None,dataId) dataId = dataId.split('/redfish/v1/AccountService/Accounts/')[1] redfish().get_account(dataId) account = self.__get_data() LOG.debug(account,json=True) username = account.get('UserName') assert_equal(dataId, username, message='unexpected username {0}, expected {1}'.format(username,dataId)) @test(groups=['redfish.create_account'], depends_on_groups=['redfish.get_accounts']) def test_create_account(self): """ Testing POST /AcountService/Accounts """ body = { 'UserName': 'funtest-name', 'Password': 'funtest123', 'RoleId': 'Administrator' } redfish().create_account(payload=body) self.test_get_accounts() found = False for member in self.__accounts: dataId = member.get('@odata.id') assert_not_equal(None,dataId) dataId = dataId.split('/redfish/v1/AccountService/Accounts/')[1] if dataId == 'funtest-name': found = True redfish().get_account(dataId) account = self.__get_data() assert_equal(account.get('RoleId'), 'Administrator', message='unexpected RoleId') break if not found: fail(message='newly created user was not found') @test(groups=['redfish.modify_account'], depends_on_groups=['redfish.create_account']) def test_modify_account(self): """ Testing PATCH /AcountService/Accounts/{name} """ body = { 'Password': 'funtest456', 'RoleId': 'ReadOnly' } redfish().modify_account('funtest-name', payload=body) redfish().get_account('funtest-name') account = self.__get_data() assert_equal(account.get('RoleId'), 'ReadOnly', message='unexpected RoleId') @test(groups=['redfish.remove_account'], depends_on_groups=['redfish.create_account']) def test_remove_account(self): redfish().remove_account('funtest-name') self.test_get_accounts() found = False for member in self.__accounts: dataId = member.get('@odata.id') assert_not_equal(None,dataId) dataId = dataId.split('/redfish/v1/AccountService/Accounts/')[1] if dataId == 'funtest-name': fail(message='failed to delete account')
apache-2.0
[ 504, 1101, 14, 581, 16056, 17, 63, 16, 63, 888, 492, 627, 199, 504, 4621, 14, 2921, 492, 5297, 199, 504, 4621, 14, 581, 16056, 63, 1178, 492, 3590, 199, 504, 641, 63, 1014, 63, 581, 16056, 63, 17, 63, 16, 492, 9572, 16056, 86, 7394, 465, 8992, 16056, 199, 504, 641, 63, 1014, 63, 581, 16056, 63, 17, 63, 16, 492, 4618, 199, 504, 2197, 492, 2197, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 1452, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 3910, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 3536, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 1397, 63, 1452, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 2052, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 2449, 199, 504, 557, 656, 551, 374, 492, 18795, 199, 504, 557, 656, 551, 374, 492, 511, 199, 504, 2022, 492, 14404, 12, 4180, 199, 504, 557, 656, 551, 374, 492, 2544, 63, 533, 199, 504, 557, 656, 551, 374, 492, 2410, 63, 533, 421, 199, 4947, 275, 5297, 3460, 354, 3368, 199, 199, 32, 396, 8, 2634, 2968, 581, 16056, 14, 2048, 63, 1364, 14, 2219, 995, 8350, 63, 265, 63, 2634, 2968, 2873, 77, 14, 2219, 1105, 199, 533, 9973, 3167, 2925, 8, 785, 304, 339, 347, 636, 826, 721, 277, 304, 267, 291, 855, 1258, 275, 1101, 14, 1246, 63, 1258, 267, 291, 855, 8370, 275, 488, 267, 291, 855, 8050, 275, 488, 339, 768, 5182, 63, 533, 342, 272, 347, 3272, 8, 277, 304, 267, 408, 2758, 511, 3734, 624, 267, 3590, 14, 4296, 342, 339, 768, 4399, 63, 533, 8, 9223, 63, 1065, 29, 549, 9, 272, 347, 17558, 8, 277, 304, 267, 408, 9066, 511, 3734, 408, 267, 3590, 14, 5993, 342, 339, 347, 636, 362, 63, 576, 8, 277, 304, 267, 372, 14404, 8, 277, 855, 1258, 14, 2019, 63, 1310, 14, 576, 9, 339, 768, 396, 8, 2634, 2968, 581, 16056, 14, 362, 63, 2048, 63, 1364, 1105, 272, 347, 511, 63, 362, 63, 2048, 63, 1364, 8, 277, 304, 267, 408, 11940, 9576, 1182, 6009, 3167, 408, 267, 8992, 16056, 1252, 362, 63, 2048, 63, 1364, 342, 267, 2435, 275, 291, 855, 362, 63, 576, 342, 267, 5051, 14, 1757, 8, 1364, 12, 1001, 29, 549, 9, 267, 1305, 275, 2435, 14, 362, 360, 1304, 358, 267, 702, 63, 1452, 360, 6009, 3167, 297, 1305, 12, 1245, 534, 8953, 1305, 469, 16, 1386, 1420, 469, 17, 5285, 908, 8, 344, 2584, 6009, 3167, 1333, 267, 12639, 275, 2435, 14, 362, 360, 30682, 358, 267, 11689, 275, 2435, 14, 362, 360, 3863, 2978, 358, 267, 702, 63, 1397, 63, 1452, 8, 403, 12, 12639, 12, 1245, 534, 4276, 370, 664, 12639, 358, 267, 702, 63, 1397, 63, 1452, 8, 403, 12, 11689, 12, 1245, 534, 4276, 370, 664, 11689, 358, 339, 768, 396, 8, 2634, 2968, 581, 16056, 14, 513, 63, 8050, 995, 8350, 63, 265, 63, 2634, 2968, 581, 16056, 14, 362, 63, 2048, 63, 1364, 1105, 272, 347, 511, 63, 513, 63, 8050, 8, 277, 304, 267, 408, 11940, 9576, 1182, 33, 835, 3167, 15, 3863, 2978, 408, 267, 8992, 16056, 1252, 513, 63, 8050, 342, 267, 11689, 275, 291, 855, 362, 63, 576, 342, 267, 5051, 14, 1757, 8, 8050, 12, 1001, 29, 549, 9, 267, 291, 855, 8050, 275, 11689, 14, 362, 360, 23056, 358, 267, 702, 63, 1452, 8, 552, 8, 277, 855, 8050, 395, 650, 12, 1245, 534, 2062, 4719, 2582, 370, 506, 650, 358, 267, 367, 3653, 315, 291, 855, 8050, 26, 288, 666, 1304, 275, 3653, 14, 362, 16591, 22971, 14, 344, 358, 288, 702, 63, 1397, 63, 1452, 8, 403, 12, 576, 1304, 9, 288, 666, 1304, 275, 666, 1304, 14, 1294, 2336, 581, 16056, 15, 86, 17, 15, 6009, 3167, 15, 3863, 2978, 15, 5832, 17, 61, 288, 8992, 16056, 1252, 362, 63, 3756, 8, 576, 1304, 9, 288, 4719, 275, 291, 855, 362, 63, 576, 342, 288, 5051, 14, 1757, 8, 3756, 12, 1001, 29, 549, 9, 288, 536, 275, 4719, 14, 362, 360, 985, 358, 288, 702, 63, 1452, 8, 576, 1304, 12, 536, 12, 1245, 534, 8953, 536, 469, 16, 1386, 1420, 469, 17, 5285, 908, 8, 354, 12, 576, 1304, 430, 339, 768, 396, 8, 2634, 2968, 581, 16056, 14, 362, 63, 8370, 995, 8350, 63, 265, 63, 2634, 2968, 581, 16056, 14, 362, 63, 2048, 63, 1364, 1105, 272, 347, 511, 63, 362, 63, 8370, 8, 277, 304, 267, 408, 11940, 9576, 1182, 33, 835, 3167, 15, 30682, 408, 267, 8992, 16056, 1252, 362, 63, 8370, 342, 267, 12639, 275, 291, 855, 362, 63, 576, 342, 267, 5051, 14, 1757, 8, 8370, 12, 1001, 29, 549, 9, 267, 291, 855, 8370, 275, 12639, 14, 362, 360, 23056, 358, 267, 367, 3653, 315, 291, 855, 8370, 26, 288, 666, 1304, 275, 3653, 14, 362, 16591, 22971, 14, 344, 358, 288, 702, 63, 1397, 63, 1452, 8, 403, 12, 576, 1304, 9, 288, 666, 1304, 275, 666, 1304, 14, 1294, 2336, 581, 16056, 15, 86, 17, 15, 6009, 3167, 15, 30682, 15, 5832, 17, 61, 288, 8992, 16056, 1252, 362, 63, 2048, 8, 576, 1304, 9, 288, 2933, 275, 291, 855, 362, 63, 576, 342, 288, 5051, 14, 1757, 8, 2048, 12, 1001, 29, 549, 9, 288, 3434, 275, 2933, 14, 362, 360, 25108, 358, 288, 702, 63, 1452, 8, 576, 1304, 12, 3434, 12, 1245, 534, 8953, 3434, 469, 16, 1386, 1420, 469, 17, 5285, 908, 8, 2473, 12, 576, 1304, 430, 339, 768, 396, 8, 2634, 2968, 581, 16056, 14, 981, 63, 2048, 995, 8350, 63, 265, 63, 2634, 2968, 581, 16056, 14, 362, 63, 8370, 1105, 272, 347, 511, 63, 981, 63, 2048, 8, 277, 304, 267, 408, 11940, 8761, 1182, 33, 835, 3167, 15, 30682, 408, 267, 2396, 275, 469, 288, 283, 25108, 356, 283, 7036, 396, 13, 354, 297, 288, 283, 6139, 356, 283, 7036, 396, 4288, 297, 288, 283, 7422, 1304, 356, 283, 31972, 7, 267, 789, 267, 8992, 16056, 1252, 981 ]
[ 1101, 14, 581, 16056, 17, 63, 16, 63, 888, 492, 627, 199, 504, 4621, 14, 2921, 492, 5297, 199, 504, 4621, 14, 581, 16056, 63, 1178, 492, 3590, 199, 504, 641, 63, 1014, 63, 581, 16056, 63, 17, 63, 16, 492, 9572, 16056, 86, 7394, 465, 8992, 16056, 199, 504, 641, 63, 1014, 63, 581, 16056, 63, 17, 63, 16, 492, 4618, 199, 504, 2197, 492, 2197, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 1452, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 3910, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 3536, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 1397, 63, 1452, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 702, 63, 2052, 199, 504, 557, 656, 551, 374, 14, 479, 83, 492, 2449, 199, 504, 557, 656, 551, 374, 492, 18795, 199, 504, 557, 656, 551, 374, 492, 511, 199, 504, 2022, 492, 14404, 12, 4180, 199, 504, 557, 656, 551, 374, 492, 2544, 63, 533, 199, 504, 557, 656, 551, 374, 492, 2410, 63, 533, 421, 199, 4947, 275, 5297, 3460, 354, 3368, 199, 199, 32, 396, 8, 2634, 2968, 581, 16056, 14, 2048, 63, 1364, 14, 2219, 995, 8350, 63, 265, 63, 2634, 2968, 2873, 77, 14, 2219, 1105, 199, 533, 9973, 3167, 2925, 8, 785, 304, 339, 347, 636, 826, 721, 277, 304, 267, 291, 855, 1258, 275, 1101, 14, 1246, 63, 1258, 267, 291, 855, 8370, 275, 488, 267, 291, 855, 8050, 275, 488, 339, 768, 5182, 63, 533, 342, 272, 347, 3272, 8, 277, 304, 267, 408, 2758, 511, 3734, 624, 267, 3590, 14, 4296, 342, 339, 768, 4399, 63, 533, 8, 9223, 63, 1065, 29, 549, 9, 272, 347, 17558, 8, 277, 304, 267, 408, 9066, 511, 3734, 408, 267, 3590, 14, 5993, 342, 339, 347, 636, 362, 63, 576, 8, 277, 304, 267, 372, 14404, 8, 277, 855, 1258, 14, 2019, 63, 1310, 14, 576, 9, 339, 768, 396, 8, 2634, 2968, 581, 16056, 14, 362, 63, 2048, 63, 1364, 1105, 272, 347, 511, 63, 362, 63, 2048, 63, 1364, 8, 277, 304, 267, 408, 11940, 9576, 1182, 6009, 3167, 408, 267, 8992, 16056, 1252, 362, 63, 2048, 63, 1364, 342, 267, 2435, 275, 291, 855, 362, 63, 576, 342, 267, 5051, 14, 1757, 8, 1364, 12, 1001, 29, 549, 9, 267, 1305, 275, 2435, 14, 362, 360, 1304, 358, 267, 702, 63, 1452, 360, 6009, 3167, 297, 1305, 12, 1245, 534, 8953, 1305, 469, 16, 1386, 1420, 469, 17, 5285, 908, 8, 344, 2584, 6009, 3167, 1333, 267, 12639, 275, 2435, 14, 362, 360, 30682, 358, 267, 11689, 275, 2435, 14, 362, 360, 3863, 2978, 358, 267, 702, 63, 1397, 63, 1452, 8, 403, 12, 12639, 12, 1245, 534, 4276, 370, 664, 12639, 358, 267, 702, 63, 1397, 63, 1452, 8, 403, 12, 11689, 12, 1245, 534, 4276, 370, 664, 11689, 358, 339, 768, 396, 8, 2634, 2968, 581, 16056, 14, 513, 63, 8050, 995, 8350, 63, 265, 63, 2634, 2968, 581, 16056, 14, 362, 63, 2048, 63, 1364, 1105, 272, 347, 511, 63, 513, 63, 8050, 8, 277, 304, 267, 408, 11940, 9576, 1182, 33, 835, 3167, 15, 3863, 2978, 408, 267, 8992, 16056, 1252, 513, 63, 8050, 342, 267, 11689, 275, 291, 855, 362, 63, 576, 342, 267, 5051, 14, 1757, 8, 8050, 12, 1001, 29, 549, 9, 267, 291, 855, 8050, 275, 11689, 14, 362, 360, 23056, 358, 267, 702, 63, 1452, 8, 552, 8, 277, 855, 8050, 395, 650, 12, 1245, 534, 2062, 4719, 2582, 370, 506, 650, 358, 267, 367, 3653, 315, 291, 855, 8050, 26, 288, 666, 1304, 275, 3653, 14, 362, 16591, 22971, 14, 344, 358, 288, 702, 63, 1397, 63, 1452, 8, 403, 12, 576, 1304, 9, 288, 666, 1304, 275, 666, 1304, 14, 1294, 2336, 581, 16056, 15, 86, 17, 15, 6009, 3167, 15, 3863, 2978, 15, 5832, 17, 61, 288, 8992, 16056, 1252, 362, 63, 3756, 8, 576, 1304, 9, 288, 4719, 275, 291, 855, 362, 63, 576, 342, 288, 5051, 14, 1757, 8, 3756, 12, 1001, 29, 549, 9, 288, 536, 275, 4719, 14, 362, 360, 985, 358, 288, 702, 63, 1452, 8, 576, 1304, 12, 536, 12, 1245, 534, 8953, 536, 469, 16, 1386, 1420, 469, 17, 5285, 908, 8, 354, 12, 576, 1304, 430, 339, 768, 396, 8, 2634, 2968, 581, 16056, 14, 362, 63, 8370, 995, 8350, 63, 265, 63, 2634, 2968, 581, 16056, 14, 362, 63, 2048, 63, 1364, 1105, 272, 347, 511, 63, 362, 63, 8370, 8, 277, 304, 267, 408, 11940, 9576, 1182, 33, 835, 3167, 15, 30682, 408, 267, 8992, 16056, 1252, 362, 63, 8370, 342, 267, 12639, 275, 291, 855, 362, 63, 576, 342, 267, 5051, 14, 1757, 8, 8370, 12, 1001, 29, 549, 9, 267, 291, 855, 8370, 275, 12639, 14, 362, 360, 23056, 358, 267, 367, 3653, 315, 291, 855, 8370, 26, 288, 666, 1304, 275, 3653, 14, 362, 16591, 22971, 14, 344, 358, 288, 702, 63, 1397, 63, 1452, 8, 403, 12, 576, 1304, 9, 288, 666, 1304, 275, 666, 1304, 14, 1294, 2336, 581, 16056, 15, 86, 17, 15, 6009, 3167, 15, 30682, 15, 5832, 17, 61, 288, 8992, 16056, 1252, 362, 63, 2048, 8, 576, 1304, 9, 288, 2933, 275, 291, 855, 362, 63, 576, 342, 288, 5051, 14, 1757, 8, 2048, 12, 1001, 29, 549, 9, 288, 3434, 275, 2933, 14, 362, 360, 25108, 358, 288, 702, 63, 1452, 8, 576, 1304, 12, 3434, 12, 1245, 534, 8953, 3434, 469, 16, 1386, 1420, 469, 17, 5285, 908, 8, 2473, 12, 576, 1304, 430, 339, 768, 396, 8, 2634, 2968, 581, 16056, 14, 981, 63, 2048, 995, 8350, 63, 265, 63, 2634, 2968, 581, 16056, 14, 362, 63, 8370, 1105, 272, 347, 511, 63, 981, 63, 2048, 8, 277, 304, 267, 408, 11940, 8761, 1182, 33, 835, 3167, 15, 30682, 408, 267, 2396, 275, 469, 288, 283, 25108, 356, 283, 7036, 396, 13, 354, 297, 288, 283, 6139, 356, 283, 7036, 396, 4288, 297, 288, 283, 7422, 1304, 356, 283, 31972, 7, 267, 789, 267, 8992, 16056, 1252, 981, 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, 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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 ]
0x20h/graphite-web
misc/generate-apache-config.py
21
1339
#!/usr/bin/env python import sys, os from optparse import OptionParser option_parser = OptionParser() option_parser.add_option('--install-root',default='/opt/graphite/', help="The base directory of the graphite installation") option_parser.add_option('--libs',default=None, help="The directory where the graphite python package is installed (default is system site-packages)") (options,args) = option_parser.parse_args() install_root = options.install_root if not install_root.endswith('/'): install_root += '/' if not os.path.isdir(install_root): print "Graphite does not appear to be installed at %s, do you need to specify a different --install-root?" % install_root sys.exit(1) python_path = [ os.path.join(install_root,'webapp') ] if options.libs: python_path.append( options.libs ) import django django_root = django.__path__[0] vhost = open('misc/template-vhost.conf').read() vhost = vhost.replace('@INSTALL_ROOT@', install_root) vhost = vhost.replace('@PYTHON_PATH@', str(python_path)) vhost = vhost.replace('@DJANGO_ROOT@', django_root) fh = open('graphite-vhost.conf','w') fh.write(vhost) fh.close() print "Generated graphite-vhost.conf" print "Put this file in your apache installation's vhost include directory." print "NOTE: you must ensure that mod_python is properly configured before using Graphite."
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 646, 984, 12, 747, 199, 504, 8691, 492, 13491, 199, 199, 1422, 63, 2087, 275, 13491, 342, 199, 1422, 63, 2087, 14, 525, 63, 1422, 4517, 3174, 13, 1231, 297, 885, 8805, 2992, 15, 2180, 1175, 3678, 523, 1720, 628, 1918, 1300, 2082, 402, 314, 3343, 1175, 12096, 531, 199, 1422, 63, 2087, 14, 525, 63, 1422, 4517, 8450, 297, 885, 29, 403, 12, 523, 1720, 628, 1918, 2082, 2382, 314, 3343, 1175, 2366, 2559, 365, 4903, 334, 885, 365, 2656, 4770, 13, 5154, 6320, 199, 199, 8, 1419, 12, 589, 9, 275, 945, 63, 2087, 14, 1122, 63, 589, 342, 199, 199, 3174, 63, 1231, 275, 1511, 14, 3174, 63, 1231, 199, 692, 440, 3907, 63, 1231, 14, 4130, 18265, 523, 3907, 63, 1231, 847, 7324, 199, 199, 692, 440, 747, 14, 515, 14, 6027, 8, 3174, 63, 1231, 304, 523, 870, 298, 4578, 1175, 1630, 440, 7468, 370, 506, 4903, 737, 450, 83, 12, 886, 1265, 1929, 370, 4165, 282, 3365, 1553, 3174, 13, 1231, 13472, 450, 3907, 63, 1231, 523, 984, 14, 2224, 8, 17, 9, 199, 199, 1548, 63, 515, 275, 359, 747, 14, 515, 14, 904, 8, 3174, 63, 1231, 2584, 22632, 358, 1622, 199, 692, 1511, 14, 8450, 26, 523, 2366, 63, 515, 14, 740, 8, 1511, 14, 8450, 776, 199, 199, 646, 1639, 199, 1176, 63, 1231, 275, 1639, 855, 515, 12298, 16, 61, 199, 199, 32071, 275, 1551, 360, 9923, 15, 1160, 13, 32071, 14, 2190, 1959, 739, 342, 199, 32071, 275, 373, 1102, 14, 1814, 16591, 16811, 63, 5441, 32, 297, 3907, 63, 1231, 9, 199, 32071, 275, 373, 1102, 14, 1814, 16591, 11720, 63, 3243, 32, 297, 620, 8, 1548, 63, 515, 430, 199, 32071, 275, 373, 1102, 14, 1814, 16591, 22848, 63, 5441, 32, 297, 1639, 63, 1231, 9, 199, 199, 12853, 275, 1551, 360, 2180, 1175, 13, 32071, 14, 2190, 1673, 87, 358, 199, 12853, 14, 952, 8, 32071, 9, 199, 12853, 14, 1600, 342, 199, 199, 1361, 298, 12706, 3343, 1175, 13, 32071, 14, 2190, 2, 199, 1361, 298, 18989, 642, 570, 315, 2195, 17098, 12096, 1159, 373, 1102, 2387, 2082, 2122, 199, 1361, 298, 19855, 26, 1265, 1471, 4868, 626, 3413, 63, 1548, 365, 7684, 7526, 2544, 1808, 11513, 1175, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 646, 984, 12, 747, 199, 504, 8691, 492, 13491, 199, 199, 1422, 63, 2087, 275, 13491, 342, 199, 1422, 63, 2087, 14, 525, 63, 1422, 4517, 3174, 13, 1231, 297, 885, 8805, 2992, 15, 2180, 1175, 3678, 523, 1720, 628, 1918, 1300, 2082, 402, 314, 3343, 1175, 12096, 531, 199, 1422, 63, 2087, 14, 525, 63, 1422, 4517, 8450, 297, 885, 29, 403, 12, 523, 1720, 628, 1918, 2082, 2382, 314, 3343, 1175, 2366, 2559, 365, 4903, 334, 885, 365, 2656, 4770, 13, 5154, 6320, 199, 199, 8, 1419, 12, 589, 9, 275, 945, 63, 2087, 14, 1122, 63, 589, 342, 199, 199, 3174, 63, 1231, 275, 1511, 14, 3174, 63, 1231, 199, 692, 440, 3907, 63, 1231, 14, 4130, 18265, 523, 3907, 63, 1231, 847, 7324, 199, 199, 692, 440, 747, 14, 515, 14, 6027, 8, 3174, 63, 1231, 304, 523, 870, 298, 4578, 1175, 1630, 440, 7468, 370, 506, 4903, 737, 450, 83, 12, 886, 1265, 1929, 370, 4165, 282, 3365, 1553, 3174, 13, 1231, 13472, 450, 3907, 63, 1231, 523, 984, 14, 2224, 8, 17, 9, 199, 199, 1548, 63, 515, 275, 359, 747, 14, 515, 14, 904, 8, 3174, 63, 1231, 2584, 22632, 358, 1622, 199, 692, 1511, 14, 8450, 26, 523, 2366, 63, 515, 14, 740, 8, 1511, 14, 8450, 776, 199, 199, 646, 1639, 199, 1176, 63, 1231, 275, 1639, 855, 515, 12298, 16, 61, 199, 199, 32071, 275, 1551, 360, 9923, 15, 1160, 13, 32071, 14, 2190, 1959, 739, 342, 199, 32071, 275, 373, 1102, 14, 1814, 16591, 16811, 63, 5441, 32, 297, 3907, 63, 1231, 9, 199, 32071, 275, 373, 1102, 14, 1814, 16591, 11720, 63, 3243, 32, 297, 620, 8, 1548, 63, 515, 430, 199, 32071, 275, 373, 1102, 14, 1814, 16591, 22848, 63, 5441, 32, 297, 1639, 63, 1231, 9, 199, 199, 12853, 275, 1551, 360, 2180, 1175, 13, 32071, 14, 2190, 1673, 87, 358, 199, 12853, 14, 952, 8, 32071, 9, 199, 12853, 14, 1600, 342, 199, 199, 1361, 298, 12706, 3343, 1175, 13, 32071, 14, 2190, 2, 199, 1361, 298, 18989, 642, 570, 315, 2195, 17098, 12096, 1159, 373, 1102, 2387, 2082, 2122, 199, 1361, 298, 19855, 26, 1265, 1471, 4868, 626, 3413, 63, 1548, 365, 7684, 7526, 2544, 1808, 11513, 1175, 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, 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,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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 ]
tpodowd/boto
boto/cloudsearch/document.py
153
9780
# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/ # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. # All Rights Reserved # # 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.exception from boto.compat import json import requests import boto class SearchServiceException(Exception): pass class CommitMismatchError(Exception): pass class EncodingError(Exception): """ Content sent for Cloud Search indexing was incorrectly encoded. This usually happens when a document is marked as unicode but non-unicode characters are present. """ pass class ContentTooLongError(Exception): """ Content sent for Cloud Search indexing was too long This will usually happen when documents queued for indexing add up to more than the limit allowed per upload batch (5MB) """ pass class DocumentServiceConnection(object): """ A CloudSearch document service. The DocumentServiceConection is used to add, remove and update documents in CloudSearch. Commands are uploaded to CloudSearch in SDF (Search Document Format). To generate an appropriate SDF, use :func:`add` to add or update documents, as well as :func:`delete` to remove documents. Once the set of documents is ready to be index, use :func:`commit` to send the commands to CloudSearch. If there are a lot of documents to index, it may be preferable to split the generation of SDF data and the actual uploading into CloudSearch. Retrieve the current SDF with :func:`get_sdf`. If this file is the uploaded into S3, it can be retrieved back afterwards for upload into CloudSearch using :func:`add_sdf_from_s3`. The SDF is not cleared after a :func:`commit`. If you wish to continue using the DocumentServiceConnection for another batch upload of commands, you will need to :func:`clear_sdf` first to stop the previous batch of commands from being uploaded again. """ def __init__(self, domain=None, endpoint=None): self.domain = domain self.endpoint = endpoint if not self.endpoint: self.endpoint = domain.doc_service_endpoint self.documents_batch = [] self._sdf = None def add(self, _id, version, fields, lang='en'): """ Add a document to be processed by the DocumentService The document will not actually be added until :func:`commit` is called :type _id: string :param _id: A unique ID used to refer to this document. :type version: int :param version: Version of the document being indexed. If a file is being reindexed, the version should be higher than the existing one in CloudSearch. :type fields: dict :param fields: A dictionary of key-value pairs to be uploaded . :type lang: string :param lang: The language code the data is in. Only 'en' is currently supported """ d = {'type': 'add', 'id': _id, 'version': version, 'lang': lang, 'fields': fields} self.documents_batch.append(d) def delete(self, _id, version): """ Schedule a document to be removed from the CloudSearch service The document will not actually be scheduled for removal until :func:`commit` is called :type _id: string :param _id: The unique ID of this document. :type version: int :param version: Version of the document to remove. The delete will only occur if this version number is higher than the version currently in the index. """ d = {'type': 'delete', 'id': _id, 'version': version} self.documents_batch.append(d) def get_sdf(self): """ Generate the working set of documents in Search Data Format (SDF) :rtype: string :returns: JSON-formatted string of the documents in SDF """ return self._sdf if self._sdf else json.dumps(self.documents_batch) def clear_sdf(self): """ Clear the working documents from this DocumentServiceConnection This should be used after :func:`commit` if the connection will be reused for another set of documents. """ self._sdf = None self.documents_batch = [] def add_sdf_from_s3(self, key_obj): """ Load an SDF from S3 Using this method will result in documents added through :func:`add` and :func:`delete` being ignored. :type key_obj: :class:`boto.s3.key.Key` :param key_obj: An S3 key which contains an SDF """ #@todo:: (lucas) would be nice if this could just take an s3://uri..." self._sdf = key_obj.get_contents_as_string() def commit(self): """ Actually send an SDF to CloudSearch for processing If an SDF file has been explicitly loaded it will be used. Otherwise, documents added through :func:`add` and :func:`delete` will be used. :rtype: :class:`CommitResponse` :returns: A summary of documents added and deleted """ sdf = self.get_sdf() if ': null' in sdf: boto.log.error('null value in sdf detected. This will probably raise ' '500 error.') index = sdf.index(': null') boto.log.error(sdf[index - 100:index + 100]) url = "http://%s/2011-02-01/documents/batch" % (self.endpoint) # Keep-alive is automatic in a post-1.0 requests world. session = requests.Session() adapter = requests.adapters.HTTPAdapter( pool_connections=20, pool_maxsize=50, max_retries=5 ) session.mount('http://', adapter) session.mount('https://', adapter) r = session.post(url, data=sdf, headers={'Content-Type': 'application/json'}) return CommitResponse(r, self, sdf) class CommitResponse(object): """Wrapper for response to Cloudsearch document batch commit. :type response: :class:`requests.models.Response` :param response: Response from Cloudsearch /documents/batch API :type doc_service: :class:`boto.cloudsearch.document.DocumentServiceConnection` :param doc_service: Object containing the documents posted and methods to retry :raises: :class:`boto.exception.BotoServerError` :raises: :class:`boto.cloudsearch.document.SearchServiceException` :raises: :class:`boto.cloudsearch.document.EncodingError` :raises: :class:`boto.cloudsearch.document.ContentTooLongError` """ def __init__(self, response, doc_service, sdf): self.response = response self.doc_service = doc_service self.sdf = sdf _body = response.content.decode('utf-8') try: self.content = json.loads(_body) except: boto.log.error('Error indexing documents.\nResponse Content:\n{0}\n\n' 'SDF:\n{1}'.format(_body, self.sdf)) raise boto.exception.BotoServerError(self.response.status_code, '', body=_body) self.status = self.content['status'] if self.status == 'error': self.errors = [e.get('message') for e in self.content.get('errors', [])] for e in self.errors: if "Illegal Unicode character" in e: raise EncodingError("Illegal Unicode character in document") elif e == "The Content-Length is too long": raise ContentTooLongError("Content was too long") if 'adds' not in self.content or 'deletes' not in self.content: raise SearchServiceException("Error indexing documents" " => %s" % self.content.get('message', '')) else: self.errors = [] self.adds = self.content['adds'] self.deletes = self.content['deletes'] self._check_num_ops('add', self.adds) self._check_num_ops('delete', self.deletes) def _check_num_ops(self, type_, response_num): """Raise exception if number of ops in response doesn't match commit :type type_: str :param type_: Type of commit operation: 'add' or 'delete' :type response_num: int :param response_num: Number of adds or deletes in the response. :raises: :class:`boto.cloudsearch.document.CommitMismatchError` """ commit_num = len([d for d in self.doc_service.documents_batch if d['type'] == type_]) if response_num != commit_num: raise CommitMismatchError( 'Incorrect number of {0}s returned. Commit: {1} Response: {2}'\ .format(type_, commit_num, response_num))
mit
[ 3, 1898, 334, 67, 9, 6029, 603, 9414, 598, 26272, 1455, 921, 71, 26272, 14, 1308, 15, 199, 3, 1898, 334, 67, 9, 6029, 14347, 14, 957, 12, 3277, 14, 503, 2399, 29172, 2335, 14, 199, 3, 2900, 5924, 5702, 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, 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, 199, 646, 6055, 14, 1971, 199, 504, 6055, 14, 5819, 492, 2022, 199, 646, 4145, 199, 646, 6055, 199, 199, 533, 8730, 3167, 1726, 8, 1726, 304, 272, 986, 421, 199, 533, 21447, 23055, 547, 8, 1726, 304, 272, 986, 199, 199, 533, 19694, 547, 8, 1726, 304, 272, 408, 272, 6646, 4847, 367, 8142, 8730, 16356, 1990, 22743, 5737, 14, 339, 961, 9987, 10986, 1380, 282, 2213, 365, 11584, 465, 2649, 1325, 2222, 13, 2975, 272, 4110, 787, 3451, 14, 272, 408, 272, 986, 199, 199, 533, 6646, 13749, 9551, 547, 8, 1726, 304, 272, 408, 272, 6646, 4847, 367, 8142, 8730, 16356, 1990, 4634, 1846, 339, 961, 911, 9987, 5992, 1380, 8247, 26102, 367, 16356, 1050, 1536, 370, 1655, 272, 2419, 314, 2304, 4370, 1126, 5802, 3522, 334, 21, 4567, 9, 339, 408, 272, 986, 199, 199, 533, 7543, 3167, 3225, 8, 785, 304, 272, 408, 272, 437, 8142, 5278, 2213, 2435, 14, 339, 710, 7543, 3167, 35, 368, 414, 365, 1202, 370, 1050, 12, 2813, 436, 1678, 8247, 315, 272, 8142, 5278, 14, 5817, 83, 787, 14238, 370, 8142, 5278, 315, 428, 3888, 334, 5278, 7543, 9701, 680, 339, 4005, 3550, 376, 5827, 428, 3888, 12, 675, 520, 1532, 1705, 525, 64, 370, 1050, 503, 1678, 8247, 12, 272, 465, 5521, 465, 520, 1532, 1705, 1807, 64, 370, 2813, 8247, 14, 339, 19468, 314, 663, 402, 8247, 365, 10144, 370, 506, 1478, 12, 675, 520, 1532, 1705, 3543, 64, 370, 3222, 314, 272, 3718, 370, 8142, 5278, 14, 339, 982, 2337, 787, 282, 13918, 402, 8247, 370, 1478, 12, 652, 1443, 506, 16602, 461, 370, 3715, 314, 272, 10152, 402, 428, 3888, 666, 436, 314, 3503, 24349, 1901, 8142, 5278, 14, 13939, 272, 314, 1453, 428, 3888, 543, 520, 1532, 1705, 362, 63, 83, 1587, 2313, 982, 642, 570, 365, 314, 14238, 1901, 428, 19, 12, 272, 652, 883, 506, 12396, 1771, 26982, 367, 5802, 1901, 8142, 5278, 1808, 272, 520, 1532, 1705, 525, 63, 83, 1587, 63, 504, 63, 83, 19, 2313, 339, 710, 428, 3888, 365, 440, 20518, 2410, 282, 520, 1532, 1705, 3543, 2313, 982, 1265, 13809, 370, 1980, 272, 1808, 314, 7543, 3167, 3225, 367, 4573, 3522, 5802, 402, 3718, 12, 272, 1265, 911, 1929, 370, 520, 1532, 1705, 3584, 63, 83, 1587, 64, 1642, 370, 3631, 314, 4136, 3522, 402, 272, 3718, 687, 3769, 14238, 4020, 14, 339, 408, 339, 347, 636, 826, 721, 277, 12, 2881, 29, 403, 12, 6037, 29, 403, 304, 267, 291, 14, 2261, 275, 2881, 267, 291, 14, 6520, 275, 6037, 267, 340, 440, 291, 14, 6520, 26, 288, 291, 14, 6520, 275, 2881, 14, 1301, 63, 1364, 63, 6520, 267, 291, 14, 12233, 63, 2912, 275, 942, 267, 291, 423, 83, 1587, 275, 488, 339, 347, 1050, 8, 277, 12, 485, 344, 12, 1015, 12, 1504, 12, 6339, 534, 287, 735, 267, 408, 267, 2654, 282, 2213, 370, 506, 7686, 701, 314, 7543, 3167, 398, 710, 2213, 911, 440, 5965, 506, 3483, 5133, 520, 1532, 1705, 3543, 64, 365, 2797, 398, 520, 466, 485, 344, 26, 1059, 267, 520, 635, 485, 344, 26, 437, 3747, 2870, 1202, 370, 10618, 370, 642, 2213, 14, 398, 520, 466, 1015, 26, 1109, 267, 520, 635, 1015, 26, 3394, 402, 314, 2213, 3769, 15235, 14, 982, 282, 570, 365, 288, 3769, 295, 16821, 12, 314, 1015, 1077, 506, 10948, 2419, 314, 3411, 1373, 288, 315, 8142, 5278, 14, 398, 520, 466, 1504, 26, 1211, 267, 520, 635, 1504, 26, 437, 2600, 402, 790, 13, 585, 6342, 370, 506, 14238, 1275, 398, 520, 466, 6339, 26, 1059, 267, 520, 635, 6339, 26, 710, 2637, 1233, 314, 666, 365, 315, 14, 5972, 283, 287, 7, 365, 5544, 288, 3748, 267, 408, 398, 366, 275, 791, 466, 356, 283, 525, 297, 283, 344, 356, 485, 344, 12, 283, 1023, 356, 1015, 12, 283, 4159, 356, 6339, 12, 288, 283, 955, 356, 1504, 93, 267, 291, 14, 12233, 63, 2912, 14, 740, 8, 68, 9, 339, 347, 3145, 8, 277, 12, 485, 344, 12, 1015, 304, 267, 408, 267, 24317, 282, 2213, 370, 506, 4829, 687, 314, 8142, 5278, 2435, 398, 710, 2213, 911, 440, 5965, 506, 18416, 367, 20055, 5133, 520, 1532, 1705, 3543, 64, 365, 2797, 398, 520, 466, 485, 344, 26, 1059, 267, 520, 635, 485, 344, 26, 710, 3747, 2870, 402, 642, 2213, 14, 398, 520, 466, 1015, 26, 1109, 267, 520, 635, 1015, 26, 3394, 402, 314, 2213, 370, 2813, 14, 710, 3145, 911, 1454, 288 ]
[ 1898, 334, 67, 9, 6029, 603, 9414, 598, 26272, 1455, 921, 71, 26272, 14, 1308, 15, 199, 3, 1898, 334, 67, 9, 6029, 14347, 14, 957, 12, 3277, 14, 503, 2399, 29172, 2335, 14, 199, 3, 2900, 5924, 5702, 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, 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, 199, 646, 6055, 14, 1971, 199, 504, 6055, 14, 5819, 492, 2022, 199, 646, 4145, 199, 646, 6055, 199, 199, 533, 8730, 3167, 1726, 8, 1726, 304, 272, 986, 421, 199, 533, 21447, 23055, 547, 8, 1726, 304, 272, 986, 199, 199, 533, 19694, 547, 8, 1726, 304, 272, 408, 272, 6646, 4847, 367, 8142, 8730, 16356, 1990, 22743, 5737, 14, 339, 961, 9987, 10986, 1380, 282, 2213, 365, 11584, 465, 2649, 1325, 2222, 13, 2975, 272, 4110, 787, 3451, 14, 272, 408, 272, 986, 199, 199, 533, 6646, 13749, 9551, 547, 8, 1726, 304, 272, 408, 272, 6646, 4847, 367, 8142, 8730, 16356, 1990, 4634, 1846, 339, 961, 911, 9987, 5992, 1380, 8247, 26102, 367, 16356, 1050, 1536, 370, 1655, 272, 2419, 314, 2304, 4370, 1126, 5802, 3522, 334, 21, 4567, 9, 339, 408, 272, 986, 199, 199, 533, 7543, 3167, 3225, 8, 785, 304, 272, 408, 272, 437, 8142, 5278, 2213, 2435, 14, 339, 710, 7543, 3167, 35, 368, 414, 365, 1202, 370, 1050, 12, 2813, 436, 1678, 8247, 315, 272, 8142, 5278, 14, 5817, 83, 787, 14238, 370, 8142, 5278, 315, 428, 3888, 334, 5278, 7543, 9701, 680, 339, 4005, 3550, 376, 5827, 428, 3888, 12, 675, 520, 1532, 1705, 525, 64, 370, 1050, 503, 1678, 8247, 12, 272, 465, 5521, 465, 520, 1532, 1705, 1807, 64, 370, 2813, 8247, 14, 339, 19468, 314, 663, 402, 8247, 365, 10144, 370, 506, 1478, 12, 675, 520, 1532, 1705, 3543, 64, 370, 3222, 314, 272, 3718, 370, 8142, 5278, 14, 339, 982, 2337, 787, 282, 13918, 402, 8247, 370, 1478, 12, 652, 1443, 506, 16602, 461, 370, 3715, 314, 272, 10152, 402, 428, 3888, 666, 436, 314, 3503, 24349, 1901, 8142, 5278, 14, 13939, 272, 314, 1453, 428, 3888, 543, 520, 1532, 1705, 362, 63, 83, 1587, 2313, 982, 642, 570, 365, 314, 14238, 1901, 428, 19, 12, 272, 652, 883, 506, 12396, 1771, 26982, 367, 5802, 1901, 8142, 5278, 1808, 272, 520, 1532, 1705, 525, 63, 83, 1587, 63, 504, 63, 83, 19, 2313, 339, 710, 428, 3888, 365, 440, 20518, 2410, 282, 520, 1532, 1705, 3543, 2313, 982, 1265, 13809, 370, 1980, 272, 1808, 314, 7543, 3167, 3225, 367, 4573, 3522, 5802, 402, 3718, 12, 272, 1265, 911, 1929, 370, 520, 1532, 1705, 3584, 63, 83, 1587, 64, 1642, 370, 3631, 314, 4136, 3522, 402, 272, 3718, 687, 3769, 14238, 4020, 14, 339, 408, 339, 347, 636, 826, 721, 277, 12, 2881, 29, 403, 12, 6037, 29, 403, 304, 267, 291, 14, 2261, 275, 2881, 267, 291, 14, 6520, 275, 6037, 267, 340, 440, 291, 14, 6520, 26, 288, 291, 14, 6520, 275, 2881, 14, 1301, 63, 1364, 63, 6520, 267, 291, 14, 12233, 63, 2912, 275, 942, 267, 291, 423, 83, 1587, 275, 488, 339, 347, 1050, 8, 277, 12, 485, 344, 12, 1015, 12, 1504, 12, 6339, 534, 287, 735, 267, 408, 267, 2654, 282, 2213, 370, 506, 7686, 701, 314, 7543, 3167, 398, 710, 2213, 911, 440, 5965, 506, 3483, 5133, 520, 1532, 1705, 3543, 64, 365, 2797, 398, 520, 466, 485, 344, 26, 1059, 267, 520, 635, 485, 344, 26, 437, 3747, 2870, 1202, 370, 10618, 370, 642, 2213, 14, 398, 520, 466, 1015, 26, 1109, 267, 520, 635, 1015, 26, 3394, 402, 314, 2213, 3769, 15235, 14, 982, 282, 570, 365, 288, 3769, 295, 16821, 12, 314, 1015, 1077, 506, 10948, 2419, 314, 3411, 1373, 288, 315, 8142, 5278, 14, 398, 520, 466, 1504, 26, 1211, 267, 520, 635, 1504, 26, 437, 2600, 402, 790, 13, 585, 6342, 370, 506, 14238, 1275, 398, 520, 466, 6339, 26, 1059, 267, 520, 635, 6339, 26, 710, 2637, 1233, 314, 666, 365, 315, 14, 5972, 283, 287, 7, 365, 5544, 288, 3748, 267, 408, 398, 366, 275, 791, 466, 356, 283, 525, 297, 283, 344, 356, 485, 344, 12, 283, 1023, 356, 1015, 12, 283, 4159, 356, 6339, 12, 288, 283, 955, 356, 1504, 93, 267, 291, 14, 12233, 63, 2912, 14, 740, 8, 68, 9, 339, 347, 3145, 8, 277, 12, 485, 344, 12, 1015, 304, 267, 408, 267, 24317, 282, 2213, 370, 506, 4829, 687, 314, 8142, 5278, 2435, 398, 710, 2213, 911, 440, 5965, 506, 18416, 367, 20055, 5133, 520, 1532, 1705, 3543, 64, 365, 2797, 398, 520, 466, 485, 344, 26, 1059, 267, 520, 635, 485, 344, 26, 710, 3747, 2870, 402, 642, 2213, 14, 398, 520, 466, 1015, 26, 1109, 267, 520, 635, 1015, 26, 3394, 402, 314, 2213, 370, 2813, 14, 710, 3145, 911, 1454, 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,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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 ]
thepiper/standoff
venv/lib/python2.7/site-packages/werkzeug/contrib/securecookie.py
254
12206
# -*- coding: utf-8 -*- r""" werkzeug.contrib.securecookie ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This module implements a cookie that is not alterable from the client because it adds a checksum the server checks for. You can use it as session replacement if all you have is a user id or something to mark a logged in user. Keep in mind that the data is still readable from the client as a normal cookie is. However you don't have to store and flush the sessions you have at the server. Example usage: >>> from werkzeug.contrib.securecookie import SecureCookie >>> x = SecureCookie({"foo": 42, "baz": (1, 2, 3)}, "deadbeef") Dumping into a string so that one can store it in a cookie: >>> value = x.serialize() Loading from that string again: >>> x = SecureCookie.unserialize(value, "deadbeef") >>> x["baz"] (1, 2, 3) If someone modifies the cookie and the checksum is wrong the unserialize method will fail silently and return a new empty `SecureCookie` object. Keep in mind that the values will be visible in the cookie so do not store data in a cookie you don't want the user to see. Application Integration ======================= If you are using the werkzeug request objects you could integrate the secure cookie into your application like this:: from werkzeug.utils import cached_property from werkzeug.wrappers import BaseRequest from werkzeug.contrib.securecookie import SecureCookie # don't use this key but a different one; you could just use # os.urandom(20) to get something random SECRET_KEY = '\xfa\xdd\xb8z\xae\xe0}4\x8b\xea' class Request(BaseRequest): @cached_property def client_session(self): data = self.cookies.get('session_data') if not data: return SecureCookie(secret_key=SECRET_KEY) return SecureCookie.unserialize(data, SECRET_KEY) def application(environ, start_response): request = Request(environ, start_response) # get a response object here response = ... if request.client_session.should_save: session_data = request.client_session.serialize() response.set_cookie('session_data', session_data, httponly=True) return response(environ, start_response) A less verbose integration can be achieved by using shorthand methods:: class Request(BaseRequest): @cached_property def client_session(self): return SecureCookie.load_cookie(self, secret_key=COOKIE_SECRET) def application(environ, start_response): request = Request(environ, start_response) # get a response object here response = ... request.client_session.save_cookie(response) return response(environ, start_response) :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. """ import pickle import base64 from hmac import new as hmac from time import time from hashlib import sha1 as _default_hash from werkzeug._compat import iteritems, text_type from werkzeug.urls import url_quote_plus, url_unquote_plus from werkzeug._internal import _date_to_unix from werkzeug.contrib.sessions import ModificationTrackingDict from werkzeug.security import safe_str_cmp from werkzeug._compat import to_native class UnquoteError(Exception): """Internal exception used to signal failures on quoting.""" class SecureCookie(ModificationTrackingDict): """Represents a secure cookie. You can subclass this class and provide an alternative mac method. The import thing is that the mac method is a function with a similar interface to the hashlib. Required methods are update() and digest(). Example usage: >>> x = SecureCookie({"foo": 42, "baz": (1, 2, 3)}, "deadbeef") >>> x["foo"] 42 >>> x["baz"] (1, 2, 3) >>> x["blafasel"] = 23 >>> x.should_save True :param data: the initial data. Either a dict, list of tuples or `None`. :param secret_key: the secret key. If not set `None` or not specified it has to be set before :meth:`serialize` is called. :param new: The initial value of the `new` flag. """ #: The hash method to use. This has to be a module with a new function #: or a function that creates a hashlib object. Such as `hashlib.md5` #: Subclasses can override this attribute. The default hash is sha1. #: Make sure to wrap this in staticmethod() if you store an arbitrary #: function there such as hashlib.sha1 which might be implemented #: as a function. hash_method = staticmethod(_default_hash) #: the module used for serialization. Unless overriden by subclasses #: the standard pickle module is used. serialization_method = pickle #: if the contents should be base64 quoted. This can be disabled if the #: serialization process returns cookie safe strings only. quote_base64 = True def __init__(self, data=None, secret_key=None, new=True): ModificationTrackingDict.__init__(self, data or ()) # explicitly convert it into a bytestring because python 2.6 # no longer performs an implicit string conversion on hmac if secret_key is not None: secret_key = bytes(secret_key) self.secret_key = secret_key self.new = new def __repr__(self): return '<%s %s%s>' % ( self.__class__.__name__, dict.__repr__(self), self.should_save and '*' or '' ) @property def should_save(self): """True if the session should be saved. By default this is only true for :attr:`modified` cookies, not :attr:`new`. """ return self.modified @classmethod def quote(cls, value): """Quote the value for the cookie. This can be any object supported by :attr:`serialization_method`. :param value: the value to quote. """ if cls.serialization_method is not None: value = cls.serialization_method.dumps(value) if cls.quote_base64: value = b''.join(base64.b64encode(value).splitlines()).strip() return value @classmethod def unquote(cls, value): """Unquote the value for the cookie. If unquoting does not work a :exc:`UnquoteError` is raised. :param value: the value to unquote. """ try: if cls.quote_base64: value = base64.b64decode(value) if cls.serialization_method is not None: value = cls.serialization_method.loads(value) return value except Exception: # unfortunately pickle and other serialization modules can # cause pretty every error here. if we get one we catch it # and convert it into an UnquoteError raise UnquoteError() def serialize(self, expires=None): """Serialize the secure cookie into a string. If expires is provided, the session will be automatically invalidated after expiration when you unseralize it. This provides better protection against session cookie theft. :param expires: an optional expiration date for the cookie (a :class:`datetime.datetime` object) """ if self.secret_key is None: raise RuntimeError('no secret key defined') if expires: self['_expires'] = _date_to_unix(expires) result = [] mac = hmac(self.secret_key, None, self.hash_method) for key, value in sorted(self.items()): result.append(('%s=%s' % ( url_quote_plus(key), self.quote(value).decode('ascii') )).encode('ascii')) mac.update(b'|' + result[-1]) return b'?'.join([ base64.b64encode(mac.digest()).strip(), b'&'.join(result) ]) @classmethod def unserialize(cls, string, secret_key): """Load the secure cookie from a serialized string. :param string: the cookie value to unserialize. :param secret_key: the secret key used to serialize the cookie. :return: a new :class:`SecureCookie`. """ if isinstance(string, text_type): string = string.encode('utf-8', 'replace') if isinstance(secret_key, text_type): secret_key = secret_key.encode('utf-8', 'replace') try: base64_hash, data = string.split(b'?', 1) except (ValueError, IndexError): items = () else: items = {} mac = hmac(secret_key, None, cls.hash_method) for item in data.split(b'&'): mac.update(b'|' + item) if b'=' not in item: items = None break key, value = item.split(b'=', 1) # try to make the key a string key = url_unquote_plus(key.decode('ascii')) try: key = to_native(key) except UnicodeError: pass items[key] = value # no parsing error and the mac looks okay, we can now # sercurely unpickle our cookie. try: client_hash = base64.b64decode(base64_hash) except TypeError: items = client_hash = None if items is not None and safe_str_cmp(client_hash, mac.digest()): try: for key, value in iteritems(items): items[key] = cls.unquote(value) except UnquoteError: items = () else: if '_expires' in items: if time() > items['_expires']: items = () else: del items['_expires'] else: items = () return cls(items, secret_key, False) @classmethod def load_cookie(cls, request, key='session', secret_key=None): """Loads a :class:`SecureCookie` from a cookie in request. If the cookie is not set, a new :class:`SecureCookie` instanced is returned. :param request: a request object that has a `cookies` attribute which is a dict of all cookie values. :param key: the name of the cookie. :param secret_key: the secret key used to unquote the cookie. Always provide the value even though it has no default! """ data = request.cookies.get(key) if not data: return cls(secret_key=secret_key) return cls.unserialize(data, secret_key) def save_cookie(self, response, key='session', expires=None, session_expires=None, max_age=None, path='/', domain=None, secure=None, httponly=False, force=False): """Saves the SecureCookie in a cookie on response object. All parameters that are not described here are forwarded directly to :meth:`~BaseResponse.set_cookie`. :param response: a response object that has a :meth:`~BaseResponse.set_cookie` method. :param key: the name of the cookie. :param session_expires: the expiration date of the secure cookie stored information. If this is not provided the cookie `expires` date is used instead. """ if force or self.should_save: data = self.serialize(session_expires or expires) response.set_cookie(key, data, expires=expires, max_age=max_age, path=path, domain=domain, secure=secure, httponly=httponly)
gpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 82, 624, 272, 10380, 14, 2828, 14, 7817, 5306, 272, 18294, 22935, 94, 339, 961, 859, 9031, 282, 5494, 626, 365, 440, 741, 13048, 687, 314, 1890, 272, 2952, 652, 9584, 282, 9040, 314, 1654, 5920, 367, 14, 221, 2047, 883, 675, 652, 465, 272, 2351, 8343, 340, 1006, 1265, 1172, 365, 282, 922, 1305, 503, 6020, 370, 2216, 272, 282, 10367, 315, 922, 14, 339, 14797, 315, 25169, 626, 314, 666, 365, 5139, 12701, 687, 314, 1890, 465, 282, 272, 3293, 5494, 365, 14, 221, 9738, 1265, 2793, 1133, 1172, 370, 3877, 436, 8976, 314, 272, 12184, 1265, 1172, 737, 314, 1654, 14, 339, 5679, 4503, 26, 339, 1306, 687, 10380, 14, 2828, 14, 7817, 5306, 492, 30894, 7810, 272, 1306, 671, 275, 30894, 7810, 6333, 1421, 582, 5685, 12, 298, 6185, 582, 334, 17, 12, 499, 12, 650, 16658, 298, 10957, 19446, 70, 531, 339, 19460, 316, 1901, 282, 1059, 880, 626, 1373, 883, 3877, 652, 315, 282, 5494, 26, 339, 1306, 574, 275, 671, 14, 3549, 342, 339, 3835, 5384, 687, 626, 1059, 4020, 26, 339, 1306, 671, 275, 30894, 7810, 14, 324, 3549, 8, 585, 12, 298, 10957, 19446, 70, 531, 272, 1306, 671, 905, 6185, 937, 272, 334, 17, 12, 499, 12, 650, 9, 339, 982, 17122, 26473, 314, 5494, 436, 314, 9040, 365, 6835, 314, 625, 3549, 272, 1083, 911, 2449, 18030, 436, 372, 282, 892, 2701, 658, 24117, 7810, 64, 909, 14, 339, 14797, 315, 25169, 626, 314, 1338, 911, 506, 8917, 315, 314, 5494, 880, 886, 440, 272, 3877, 666, 315, 282, 5494, 1265, 2793, 1133, 2934, 314, 922, 370, 1937, 14, 339, 13515, 27561, 272, 16248, 23476, 339, 982, 1265, 787, 1808, 314, 10380, 1056, 2251, 1265, 4293, 21494, 314, 272, 11153, 5494, 1901, 2195, 4223, 2839, 642, 447, 398, 687, 10380, 14, 1208, 492, 6328, 63, 1829, 267, 687, 10380, 14, 21148, 492, 3523, 2017, 267, 687, 10380, 14, 2828, 14, 7817, 5306, 492, 30894, 7810, 398, 327, 2793, 1133, 675, 642, 790, 1325, 282, 3365, 1373, 27, 1265, 4293, 2951, 675, 267, 327, 747, 14, 22776, 8, 1165, 9, 370, 664, 6020, 2196, 267, 5795, 11771, 63, 3078, 275, 1557, 10500, 60, 11110, 60, 1774, 24, 90, 60, 10183, 60, 1845, 16, 93, 20, 60, 88, 24, 66, 60, 10656, 7, 398, 1021, 4784, 8, 1563, 2017, 304, 953, 768, 5245, 63, 1829, 288, 347, 1890, 63, 1730, 8, 277, 304, 355, 666, 275, 291, 14, 7792, 14, 362, 360, 1730, 63, 576, 358, 355, 340, 440, 666, 26, 490, 372, 30894, 7810, 8, 4731, 63, 498, 29, 12961, 63, 3078, 9, 355, 372, 30894, 7810, 14, 324, 3549, 8, 576, 12, 5795, 11771, 63, 3078, 9, 398, 347, 4223, 8, 2314, 12, 1343, 63, 1310, 304, 288, 1056, 275, 4784, 8, 2314, 12, 1343, 63, 1310, 9, 953, 327, 664, 282, 1177, 909, 2348, 288, 1177, 275, 2263, 953, 340, 1056, 14, 1258, 63, 1730, 14, 5626, 63, 2117, 26, 355, 2351, 63, 576, 275, 1056, 14, 1258, 63, 1730, 14, 3549, 342, 355, 1177, 14, 409, 63, 5306, 360, 1730, 63, 576, 297, 2351, 63, 576, 12, 2511, 22768, 26960, 29, 549, 9, 288, 372, 1177, 8, 2314, 12, 1343, 63, 1310, 9, 339, 437, 6656, 3376, 13150, 883, 506, 22175, 1354, 701, 1808, 1033, 23999, 3102, 447, 398, 1021, 4784, 8, 1563, 2017, 304, 953, 768, 5245, 63, 1829, 288, 347, 1890, 63, 1730, 8, 277, 304, 355, 372, 30894, 7810, 14, 912, 63, 5306, 8, 277, 12, 7565, 63, 498, 29, 13665, 63, 12961, 9, 398, 347, 4223, 8, 2314, 12, 1343, 63, 1310, 304, 288, 1056, 275, 4784, 8, 2314, 12, 1343, 63, 1310, 9, 953, 327, 664, 282, 1177, 909, 2348, 288, 1177, 275, 2263, 953, 1056, 14, 1258, 63, 1730, 14, 2117, 63, 5306, 8, 1310, 9, 288, 372, 1177, 8, 2314, 12, 1343, 63, 1310, 9, 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, 5927, 199, 646, 1300, 772, 199, 504, 20330, 492, 892, 465, 20330, 199, 504, 900, 492, 900, 199, 504, 8337, 492, 7793, 17, 465, 485, 885, 63, 2227, 199, 199, 504, 10380, 423, 5819, 492, 10849, 12, 1318, 63, 466, 199, 504, 10380, 14, 3603, 492, 1166, 63, 3513, 63, 6666, 12, 1166, 63, 12240, 63, 6666, 199, 504, 10380, 423, 4672, 492, 485, 602, 63, 475, 63, 11864, 199, 504, 10380, 14, 2828, 14, 11676, 492, 12972, 3477, 23785, 2141, 199, 504, 10380, 14, 4416, 492, 5048, 63, 495, 63, 5730, 199, 504, 10380, 423, 5819, 492, 370, 63, 6106, 421, 199, 533, 1910, 3513, 547, 8, 1726, 304, 339, 408, 8405, 1919, 1202, 370, 4673, 9081, 641, 18593, 1041, 421, 199, 533, 30894, 7810, 8, 29188, 23785, 2141, 304, 339, 408, 18089, 282, 11153, 5494, 14, 221, 2047, 883, 5516, 642, 1021, 436, 5647, 272, 376, 13943, 4497, 1083, 14, 221, 710, 492, 8377, 365, 626, 314, 4497, 1083, 272, 365, 282, 805, 543, 282, 8545, 3217, 370, 314, 8337, 14, 221, 11105, 272, 3102, 787, 1678, 342, 436, 10017, 1252, 339, 5679, 4503, 26, 339, 1306, 671, 275, 30894, 7810, 6333, 1421, 582, 5685, 12, 298, 6185, 582, 334, 17, 12, 499, 12, 650, 16658, 298, 10957, 19446, 70, 531, 272, 1306, 671, 905, 1421, 937, 272, 5685, 272, 1306, 671, 905, 6185, 937, 272, 334, 17, 12, 499, 12, 650, 9, 272, 1306, 671, 905, 21244, 70, 482, 76, 937, 275, 6546, 272, 1306, 671, 14, 5626, 63, 2117, 272, 715, 339, 520, 635, 666, 26, 314, 2536, 666, 14, 221, 13083, 282, 1211, 12, 769, 402, 6346, 503, 658, 403, 2313, 272, 520, 635, 7565, 63, 498, 26, 314, 7565, 790, 14, 221, 982, 440, 663, 658, 403, 64, 503, 440, 2013, 2432, 652, 965, 370, 506, 663, 2544, 520, 5247, 1705, 3549, 64, 365, 2797, 14, 272, 520, 635, 892, 26, 710, 2536, 574, 402, 314, 658, 1222, 64, 3305, 14, 272, 408, 339, 6079, 710, 2631, 1083, 370 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 82, 624, 272, 10380, 14, 2828, 14, 7817, 5306, 272, 18294, 22935, 94, 339, 961, 859, 9031, 282, 5494, 626, 365, 440, 741, 13048, 687, 314, 1890, 272, 2952, 652, 9584, 282, 9040, 314, 1654, 5920, 367, 14, 221, 2047, 883, 675, 652, 465, 272, 2351, 8343, 340, 1006, 1265, 1172, 365, 282, 922, 1305, 503, 6020, 370, 2216, 272, 282, 10367, 315, 922, 14, 339, 14797, 315, 25169, 626, 314, 666, 365, 5139, 12701, 687, 314, 1890, 465, 282, 272, 3293, 5494, 365, 14, 221, 9738, 1265, 2793, 1133, 1172, 370, 3877, 436, 8976, 314, 272, 12184, 1265, 1172, 737, 314, 1654, 14, 339, 5679, 4503, 26, 339, 1306, 687, 10380, 14, 2828, 14, 7817, 5306, 492, 30894, 7810, 272, 1306, 671, 275, 30894, 7810, 6333, 1421, 582, 5685, 12, 298, 6185, 582, 334, 17, 12, 499, 12, 650, 16658, 298, 10957, 19446, 70, 531, 339, 19460, 316, 1901, 282, 1059, 880, 626, 1373, 883, 3877, 652, 315, 282, 5494, 26, 339, 1306, 574, 275, 671, 14, 3549, 342, 339, 3835, 5384, 687, 626, 1059, 4020, 26, 339, 1306, 671, 275, 30894, 7810, 14, 324, 3549, 8, 585, 12, 298, 10957, 19446, 70, 531, 272, 1306, 671, 905, 6185, 937, 272, 334, 17, 12, 499, 12, 650, 9, 339, 982, 17122, 26473, 314, 5494, 436, 314, 9040, 365, 6835, 314, 625, 3549, 272, 1083, 911, 2449, 18030, 436, 372, 282, 892, 2701, 658, 24117, 7810, 64, 909, 14, 339, 14797, 315, 25169, 626, 314, 1338, 911, 506, 8917, 315, 314, 5494, 880, 886, 440, 272, 3877, 666, 315, 282, 5494, 1265, 2793, 1133, 2934, 314, 922, 370, 1937, 14, 339, 13515, 27561, 272, 16248, 23476, 339, 982, 1265, 787, 1808, 314, 10380, 1056, 2251, 1265, 4293, 21494, 314, 272, 11153, 5494, 1901, 2195, 4223, 2839, 642, 447, 398, 687, 10380, 14, 1208, 492, 6328, 63, 1829, 267, 687, 10380, 14, 21148, 492, 3523, 2017, 267, 687, 10380, 14, 2828, 14, 7817, 5306, 492, 30894, 7810, 398, 327, 2793, 1133, 675, 642, 790, 1325, 282, 3365, 1373, 27, 1265, 4293, 2951, 675, 267, 327, 747, 14, 22776, 8, 1165, 9, 370, 664, 6020, 2196, 267, 5795, 11771, 63, 3078, 275, 1557, 10500, 60, 11110, 60, 1774, 24, 90, 60, 10183, 60, 1845, 16, 93, 20, 60, 88, 24, 66, 60, 10656, 7, 398, 1021, 4784, 8, 1563, 2017, 304, 953, 768, 5245, 63, 1829, 288, 347, 1890, 63, 1730, 8, 277, 304, 355, 666, 275, 291, 14, 7792, 14, 362, 360, 1730, 63, 576, 358, 355, 340, 440, 666, 26, 490, 372, 30894, 7810, 8, 4731, 63, 498, 29, 12961, 63, 3078, 9, 355, 372, 30894, 7810, 14, 324, 3549, 8, 576, 12, 5795, 11771, 63, 3078, 9, 398, 347, 4223, 8, 2314, 12, 1343, 63, 1310, 304, 288, 1056, 275, 4784, 8, 2314, 12, 1343, 63, 1310, 9, 953, 327, 664, 282, 1177, 909, 2348, 288, 1177, 275, 2263, 953, 340, 1056, 14, 1258, 63, 1730, 14, 5626, 63, 2117, 26, 355, 2351, 63, 576, 275, 1056, 14, 1258, 63, 1730, 14, 3549, 342, 355, 1177, 14, 409, 63, 5306, 360, 1730, 63, 576, 297, 2351, 63, 576, 12, 2511, 22768, 26960, 29, 549, 9, 288, 372, 1177, 8, 2314, 12, 1343, 63, 1310, 9, 339, 437, 6656, 3376, 13150, 883, 506, 22175, 1354, 701, 1808, 1033, 23999, 3102, 447, 398, 1021, 4784, 8, 1563, 2017, 304, 953, 768, 5245, 63, 1829, 288, 347, 1890, 63, 1730, 8, 277, 304, 355, 372, 30894, 7810, 14, 912, 63, 5306, 8, 277, 12, 7565, 63, 498, 29, 13665, 63, 12961, 9, 398, 347, 4223, 8, 2314, 12, 1343, 63, 1310, 304, 288, 1056, 275, 4784, 8, 2314, 12, 1343, 63, 1310, 9, 953, 327, 664, 282, 1177, 909, 2348, 288, 1177, 275, 2263, 953, 1056, 14, 1258, 63, 1730, 14, 2117, 63, 5306, 8, 1310, 9, 288, 372, 1177, 8, 2314, 12, 1343, 63, 1310, 9, 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, 5927, 199, 646, 1300, 772, 199, 504, 20330, 492, 892, 465, 20330, 199, 504, 900, 492, 900, 199, 504, 8337, 492, 7793, 17, 465, 485, 885, 63, 2227, 199, 199, 504, 10380, 423, 5819, 492, 10849, 12, 1318, 63, 466, 199, 504, 10380, 14, 3603, 492, 1166, 63, 3513, 63, 6666, 12, 1166, 63, 12240, 63, 6666, 199, 504, 10380, 423, 4672, 492, 485, 602, 63, 475, 63, 11864, 199, 504, 10380, 14, 2828, 14, 11676, 492, 12972, 3477, 23785, 2141, 199, 504, 10380, 14, 4416, 492, 5048, 63, 495, 63, 5730, 199, 504, 10380, 423, 5819, 492, 370, 63, 6106, 421, 199, 533, 1910, 3513, 547, 8, 1726, 304, 339, 408, 8405, 1919, 1202, 370, 4673, 9081, 641, 18593, 1041, 421, 199, 533, 30894, 7810, 8, 29188, 23785, 2141, 304, 339, 408, 18089, 282, 11153, 5494, 14, 221, 2047, 883, 5516, 642, 1021, 436, 5647, 272, 376, 13943, 4497, 1083, 14, 221, 710, 492, 8377, 365, 626, 314, 4497, 1083, 272, 365, 282, 805, 543, 282, 8545, 3217, 370, 314, 8337, 14, 221, 11105, 272, 3102, 787, 1678, 342, 436, 10017, 1252, 339, 5679, 4503, 26, 339, 1306, 671, 275, 30894, 7810, 6333, 1421, 582, 5685, 12, 298, 6185, 582, 334, 17, 12, 499, 12, 650, 16658, 298, 10957, 19446, 70, 531, 272, 1306, 671, 905, 1421, 937, 272, 5685, 272, 1306, 671, 905, 6185, 937, 272, 334, 17, 12, 499, 12, 650, 9, 272, 1306, 671, 905, 21244, 70, 482, 76, 937, 275, 6546, 272, 1306, 671, 14, 5626, 63, 2117, 272, 715, 339, 520, 635, 666, 26, 314, 2536, 666, 14, 221, 13083, 282, 1211, 12, 769, 402, 6346, 503, 658, 403, 2313, 272, 520, 635, 7565, 63, 498, 26, 314, 7565, 790, 14, 221, 982, 440, 663, 658, 403, 64, 503, 440, 2013, 2432, 652, 965, 370, 506, 663, 2544, 520, 5247, 1705, 3549, 64, 365, 2797, 14, 272, 520, 635, 892, 26, 710, 2536, 574, 402, 314, 658, 1222, 64, 3305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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
lupyuen/RaspberryPiImage
home/pi/GrovePi/Software/Python/others/temboo/core/exception.py
4
1932
############################################################################### # # temboo.core.exception.TembooError # temboo.core.exception.TembooHTTPError # temboo.core.exception.TembooCredentialError # temboo.core.exception.TembooObjectNotAccessibleError # # Classes for handling Temboo-related exceptions. # # Python versions 2.6, 2.7, 3.x # # Copyright 2014, Temboo 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. # ############################################################################### class TembooError(Exception): def __init__(self, msg): super(TembooError, self).__init__(msg) self.type = 'Temboo' class TembooObjectNotAccessibleError(TembooError): def __init__(self, msg, uri): super(TembooObjectNotAccessibleError, self).__init__(msg) self.uri = uri class TembooCredentialError(TembooError): pass class TembooHTTPError(TembooError): def __init__(self, msg, status, reason, response_body): super(TembooHTTPError, self).__init__(msg) self.args = (msg, status, reason, response_body) class TembooDisallowedInputError(TembooError): def __init__(self, msg, input_name): super(TembooDisallowedInputError, self).__init__(msg) self.type = 'DisallowedInput' self.input_name = input_name class TembooNotFoundError(TembooError): def __init__(self, msg): super(TembooNotFoundError, self).__init__(msg) self.type = 'NotFound'
apache-2.0
[ 11490, 199, 3, 199, 3, 29072, 15056, 14, 1018, 14, 1971, 14, 52, 5633, 15056, 547, 199, 3, 29072, 15056, 14, 1018, 14, 1971, 14, 52, 5633, 15056, 12815, 199, 3, 29072, 15056, 14, 1018, 14, 1971, 14, 52, 5633, 15056, 23330, 547, 199, 3, 29072, 15056, 14, 1018, 14, 1971, 14, 52, 5633, 15056, 1692, 1763, 1945, 13339, 547, 199, 3, 199, 3, 27939, 367, 7252, 377, 5633, 15056, 13, 2407, 4967, 14, 199, 3, 199, 3, 2018, 5459, 499, 14, 22, 12, 499, 14, 23, 12, 650, 14, 88, 199, 3, 199, 3, 1898, 6927, 12, 377, 5633, 15056, 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, 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, 199, 3, 2032, 1854, 1334, 314, 844, 365, 1854, 641, 376, 199, 3, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 199, 3, 1902, 4056, 503, 2478, 14, 1666, 314, 844, 367, 314, 2488, 199, 3, 2637, 4210, 3443, 436, 4204, 1334, 314, 844, 14, 199, 3, 199, 11490, 421, 199, 533, 377, 5633, 15056, 547, 8, 1726, 304, 339, 347, 636, 826, 721, 277, 12, 1499, 304, 267, 1613, 8, 52, 5633, 15056, 547, 12, 291, 2843, 826, 721, 1328, 9, 267, 291, 14, 466, 275, 283, 52, 5633, 15056, 7, 199, 199, 533, 377, 5633, 15056, 1692, 1763, 1945, 13339, 547, 8, 52, 5633, 15056, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 12, 5108, 304, 267, 1613, 8, 52, 5633, 15056, 1692, 1763, 1945, 13339, 547, 12, 291, 2843, 826, 721, 1328, 9, 267, 291, 14, 2302, 275, 5108, 199, 199, 533, 377, 5633, 15056, 23330, 547, 8, 52, 5633, 15056, 547, 304, 272, 986, 199, 199, 533, 377, 5633, 15056, 12815, 8, 52, 5633, 15056, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 12, 2004, 12, 4499, 12, 1177, 63, 2030, 304, 267, 1613, 8, 52, 5633, 15056, 12815, 12, 291, 2843, 826, 721, 1328, 9, 267, 291, 14, 589, 275, 334, 1328, 12, 2004, 12, 4499, 12, 1177, 63, 2030, 9, 199, 199, 533, 377, 5633, 15056, 2825, 6541, 3205, 547, 8, 52, 5633, 15056, 547, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1499, 12, 1324, 63, 354, 304, 507, 198, 4792, 8, 52, 5633, 15056, 2825, 6541, 3205, 547, 12, 291, 2843, 826, 721, 1328, 9, 507, 198, 277, 14, 466, 275, 283, 2825, 6541, 3205, 7, 507, 198, 277, 14, 1210, 63, 354, 275, 1324, 63, 354, 199, 199, 533, 377, 5633, 15056, 10870, 8, 52, 5633, 15056, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 304, 267, 1613, 8, 52, 5633, 15056, 10870, 12, 291, 2843, 826, 721, 1328, 9, 267, 291, 14, 466, 275, 283, 4667, 7, 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 ]
[ 199, 3, 199, 3, 29072, 15056, 14, 1018, 14, 1971, 14, 52, 5633, 15056, 547, 199, 3, 29072, 15056, 14, 1018, 14, 1971, 14, 52, 5633, 15056, 12815, 199, 3, 29072, 15056, 14, 1018, 14, 1971, 14, 52, 5633, 15056, 23330, 547, 199, 3, 29072, 15056, 14, 1018, 14, 1971, 14, 52, 5633, 15056, 1692, 1763, 1945, 13339, 547, 199, 3, 199, 3, 27939, 367, 7252, 377, 5633, 15056, 13, 2407, 4967, 14, 199, 3, 199, 3, 2018, 5459, 499, 14, 22, 12, 499, 14, 23, 12, 650, 14, 88, 199, 3, 199, 3, 1898, 6927, 12, 377, 5633, 15056, 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, 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, 199, 3, 2032, 1854, 1334, 314, 844, 365, 1854, 641, 376, 199, 3, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 199, 3, 1902, 4056, 503, 2478, 14, 1666, 314, 844, 367, 314, 2488, 199, 3, 2637, 4210, 3443, 436, 4204, 1334, 314, 844, 14, 199, 3, 199, 11490, 421, 199, 533, 377, 5633, 15056, 547, 8, 1726, 304, 339, 347, 636, 826, 721, 277, 12, 1499, 304, 267, 1613, 8, 52, 5633, 15056, 547, 12, 291, 2843, 826, 721, 1328, 9, 267, 291, 14, 466, 275, 283, 52, 5633, 15056, 7, 199, 199, 533, 377, 5633, 15056, 1692, 1763, 1945, 13339, 547, 8, 52, 5633, 15056, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 12, 5108, 304, 267, 1613, 8, 52, 5633, 15056, 1692, 1763, 1945, 13339, 547, 12, 291, 2843, 826, 721, 1328, 9, 267, 291, 14, 2302, 275, 5108, 199, 199, 533, 377, 5633, 15056, 23330, 547, 8, 52, 5633, 15056, 547, 304, 272, 986, 199, 199, 533, 377, 5633, 15056, 12815, 8, 52, 5633, 15056, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 12, 2004, 12, 4499, 12, 1177, 63, 2030, 304, 267, 1613, 8, 52, 5633, 15056, 12815, 12, 291, 2843, 826, 721, 1328, 9, 267, 291, 14, 589, 275, 334, 1328, 12, 2004, 12, 4499, 12, 1177, 63, 2030, 9, 199, 199, 533, 377, 5633, 15056, 2825, 6541, 3205, 547, 8, 52, 5633, 15056, 547, 304, 199, 198, 318, 636, 826, 721, 277, 12, 1499, 12, 1324, 63, 354, 304, 507, 198, 4792, 8, 52, 5633, 15056, 2825, 6541, 3205, 547, 12, 291, 2843, 826, 721, 1328, 9, 507, 198, 277, 14, 466, 275, 283, 2825, 6541, 3205, 7, 507, 198, 277, 14, 1210, 63, 354, 275, 1324, 63, 354, 199, 199, 533, 377, 5633, 15056, 10870, 8, 52, 5633, 15056, 547, 304, 272, 347, 636, 826, 721, 277, 12, 1499, 304, 267, 1613, 8, 52, 5633, 15056, 10870, 12, 291, 2843, 826, 721, 1328, 9, 267, 291, 14, 466, 275, 283, 4667, 7, 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,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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 ]
CSC301H-Fall2013/JuakStore
site-packages/django/contrib/auth/hashers.py
34
16332
from __future__ import unicode_literals import base64 import functools import hashlib from django.dispatch import receiver from django.conf import settings from django.test.signals import setting_changed from django.utils import importlib from django.utils.datastructures import SortedDict from django.utils.encoding import force_bytes, force_str from django.core.exceptions import ImproperlyConfigured from django.utils.crypto import ( pbkdf2, constant_time_compare, get_random_string) from django.utils.translation import ugettext_noop as _ UNUSABLE_PASSWORD = '!' # This will never be a valid encoded hash MAXIMUM_PASSWORD_LENGTH = 4096 # The maximum length a password can be to prevent DoS HASHERS = None # lazily loaded from PASSWORD_HASHERS PREFERRED_HASHER = None # defaults to first item in PASSWORD_HASHERS @receiver(setting_changed) def reset_hashers(**kwargs): if kwargs['setting'] == 'PASSWORD_HASHERS': global HASHERS, PREFERRED_HASHER HASHERS = None PREFERRED_HASHER = None def password_max_length(max_length): def inner(fn): @functools.wraps(fn) def wrapper(self, password, *args, **kwargs): if len(password) > max_length: raise ValueError("Invalid password; Must be less than or equal" " to %d bytes" % max_length) return fn(self, password, *args, **kwargs) return wrapper return inner def is_password_usable(encoded): if encoded is None or encoded == UNUSABLE_PASSWORD: return False try: hasher = identify_hasher(encoded) except ValueError: return False return True def check_password(password, encoded, setter=None, preferred='default'): """ Returns a boolean of whether the raw password matches the three part encoded digest. If setter is specified, it'll be called when you need to regenerate the password. """ if not password or not is_password_usable(encoded): return False preferred = get_hasher(preferred) hasher = identify_hasher(encoded) must_update = hasher.algorithm != preferred.algorithm is_correct = hasher.verify(password, encoded) if setter and is_correct and must_update: setter(password) return is_correct def make_password(password, salt=None, hasher='default'): """ Turn a plain-text password into a hash for database storage Same as encode() but generates a new random salt. If password is None or blank then UNUSABLE_PASSWORD will be returned which disallows logins. """ if not password: return UNUSABLE_PASSWORD hasher = get_hasher(hasher) if not salt: salt = hasher.salt() return hasher.encode(password, salt) def load_hashers(password_hashers=None): global HASHERS global PREFERRED_HASHER hashers = [] if not password_hashers: password_hashers = settings.PASSWORD_HASHERS for backend in password_hashers: try: mod_path, cls_name = backend.rsplit('.', 1) mod = importlib.import_module(mod_path) hasher_cls = getattr(mod, cls_name) except (AttributeError, ImportError, ValueError): raise ImproperlyConfigured("hasher not found: %s" % backend) hasher = hasher_cls() if not getattr(hasher, 'algorithm'): raise ImproperlyConfigured("hasher doesn't specify an " "algorithm name: %s" % backend) hashers.append(hasher) HASHERS = dict([(hasher.algorithm, hasher) for hasher in hashers]) PREFERRED_HASHER = hashers[0] def get_hasher(algorithm='default'): """ Returns an instance of a loaded password hasher. If algorithm is 'default', the default hasher will be returned. This function will also lazy import hashers specified in your settings file if needed. """ if hasattr(algorithm, 'algorithm'): return algorithm elif algorithm == 'default': if PREFERRED_HASHER is None: load_hashers() return PREFERRED_HASHER else: if HASHERS is None: load_hashers() if algorithm not in HASHERS: raise ValueError("Unknown password hashing algorithm '%s'. " "Did you specify it in the PASSWORD_HASHERS " "setting?" % algorithm) return HASHERS[algorithm] def identify_hasher(encoded): """ Returns an instance of a loaded password hasher. Identifies hasher algorithm by examining encoded hash, and calls get_hasher() to return hasher. Raises ValueError if algorithm cannot be identified, or if hasher is not loaded. """ # Ancient versions of Django created plain MD5 passwords and accepted # MD5 passwords with an empty salt. if ((len(encoded) == 32 and '$' not in encoded) or (len(encoded) == 37 and encoded.startswith('md5$$'))): algorithm = 'unsalted_md5' # Ancient versions of Django accepted SHA1 passwords with an empty salt. elif len(encoded) == 46 and encoded.startswith('sha1$$'): algorithm = 'unsalted_sha1' else: algorithm = encoded.split('$', 1)[0] return get_hasher(algorithm) def mask_hash(hash, show=6, char="*"): """ Returns the given hash, with only the first ``show`` number shown. The rest are masked with ``char`` for security reasons. """ masked = hash[:show] masked += char * len(hash[show:]) return masked class BasePasswordHasher(object): """ Abstract base class for password hashers When creating your own hasher, you need to override algorithm, verify(), encode() and safe_summary(). PasswordHasher objects are immutable. """ algorithm = None library = None def _load_library(self): if self.library is not None: if isinstance(self.library, (tuple, list)): name, mod_path = self.library else: name = mod_path = self.library try: module = importlib.import_module(mod_path) except ImportError: raise ValueError("Couldn't load %s password algorithm " "library" % name) return module raise ValueError("Hasher '%s' doesn't specify a library attribute" % self.__class__) def salt(self): """ Generates a cryptographically secure nonce salt in ascii """ return get_random_string() def verify(self, password, encoded): """ Checks if the given password is correct """ raise NotImplementedError() def encode(self, password, salt): """ Creates an encoded database value The result is normally formatted as "algorithm$salt$hash" and must be fewer than 128 characters. """ raise NotImplementedError() def safe_summary(self, encoded): """ Returns a summary of safe values The result is a dictionary and will be used where the password field must be displayed to construct a safe representation of the password. """ raise NotImplementedError() class PBKDF2PasswordHasher(BasePasswordHasher): """ Secure password hashing using the PBKDF2 algorithm (recommended) Configured to use PBKDF2 + HMAC + SHA256 with 10000 iterations. The result is a 64 byte binary string. Iterations may be changed safely but you must rename the algorithm if you change SHA256. """ algorithm = "pbkdf2_sha256" iterations = 10000 digest = hashlib.sha256 @password_max_length(MAXIMUM_PASSWORD_LENGTH) def encode(self, password, salt, iterations=None): assert password assert salt and '$' not in salt if not iterations: iterations = self.iterations hash = pbkdf2(password, salt, iterations, digest=self.digest) hash = base64.b64encode(hash).decode('ascii').strip() return "%s$%d$%s$%s" % (self.algorithm, iterations, salt, hash) @password_max_length(MAXIMUM_PASSWORD_LENGTH) def verify(self, password, encoded): algorithm, iterations, salt, hash = encoded.split('$', 3) assert algorithm == self.algorithm encoded_2 = self.encode(password, salt, int(iterations)) return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): algorithm, iterations, salt, hash = encoded.split('$', 3) assert algorithm == self.algorithm return SortedDict([ (_('algorithm'), algorithm), (_('iterations'), iterations), (_('salt'), mask_hash(salt)), (_('hash'), mask_hash(hash)), ]) class PBKDF2SHA1PasswordHasher(PBKDF2PasswordHasher): """ Alternate PBKDF2 hasher which uses SHA1, the default PRF recommended by PKCS #5. This is compatible with other implementations of PBKDF2, such as openssl's PKCS5_PBKDF2_HMAC_SHA1(). """ algorithm = "pbkdf2_sha1" digest = hashlib.sha1 class BCryptPasswordHasher(BasePasswordHasher): """ Secure password hashing using the bcrypt algorithm (recommended) This is considered by many to be the most secure algorithm but you must first install the py-bcrypt library. Please be warned that this library depends on native C code and might cause portability issues. """ algorithm = "bcrypt" library = ("py-bcrypt", "bcrypt") rounds = 12 def salt(self): bcrypt = self._load_library() return bcrypt.gensalt(self.rounds) @password_max_length(MAXIMUM_PASSWORD_LENGTH) def encode(self, password, salt): bcrypt = self._load_library() # Need to reevaluate the force_bytes call once bcrypt is supported on # Python 3 data = bcrypt.hashpw(force_bytes(password), salt) return "%s$%s" % (self.algorithm, data) @password_max_length(MAXIMUM_PASSWORD_LENGTH) def verify(self, password, encoded): algorithm, data = encoded.split('$', 1) assert algorithm == self.algorithm bcrypt = self._load_library() return constant_time_compare(data, bcrypt.hashpw(force_bytes(password), data)) def safe_summary(self, encoded): algorithm, empty, algostr, work_factor, data = encoded.split('$', 4) assert algorithm == self.algorithm salt, checksum = data[:22], data[22:] return SortedDict([ (_('algorithm'), algorithm), (_('work factor'), work_factor), (_('salt'), mask_hash(salt)), (_('checksum'), mask_hash(checksum)), ]) class SHA1PasswordHasher(BasePasswordHasher): """ The SHA1 password hashing algorithm (not recommended) """ algorithm = "sha1" @password_max_length(MAXIMUM_PASSWORD_LENGTH) def encode(self, password, salt): assert password assert salt and '$' not in salt hash = hashlib.sha1(force_bytes(salt + password)).hexdigest() return "%s$%s$%s" % (self.algorithm, salt, hash) @password_max_length(MAXIMUM_PASSWORD_LENGTH) def verify(self, password, encoded): algorithm, salt, hash = encoded.split('$', 2) assert algorithm == self.algorithm encoded_2 = self.encode(password, salt) return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): algorithm, salt, hash = encoded.split('$', 2) assert algorithm == self.algorithm return SortedDict([ (_('algorithm'), algorithm), (_('salt'), mask_hash(salt, show=2)), (_('hash'), mask_hash(hash)), ]) class MD5PasswordHasher(BasePasswordHasher): """ The Salted MD5 password hashing algorithm (not recommended) """ algorithm = "md5" @password_max_length(MAXIMUM_PASSWORD_LENGTH) def encode(self, password, salt): assert password assert salt and '$' not in salt hash = hashlib.md5(force_bytes(salt + password)).hexdigest() return "%s$%s$%s" % (self.algorithm, salt, hash) @password_max_length(MAXIMUM_PASSWORD_LENGTH) def verify(self, password, encoded): algorithm, salt, hash = encoded.split('$', 2) assert algorithm == self.algorithm encoded_2 = self.encode(password, salt) return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): algorithm, salt, hash = encoded.split('$', 2) assert algorithm == self.algorithm return SortedDict([ (_('algorithm'), algorithm), (_('salt'), mask_hash(salt, show=2)), (_('hash'), mask_hash(hash)), ]) class UnsaltedSHA1PasswordHasher(BasePasswordHasher): """ Very insecure algorithm that you should *never* use; stores SHA1 hashes with an empty salt. This class is implemented because Django used to accept such password hashes. Some older Django installs still have these values lingering around so we need to handle and upgrade them properly. """ algorithm = "unsalted_sha1" def salt(self): return '' @password_max_length(MAXIMUM_PASSWORD_LENGTH) def encode(self, password, salt): assert salt == '' hash = hashlib.sha1(force_bytes(password)).hexdigest() return 'sha1$$%s' % hash @password_max_length(MAXIMUM_PASSWORD_LENGTH) def verify(self, password, encoded): encoded_2 = self.encode(password, '') return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): assert encoded.startswith('sha1$$') hash = encoded[6:] return SortedDict([ (_('algorithm'), self.algorithm), (_('hash'), mask_hash(hash)), ]) class UnsaltedMD5PasswordHasher(BasePasswordHasher): """ Incredibly insecure algorithm that you should *never* use; stores unsalted MD5 hashes without the algorithm prefix, also accepts MD5 hashes with an empty salt. This class is implemented because Django used to store passwords this way and to accept such password hashes. Some older Django installs still have these values lingering around so we need to handle and upgrade them properly. """ algorithm = "unsalted_md5" def salt(self): return '' @password_max_length(MAXIMUM_PASSWORD_LENGTH) def encode(self, password, salt): assert salt == '' return hashlib.md5(force_bytes(password)).hexdigest() @password_max_length(MAXIMUM_PASSWORD_LENGTH) def verify(self, password, encoded): if len(encoded) == 37 and encoded.startswith('md5$$'): encoded = encoded[5:] encoded_2 = self.encode(password, '') return constant_time_compare(encoded, encoded_2) def safe_summary(self, encoded): return SortedDict([ (_('algorithm'), self.algorithm), (_('hash'), mask_hash(encoded, show=3)), ]) class CryptPasswordHasher(BasePasswordHasher): """ Password hashing using UNIX crypt (not recommended) The crypt module is not supported on all platforms. """ algorithm = "crypt" library = "crypt" def salt(self): return get_random_string(2) @password_max_length(MAXIMUM_PASSWORD_LENGTH) def encode(self, password, salt): crypt = self._load_library() assert len(salt) == 2 data = crypt.crypt(force_str(password), salt) # we don't need to store the salt, but Django used to do this return "%s$%s$%s" % (self.algorithm, '', data) @password_max_length(MAXIMUM_PASSWORD_LENGTH) def verify(self, password, encoded): crypt = self._load_library() algorithm, salt, data = encoded.split('$', 2) assert algorithm == self.algorithm return constant_time_compare(data, crypt.crypt(force_str(password), data)) def safe_summary(self, encoded): algorithm, salt, data = encoded.split('$', 2) assert algorithm == self.algorithm return SortedDict([ (_('algorithm'), algorithm), (_('salt'), salt), (_('hash'), mask_hash(data, show=3)), ])
mit
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 1300, 772, 199, 646, 9143, 199, 646, 8337, 199, 199, 504, 1639, 14, 6052, 492, 13035, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 396, 14, 10458, 492, 4260, 63, 2489, 199, 504, 1639, 14, 1208, 492, 14802, 199, 504, 1639, 14, 1208, 14, 23004, 492, 27432, 2141, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 2394, 12, 3542, 63, 495, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1208, 14, 10316, 492, 334, 272, 10446, 28996, 18, 12, 4413, 63, 521, 63, 5785, 12, 664, 63, 2355, 63, 875, 9, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 12921, 465, 485, 421, 199, 53, 1440, 51, 2617, 63, 9032, 275, 29376, 221, 327, 961, 911, 7078, 506, 282, 1686, 5737, 2631, 199, 4283, 27078, 63, 9032, 63, 9127, 275, 17125, 221, 327, 710, 5696, 2582, 282, 2505, 883, 506, 370, 7981, 4226, 51, 199, 13533, 31700, 275, 488, 221, 327, 29667, 3444, 6511, 687, 21705, 5172, 63, 13533, 31700, 199, 4225, 15849, 7387, 63, 13533, 3452, 275, 488, 221, 327, 4243, 370, 1642, 1242, 315, 21705, 5172, 63, 13533, 31700, 199, 199, 32, 10244, 8, 6031, 63, 2489, 9, 199, 318, 5305, 63, 31342, 3682, 958, 304, 272, 340, 2074, 459, 6031, 418, 508, 283, 9032, 63, 13533, 31700, 356, 267, 2288, 7509, 31700, 12, 510, 19494, 7387, 63, 13533, 3452, 267, 7509, 31700, 275, 488, 267, 510, 19494, 7387, 63, 13533, 3452, 275, 488, 421, 199, 318, 2505, 63, 988, 63, 1267, 8, 988, 63, 1267, 304, 272, 347, 6506, 8, 2324, 304, 267, 768, 17869, 14, 13582, 8, 2324, 9, 267, 347, 4975, 8, 277, 12, 2505, 12, 627, 589, 12, 1011, 958, 304, 288, 340, 822, 8, 2060, 9, 690, 1390, 63, 1267, 26, 355, 746, 1722, 480, 3364, 2505, 27, 9498, 506, 6656, 2419, 503, 4472, 2, 639, 298, 370, 450, 68, 2783, 2, 450, 1390, 63, 1267, 9, 288, 372, 4325, 8, 277, 12, 2505, 12, 627, 589, 12, 1011, 958, 9, 267, 372, 4975, 272, 372, 6506, 421, 199, 318, 365, 63, 2060, 63, 14418, 8, 8167, 304, 272, 340, 5737, 365, 488, 503, 5737, 508, 738, 1440, 51, 2617, 63, 9032, 26, 267, 372, 756, 272, 862, 26, 267, 19009, 275, 10405, 63, 28885, 8, 8167, 9, 272, 871, 1722, 26, 267, 372, 756, 272, 372, 715, 421, 199, 318, 1104, 63, 2060, 8, 2060, 12, 5737, 12, 18743, 29, 403, 12, 14388, 534, 885, 735, 272, 408, 272, 1803, 282, 5046, 402, 3775, 314, 3066, 2505, 4450, 314, 7795, 272, 1777, 5737, 10017, 14, 339, 982, 18743, 365, 2013, 12, 652, 7171, 506, 2797, 1380, 1265, 1929, 370, 272, 30943, 314, 2505, 14, 272, 408, 272, 340, 440, 2505, 503, 440, 365, 63, 2060, 63, 14418, 8, 8167, 304, 267, 372, 756, 339, 14388, 275, 664, 63, 28885, 8, 17477, 9, 272, 19009, 275, 10405, 63, 28885, 8, 8167, 9, 339, 1471, 63, 873, 275, 19009, 14, 8833, 1137, 14388, 14, 8833, 272, 365, 63, 4525, 275, 19009, 14, 4712, 8, 2060, 12, 5737, 9, 272, 340, 18743, 436, 365, 63, 4525, 436, 1471, 63, 873, 26, 267, 18743, 8, 2060, 9, 272, 372, 365, 63, 4525, 421, 199, 318, 1852, 63, 2060, 8, 2060, 12, 10105, 29, 403, 12, 19009, 534, 885, 735, 272, 408, 272, 16147, 282, 8971, 13, 505, 2505, 1901, 282, 2631, 367, 3050, 4887, 339, 14766, 465, 3752, 342, 1325, 12821, 282, 892, 2196, 10105, 14, 221, 982, 272, 2505, 365, 488, 503, 4596, 2066, 738, 1440, 51, 2617, 63, 9032, 911, 506, 272, 2138, 1314, 2153, 24077, 4676, 83, 14, 272, 408, 272, 340, 440, 2505, 26, 267, 372, 738, 1440, 51, 2617, 63, 9032, 339, 19009, 275, 664, 63, 28885, 8, 28885, 9, 339, 340, 440, 10105, 26, 267, 10105, 275, 19009, 14, 12597, 342, 339, 372, 19009, 14, 2143, 8, 2060, 12, 10105, 9, 421, 199, 318, 2248, 63, 31342, 8, 2060, 63, 31342, 29, 403, 304, 272, 2288, 7509, 31700, 272, 2288, 510, 19494, 7387, 63, 13533, 3452, 272, 2631, 1192, 275, 942, 272, 340, 440, 2505, 63, 31342, 26, 267, 2505, 63, 31342, 275, 2202, 14, 9032, 63, 13533, 31700, 272, 367, 4865, 315, 2505, 63, 31342, 26, 267, 862, 26, 288, 3413, 63, 515, 12, 843, 63, 354, 275, 4865, 14, 13490, 14078, 413, 9, 288, 3413, 275, 14802, 14, 646, 63, 578, 8, 1494, 63, 515, 9, 288, 19009, 63, 1886, 275, 2519, 8, 1494, 12, 843, 63, 354, 9, 267, 871, 334, 10227, 12, 3545, 12, 1722, 304, 288, 746, 11897, 480, 28885, 440, 1911, 26, 450, 83, 2, 450, 4865, 9, 267, 19009, 275, 19009, 63, 1886, 342, 267, 340, 440, 2519, 8, 28885, 12, 283, 8833, 735, 288, 746, 11897, 480, 28885, 3181, 1133, 4165, 376, 298, 4318, 298, 8833, 536, 26, 450, 83, 2, 450, 4865, 9, 267, 2631, 1192, 14, 740, 8, 28885, 9, 272, 7509, 31700, 275, 1211, 7694, 28885, 14, 8833, 12, 19009, 9, 367, 19009, 315, 2631, 1192, 566, 272, 510, 19494, 7387, 63, 13533, 3452, 275, 2631, 1192, 59, 16, 61, 421, 199, 318, 664, 63, 28885, 8, 8833, 534, 885, 735, 272, 408, 272, 1803, 376, 1256, 402, 282, 6511, 2505, 19009, 14, 339, 982, 5563, 365, 283, 885, 297, 314, 849, 19009, 911, 506, 2138, 14, 272, 961, 805, 911, 2597, 9617, 492, 2631, 1192, 2013, 315, 2195, 272, 2202, 570, 340, 4346, 14, 272, 408, 272, 340, 2688, 8, 8833, 12, 283, 8833, 735, 267, 372, 5563, 339, 916, 5563, 508, 283, 885, 356, 267, 340, 510, 19494, 7387, 63, 13533, 3452, 365, 488, 26, 288, 2248, 63, 31342, 342, 267, 372, 510, 19494, 7387, 63, 13533, 3452, 272, 587, 26, 267, 340, 7509, 31700, 365, 488, 26, 288, 2248, 63, 31342, 342, 267, 340, 5563, 440, 315, 7509, 31700, 26, 288, 746, 1722, 480, 5912, 2505, 25223, 5563, 1543, 83, 1370, 298, 2490, 298, 17366, 1265, 4165, 652, 315, 314, 21705, 5172, 63, 13533, 31700, 298, 2490, 298, 6031, 13472, 450, 5563, 9, 267, 372, 7509, 31700 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 1300, 772, 199, 646, 9143, 199, 646, 8337, 199, 199, 504, 1639, 14, 6052, 492, 13035, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 396, 14, 10458, 492, 4260, 63, 2489, 199, 504, 1639, 14, 1208, 492, 14802, 199, 504, 1639, 14, 1208, 14, 23004, 492, 27432, 2141, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 2394, 12, 3542, 63, 495, 199, 504, 1639, 14, 1018, 14, 3924, 492, 11897, 199, 504, 1639, 14, 1208, 14, 10316, 492, 334, 272, 10446, 28996, 18, 12, 4413, 63, 521, 63, 5785, 12, 664, 63, 2355, 63, 875, 9, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 12921, 465, 485, 421, 199, 53, 1440, 51, 2617, 63, 9032, 275, 29376, 221, 327, 961, 911, 7078, 506, 282, 1686, 5737, 2631, 199, 4283, 27078, 63, 9032, 63, 9127, 275, 17125, 221, 327, 710, 5696, 2582, 282, 2505, 883, 506, 370, 7981, 4226, 51, 199, 13533, 31700, 275, 488, 221, 327, 29667, 3444, 6511, 687, 21705, 5172, 63, 13533, 31700, 199, 4225, 15849, 7387, 63, 13533, 3452, 275, 488, 221, 327, 4243, 370, 1642, 1242, 315, 21705, 5172, 63, 13533, 31700, 199, 199, 32, 10244, 8, 6031, 63, 2489, 9, 199, 318, 5305, 63, 31342, 3682, 958, 304, 272, 340, 2074, 459, 6031, 418, 508, 283, 9032, 63, 13533, 31700, 356, 267, 2288, 7509, 31700, 12, 510, 19494, 7387, 63, 13533, 3452, 267, 7509, 31700, 275, 488, 267, 510, 19494, 7387, 63, 13533, 3452, 275, 488, 421, 199, 318, 2505, 63, 988, 63, 1267, 8, 988, 63, 1267, 304, 272, 347, 6506, 8, 2324, 304, 267, 768, 17869, 14, 13582, 8, 2324, 9, 267, 347, 4975, 8, 277, 12, 2505, 12, 627, 589, 12, 1011, 958, 304, 288, 340, 822, 8, 2060, 9, 690, 1390, 63, 1267, 26, 355, 746, 1722, 480, 3364, 2505, 27, 9498, 506, 6656, 2419, 503, 4472, 2, 639, 298, 370, 450, 68, 2783, 2, 450, 1390, 63, 1267, 9, 288, 372, 4325, 8, 277, 12, 2505, 12, 627, 589, 12, 1011, 958, 9, 267, 372, 4975, 272, 372, 6506, 421, 199, 318, 365, 63, 2060, 63, 14418, 8, 8167, 304, 272, 340, 5737, 365, 488, 503, 5737, 508, 738, 1440, 51, 2617, 63, 9032, 26, 267, 372, 756, 272, 862, 26, 267, 19009, 275, 10405, 63, 28885, 8, 8167, 9, 272, 871, 1722, 26, 267, 372, 756, 272, 372, 715, 421, 199, 318, 1104, 63, 2060, 8, 2060, 12, 5737, 12, 18743, 29, 403, 12, 14388, 534, 885, 735, 272, 408, 272, 1803, 282, 5046, 402, 3775, 314, 3066, 2505, 4450, 314, 7795, 272, 1777, 5737, 10017, 14, 339, 982, 18743, 365, 2013, 12, 652, 7171, 506, 2797, 1380, 1265, 1929, 370, 272, 30943, 314, 2505, 14, 272, 408, 272, 340, 440, 2505, 503, 440, 365, 63, 2060, 63, 14418, 8, 8167, 304, 267, 372, 756, 339, 14388, 275, 664, 63, 28885, 8, 17477, 9, 272, 19009, 275, 10405, 63, 28885, 8, 8167, 9, 339, 1471, 63, 873, 275, 19009, 14, 8833, 1137, 14388, 14, 8833, 272, 365, 63, 4525, 275, 19009, 14, 4712, 8, 2060, 12, 5737, 9, 272, 340, 18743, 436, 365, 63, 4525, 436, 1471, 63, 873, 26, 267, 18743, 8, 2060, 9, 272, 372, 365, 63, 4525, 421, 199, 318, 1852, 63, 2060, 8, 2060, 12, 10105, 29, 403, 12, 19009, 534, 885, 735, 272, 408, 272, 16147, 282, 8971, 13, 505, 2505, 1901, 282, 2631, 367, 3050, 4887, 339, 14766, 465, 3752, 342, 1325, 12821, 282, 892, 2196, 10105, 14, 221, 982, 272, 2505, 365, 488, 503, 4596, 2066, 738, 1440, 51, 2617, 63, 9032, 911, 506, 272, 2138, 1314, 2153, 24077, 4676, 83, 14, 272, 408, 272, 340, 440, 2505, 26, 267, 372, 738, 1440, 51, 2617, 63, 9032, 339, 19009, 275, 664, 63, 28885, 8, 28885, 9, 339, 340, 440, 10105, 26, 267, 10105, 275, 19009, 14, 12597, 342, 339, 372, 19009, 14, 2143, 8, 2060, 12, 10105, 9, 421, 199, 318, 2248, 63, 31342, 8, 2060, 63, 31342, 29, 403, 304, 272, 2288, 7509, 31700, 272, 2288, 510, 19494, 7387, 63, 13533, 3452, 272, 2631, 1192, 275, 942, 272, 340, 440, 2505, 63, 31342, 26, 267, 2505, 63, 31342, 275, 2202, 14, 9032, 63, 13533, 31700, 272, 367, 4865, 315, 2505, 63, 31342, 26, 267, 862, 26, 288, 3413, 63, 515, 12, 843, 63, 354, 275, 4865, 14, 13490, 14078, 413, 9, 288, 3413, 275, 14802, 14, 646, 63, 578, 8, 1494, 63, 515, 9, 288, 19009, 63, 1886, 275, 2519, 8, 1494, 12, 843, 63, 354, 9, 267, 871, 334, 10227, 12, 3545, 12, 1722, 304, 288, 746, 11897, 480, 28885, 440, 1911, 26, 450, 83, 2, 450, 4865, 9, 267, 19009, 275, 19009, 63, 1886, 342, 267, 340, 440, 2519, 8, 28885, 12, 283, 8833, 735, 288, 746, 11897, 480, 28885, 3181, 1133, 4165, 376, 298, 4318, 298, 8833, 536, 26, 450, 83, 2, 450, 4865, 9, 267, 2631, 1192, 14, 740, 8, 28885, 9, 272, 7509, 31700, 275, 1211, 7694, 28885, 14, 8833, 12, 19009, 9, 367, 19009, 315, 2631, 1192, 566, 272, 510, 19494, 7387, 63, 13533, 3452, 275, 2631, 1192, 59, 16, 61, 421, 199, 318, 664, 63, 28885, 8, 8833, 534, 885, 735, 272, 408, 272, 1803, 376, 1256, 402, 282, 6511, 2505, 19009, 14, 339, 982, 5563, 365, 283, 885, 297, 314, 849, 19009, 911, 506, 2138, 14, 272, 961, 805, 911, 2597, 9617, 492, 2631, 1192, 2013, 315, 2195, 272, 2202, 570, 340, 4346, 14, 272, 408, 272, 340, 2688, 8, 8833, 12, 283, 8833, 735, 267, 372, 5563, 339, 916, 5563, 508, 283, 885, 356, 267, 340, 510, 19494, 7387, 63, 13533, 3452, 365, 488, 26, 288, 2248, 63, 31342, 342, 267, 372, 510, 19494, 7387, 63, 13533, 3452, 272, 587, 26, 267, 340, 7509, 31700, 365, 488, 26, 288, 2248, 63, 31342, 342, 267, 340, 5563, 440, 315, 7509, 31700, 26, 288, 746, 1722, 480, 5912, 2505, 25223, 5563, 1543, 83, 1370, 298, 2490, 298, 17366, 1265, 4165, 652, 315, 314, 21705, 5172, 63, 13533, 31700, 298, 2490, 298, 6031, 13472, 450, 5563, 9, 267, 372, 7509, 31700, 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, 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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 ]
vedujoshi/tempest
tempest/scenario/test_object_storage_basic_ops.py
1
2961
# Copyright 2013 IBM Corp. # 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 tempest.lib import decorators from tempest.scenario import manager from tempest import test class TestObjectStorageBasicOps(manager.ObjectStorageScenarioTest): @decorators.idempotent_id('b920faf1-7b8a-4657-b9fe-9c4512bfb381') @test.services('object_storage') def test_swift_basic_ops(self): """Test swift basic ops. * get swift stat. * create container. * upload a file to the created container. * list container's objects and assure that the uploaded file is present. * download the object and check the content * delete object from container. * list container's objects and assure that the deleted file is gone. * delete a container. """ self.get_swift_stat() container_name = self.create_container() obj_name, obj_data = self.upload_object_to_container(container_name) self.list_and_check_container_objects(container_name, present_obj=[obj_name]) self.download_and_verify(container_name, obj_name, obj_data) self.delete_object(container_name, obj_name) self.list_and_check_container_objects(container_name, not_present_obj=[obj_name]) self.delete_container(container_name) @decorators.idempotent_id('916c7111-cb1f-44b2-816d-8f760e4ea910') @decorators.attr(type='slow') @test.services('object_storage') def test_swift_acl_anonymous_download(self): """This test will cover below steps: 1. Create container 2. Upload object to the new container 3. Change the ACL of the container 4. Check if the object can be download by anonymous user 5. Delete the object and container """ container_name = self.create_container() obj_name, _ = self.upload_object_to_container(container_name) obj_url = '%s/%s/%s' % (self.object_client.base_url, container_name, obj_name) resp, _ = self.object_client.raw_request(obj_url, 'GET') self.assertEqual(resp.status, 401) self.change_container_acl(container_name, '.r:*') resp, _ = self.object_client.raw_request(obj_url, 'GET') self.assertEqual(resp.status, 200)
apache-2.0
[ 3, 1898, 6171, 26202, 22304, 14, 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, 24076, 14, 773, 492, 20419, 199, 504, 24076, 14, 13444, 492, 5256, 199, 504, 24076, 492, 511, 421, 199, 533, 1379, 1692, 6408, 6845, 16452, 8, 2609, 14, 1692, 6408, 12327, 6936, 774, 304, 272, 768, 11582, 14, 21307, 63, 344, 360, 66, 31762, 667, 70, 17, 13, 23, 66, 24, 65, 13, 2466, 1641, 13, 66, 25, 771, 13, 25, 67, 2322, 713, 4361, 66, 16706, 358, 272, 768, 396, 14, 5950, 360, 785, 63, 3494, 358, 272, 347, 511, 63, 13215, 63, 4316, 63, 1483, 8, 277, 304, 267, 408, 774, 16275, 5678, 4156, 14, 13359, 627, 664, 16275, 5672, 14, 268, 627, 1218, 3970, 14, 268, 627, 5802, 282, 570, 370, 314, 2737, 3970, 14, 268, 627, 769, 3970, 1159, 2251, 436, 2661, 608, 626, 314, 14238, 570, 365, 268, 3451, 14, 268, 627, 5235, 314, 909, 436, 1104, 314, 1564, 268, 627, 3145, 909, 687, 3970, 14, 268, 627, 769, 3970, 1159, 2251, 436, 2661, 608, 626, 314, 5463, 570, 365, 21737, 14, 268, 627, 3145, 282, 3970, 14, 267, 408, 267, 291, 14, 362, 63, 13215, 63, 3736, 342, 267, 3970, 63, 354, 275, 291, 14, 981, 63, 3600, 342, 267, 1559, 63, 354, 12, 1559, 63, 576, 275, 291, 14, 5064, 63, 785, 63, 475, 63, 3600, 8, 3600, 63, 354, 9, 267, 291, 14, 513, 63, 460, 63, 1074, 63, 3600, 63, 1462, 8, 3600, 63, 354, 12, 6343, 3451, 63, 1113, 1524, 1113, 63, 354, 566, 267, 291, 14, 4249, 63, 460, 63, 4712, 8, 3600, 63, 354, 12, 1559, 63, 354, 12, 1559, 63, 576, 9, 267, 291, 14, 1807, 63, 785, 8, 3600, 63, 354, 12, 1559, 63, 354, 9, 267, 291, 14, 513, 63, 460, 63, 1074, 63, 3600, 63, 1462, 8, 3600, 63, 354, 12, 6343, 440, 63, 1881, 63, 1113, 1524, 1113, 63, 354, 566, 267, 291, 14, 1807, 63, 3600, 8, 3600, 63, 354, 9, 339, 768, 11582, 14, 21307, 63, 344, 360, 25, 975, 67, 23, 6673, 13, 2894, 17, 70, 13, 1602, 66, 18, 13, 31104, 68, 13, 24, 70, 19036, 69, 20, 4489, 25, 709, 358, 272, 768, 11582, 14, 962, 8, 466, 534, 14362, 358, 272, 768, 396, 14, 5950, 360, 785, 63, 3494, 358, 272, 347, 511, 63, 13215, 63, 5853, 63, 12628, 63, 4249, 8, 277, 304, 267, 408, 2765, 511, 911, 8486, 5084, 7124, 26, 398, 413, 14, 2790, 3970, 267, 499, 14, 19149, 909, 370, 314, 892, 3970, 267, 650, 14, 7743, 314, 16543, 402, 314, 3970, 267, 841, 14, 2670, 340, 314, 909, 883, 506, 5235, 701, 16535, 922, 267, 959, 14, 8496, 314, 909, 436, 3970, 267, 408, 267, 3970, 63, 354, 275, 291, 14, 981, 63, 3600, 342, 267, 1559, 63, 354, 12, 485, 275, 291, 14, 5064, 63, 785, 63, 475, 63, 3600, 8, 3600, 63, 354, 9, 267, 1559, 63, 633, 275, 1543, 83, 3149, 83, 3149, 83, 7, 450, 334, 277, 14, 785, 63, 1258, 14, 1095, 63, 633, 12, 1816, 3970, 63, 354, 12, 1559, 63, 354, 9, 267, 3085, 12, 485, 275, 291, 14, 785, 63, 1258, 14, 1773, 63, 1069, 8, 1113, 63, 633, 12, 283, 2970, 358, 267, 291, 14, 629, 8, 4518, 14, 1205, 12, 13952, 9, 398, 291, 14, 1461, 63, 3600, 63, 5853, 8, 3600, 63, 354, 12, 1987, 82, 26, 13418, 267, 3085, 12, 485, 275, 291, 14, 785, 63, 1258, 14, 1773, 63, 1069, 8, 1113, 63, 633, 12, 283, 2970, 358, 267, 291, 14, 629, 8, 4518, 14, 1205, 12, 1926, 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 ]
[ 1898, 6171, 26202, 22304, 14, 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, 24076, 14, 773, 492, 20419, 199, 504, 24076, 14, 13444, 492, 5256, 199, 504, 24076, 492, 511, 421, 199, 533, 1379, 1692, 6408, 6845, 16452, 8, 2609, 14, 1692, 6408, 12327, 6936, 774, 304, 272, 768, 11582, 14, 21307, 63, 344, 360, 66, 31762, 667, 70, 17, 13, 23, 66, 24, 65, 13, 2466, 1641, 13, 66, 25, 771, 13, 25, 67, 2322, 713, 4361, 66, 16706, 358, 272, 768, 396, 14, 5950, 360, 785, 63, 3494, 358, 272, 347, 511, 63, 13215, 63, 4316, 63, 1483, 8, 277, 304, 267, 408, 774, 16275, 5678, 4156, 14, 13359, 627, 664, 16275, 5672, 14, 268, 627, 1218, 3970, 14, 268, 627, 5802, 282, 570, 370, 314, 2737, 3970, 14, 268, 627, 769, 3970, 1159, 2251, 436, 2661, 608, 626, 314, 14238, 570, 365, 268, 3451, 14, 268, 627, 5235, 314, 909, 436, 1104, 314, 1564, 268, 627, 3145, 909, 687, 3970, 14, 268, 627, 769, 3970, 1159, 2251, 436, 2661, 608, 626, 314, 5463, 570, 365, 21737, 14, 268, 627, 3145, 282, 3970, 14, 267, 408, 267, 291, 14, 362, 63, 13215, 63, 3736, 342, 267, 3970, 63, 354, 275, 291, 14, 981, 63, 3600, 342, 267, 1559, 63, 354, 12, 1559, 63, 576, 275, 291, 14, 5064, 63, 785, 63, 475, 63, 3600, 8, 3600, 63, 354, 9, 267, 291, 14, 513, 63, 460, 63, 1074, 63, 3600, 63, 1462, 8, 3600, 63, 354, 12, 6343, 3451, 63, 1113, 1524, 1113, 63, 354, 566, 267, 291, 14, 4249, 63, 460, 63, 4712, 8, 3600, 63, 354, 12, 1559, 63, 354, 12, 1559, 63, 576, 9, 267, 291, 14, 1807, 63, 785, 8, 3600, 63, 354, 12, 1559, 63, 354, 9, 267, 291, 14, 513, 63, 460, 63, 1074, 63, 3600, 63, 1462, 8, 3600, 63, 354, 12, 6343, 440, 63, 1881, 63, 1113, 1524, 1113, 63, 354, 566, 267, 291, 14, 1807, 63, 3600, 8, 3600, 63, 354, 9, 339, 768, 11582, 14, 21307, 63, 344, 360, 25, 975, 67, 23, 6673, 13, 2894, 17, 70, 13, 1602, 66, 18, 13, 31104, 68, 13, 24, 70, 19036, 69, 20, 4489, 25, 709, 358, 272, 768, 11582, 14, 962, 8, 466, 534, 14362, 358, 272, 768, 396, 14, 5950, 360, 785, 63, 3494, 358, 272, 347, 511, 63, 13215, 63, 5853, 63, 12628, 63, 4249, 8, 277, 304, 267, 408, 2765, 511, 911, 8486, 5084, 7124, 26, 398, 413, 14, 2790, 3970, 267, 499, 14, 19149, 909, 370, 314, 892, 3970, 267, 650, 14, 7743, 314, 16543, 402, 314, 3970, 267, 841, 14, 2670, 340, 314, 909, 883, 506, 5235, 701, 16535, 922, 267, 959, 14, 8496, 314, 909, 436, 3970, 267, 408, 267, 3970, 63, 354, 275, 291, 14, 981, 63, 3600, 342, 267, 1559, 63, 354, 12, 485, 275, 291, 14, 5064, 63, 785, 63, 475, 63, 3600, 8, 3600, 63, 354, 9, 267, 1559, 63, 633, 275, 1543, 83, 3149, 83, 3149, 83, 7, 450, 334, 277, 14, 785, 63, 1258, 14, 1095, 63, 633, 12, 1816, 3970, 63, 354, 12, 1559, 63, 354, 9, 267, 3085, 12, 485, 275, 291, 14, 785, 63, 1258, 14, 1773, 63, 1069, 8, 1113, 63, 633, 12, 283, 2970, 358, 267, 291, 14, 629, 8, 4518, 14, 1205, 12, 13952, 9, 398, 291, 14, 1461, 63, 3600, 63, 5853, 8, 3600, 63, 354, 12, 1987, 82, 26, 13418, 267, 3085, 12, 485, 275, 291, 14, 785, 63, 1258, 14, 1773, 63, 1069, 8, 1113, 63, 633, 12, 283, 2970, 358, 267, 291, 14, 629, 8, 4518, 14, 1205, 12, 1926, 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, 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,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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 ]
AthinaB/synnefo
snf-pithos-app/pithos/api/test/unicode.py
7
18824
#!/usr/bin/env python #coding=utf8 # Copyright (C) 2010-2014 GRNET S.A. # # This program 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. # # 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from pithos.api.test import PithosAPITest, TEST_BLOCK_SIZE from pithos.api.test.util import get_random_data from synnefo.lib import join_urls from urllib import quote import random class TestUnicode(PithosAPITest): #def setUp(self): # super(TestUnicode, self).setUp() # self.user = 'χρήστης' def test_create_container(self): cname = 'φάκελος' self.create_container(cname) url = join_urls(self.pithos_path, self.user, cname) r = self.head(url) self.assertEqual(r.status_code, 204) url = join_urls(self.pithos_path, self.user) r = self.get(url) self.assertEqual(r.status_code, 200) containers = r.content.split('\n') self.assertTrue('φάκελος' in containers) def test_create_object(self): cname = 'φάκελος' oname = 'αντικείμενο' self.create_container(cname) odata = self.upload_object(cname, oname)[1] url = join_urls(self.pithos_path, self.user, cname, oname) r = self.head(url) self.assertEqual(r.status_code, 200) r = self.get(url) self.assertEqual(r.status_code, 200) self.assertEqual(r.content, odata) url = join_urls(self.pithos_path, self.user, cname) r = self.get(url) objects = r.content.split('\n') self.assertEqual(r.status_code, 200) self.assertTrue('αντικείμενο' in objects) def test_copy_object(self): src_container = 'φάκελος' src_object = 'αντικείμενο' dest_container = 'αντίγραφα' dest_object = 'ασφαλές-αντίγραφο' self.create_container(src_container) self.upload_object(src_container, src_object) self.create_container(dest_container) url = join_urls(self.pithos_path, self.user, dest_container, dest_object) self.put(url, data='', HTTP_X_COPY_FROM='/%s/%s' % (src_container, src_object)) # assert destination object exists r = self.head(url) self.assertEqual(r.status_code, 200) r = self.get(url) self.assertEqual(r.status_code, 200) # assert source object exists url = join_urls(self.pithos_path, self.user, src_container, src_object) r = self.head(url) self.assertEqual(r.status_code, 200) r = self.get(url) self.assertEqual(r.status_code, 200) # list source container objects url = join_urls(self.pithos_path, self.user, src_container) r = self.get(url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') self.assertTrue(src_object in objects) self.assertTrue(dest_object not in objects) # list destination container objects url = join_urls(self.pithos_path, self.user, dest_container) r = self.get(url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') self.assertTrue(src_object not in objects) self.assertTrue(dest_object in objects) def test_move_object(self): src_container = 'φάκελος' src_object = 'αντικείμενο' dest_container = 'αντίγραα' dest_object = 'ασφαλές-αντίγραφο' self.create_container(src_container) self.upload_object(src_container, src_object) self.create_container(dest_container) url = join_urls(self.pithos_path, self.user, dest_container, dest_object) self.put(url, data='', HTTP_X_MOVE_FROM='/%s/%s' % (src_container, src_object)) # assert destination object exists r = self.head(url) self.assertEqual(r.status_code, 200) r = self.get(url) self.assertEqual(r.status_code, 200) # assert source object does not exist url = join_urls(self.pithos_path, self.user, src_container, src_object) r = self.head(url) self.assertEqual(r.status_code, 404) r = self.get(url) self.assertEqual(r.status_code, 404) # list source container objects url = join_urls(self.pithos_path, self.user, src_container) r = self.get(url) self.assertEqual(r.status_code, 204) objects = r.content.split('\n') self.assertTrue(src_object not in objects) self.assertTrue(dest_object not in objects) # list destination container objects url = join_urls(self.pithos_path, self.user, dest_container) r = self.get(url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') self.assertTrue(src_object not in objects) self.assertTrue(dest_object in objects) def test_delete_object(self): self.create_container('φάκελος') self.upload_object('φάκελος', 'αντικείμενο') url = join_urls(self.pithos_path, self.user, 'φάκελος') r = self.get(url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') self.assertTrue('αντικείμενο' in objects) url = join_urls(self.pithos_path, self.user, 'φάκελος', 'αντικείμενο') r = self.head(url) self.assertEqual(r.status_code, 200) r = self.get(url) self.assertEqual(r.status_code, 200) r = self.delete(url) r = self.head(url) self.assertEqual(r.status_code, 404) r = self.get(url) self.assertEqual(r.status_code, 404) url = join_urls(self.pithos_path, self.user, 'φάκελος') r = self.get(url) objects = r.content.split('\n') self.assertTrue('αντικείμενο' not in objects) def test_delete_container(self): self.create_container('φάκελος') url = join_urls(self.pithos_path, self.user) r = self.get(url) containers = r.content.split('\n') self.assertTrue('φάκελος' in containers) self.upload_object('φάκελος', 'αντικείμενο') url = join_urls(self.pithos_path, self.user, 'φάκελος') r = self.get(url) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') self.assertTrue('αντικείμενο' in objects) url = join_urls(self.pithos_path, self.user, 'φάκελος', 'αντικείμενο') r = self.head(url) self.assertEqual(r.status_code, 200) r = self.get(url) self.assertEqual(r.status_code, 200) url = join_urls(self.pithos_path, self.user, 'φάκελος') r = self.delete(url) self.assertEqual(r.status_code, 409) url = join_urls(self.pithos_path, self.user, 'φάκελος', 'αντικείμενο') r = self.delete(url) r = self.head(url) self.assertEqual(r.status_code, 404) r = self.get(url) self.assertEqual(r.status_code, 404) url = join_urls(self.pithos_path, self.user, 'φάκελος') r = self.get(url) objects = r.content.split('\n') self.assertTrue('αντικείμενο' not in objects) url = join_urls(self.pithos_path, self.user, 'φάκελος') r = self.delete(url) self.assertEqual(r.status_code, 204) url = join_urls(self.pithos_path, self.user) r = self.get(url) containers = r.content.split('\n') self.assertTrue('φάκελος' not in containers) def test_account_meta(self): url = join_urls(self.pithos_path, self.user) headers = {'HTTP_X_ACCOUNT_META_Ποιότητα': 'Ααα'} r = self.post(url, content_type='', **headers) self.assertEqual(r.status_code, 202) meta = self.get_account_meta() self.assertTrue('Ποιότητα' in meta) self.assertEqual(meta['Ποιότητα'], 'Ααα') def test_container_meta(self): url = join_urls(self.pithos_path, self.user, 'φάκελος') headers = {'HTTP_X_CONTAINER_META_Ποιότητα': 'Ααα'} r = self.put(url, data='', **headers) self.assertEqual(r.status_code, 201) meta = self.get_container_meta('φάκελος') self.assertTrue('Ποιότητα' in meta) self.assertEqual(meta['Ποιότητα'], 'Ααα') def test_object_meta(self): self.create_container('φάκελος') url = join_urls(self.pithos_path, self.user, 'φάκελος', 'αντικείμενο') headers = {'HTTP_X_OBJECT_META_Ποιότητα': 'Ααα'} r = self.put(url, data=get_random_data(), **headers) self.assertEqual(r.status_code, 201) meta = self.get_object_meta('φάκελος', 'αντικείμενο') self.assertTrue('Ποιότητα' in meta) self.assertEqual(meta['Ποιότητα'], 'Ααα') def test_list_meta_filtering(self): self.create_container('φάκελος') meta = {'ποιότητα': 'Ααα'} self.upload_object('φάκελος', 'ο1', **meta) self.upload_object('φάκελος', 'ο2') self.upload_object('φάκελος', 'ο3') meta = {'ποσότητα': 'μεγάλη'} self.update_object_meta('φάκελος', 'ο2', meta) url = join_urls(self.pithos_path, self.user, 'φάκελος') r = self.get('%s?meta=%s' % (url, quote('ποιότητα, ποσότητα'))) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEquals(objects, ['ο1', 'ο2']) r = self.get('%s?meta=%s' % (url, quote('!ποιότητα'))) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEquals(objects, ['ο2', 'ο3']) r = self.get('%s?meta=%s' % (url, quote('!ποιότητα, !ποσότητα'))) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEquals(objects, ['ο3']) meta = {'ποιότητα': 'ΑΒ'} self.update_object_meta('φάκελος', 'ο2', meta) r = self.get('%s?meta=%s' % (url, quote('ποιότητα=Ααα'))) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEquals(objects, ['ο1']) r = self.get('%s?meta=%s' % (url, quote('ποιότητα!=Ααα'))) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEquals(objects, ['ο2']) meta = {'έτος': '2011'} self.update_object_meta('φάκελος', 'ο3', meta) meta = {'έτος': '2012'} self.update_object_meta('φάκελος', 'ο2', meta) r = self.get('%s?meta=%s' % (url, quote('έτος<2012'))) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEquals(objects, ['ο3']) r = self.get('%s?meta=%s' % (url, quote('έτος<=2012'))) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEquals(objects, ['ο2', 'ο3']) r = self.get('%s?meta=%s' % (url, quote('έτος<=2012, έτος!=2011'))) self.assertEqual(r.status_code, 200) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEquals(objects, ['ο2']) r = self.get('%s?meta=%s' % (url, quote('έτος<2012, έτος!=2011'))) self.assertEqual(r.status_code, 204) objects = r.content.split('\n') if '' in objects: objects.remove('') self.assertEquals(objects, []) def test_groups(self): # create a group headers = {'HTTP_X_ACCOUNT_GROUP_γκρουπ': 'chazapis,διογένης'} url = join_urls(self.pithos_path, self.user) r = self.post(url, **headers) self.assertEqual(r.status_code, 202) groups = self.get_account_groups() self.assertTrue('γκρουπ' in groups) self.assertEqual(groups['γκρουπ'], 'chazapis,διογένης') headers = {'HTTP_X_ACCOUNT_GROUP_γκρουπ': 'διογένης'} url = join_urls(self.pithos_path, self.user) r = self.post('%s?update=' % url, **headers) self.assertEqual(r.status_code, 202) groups = self.get_account_groups() self.assertTrue('γκρουπ' in groups) self.assertEqual(groups['γκρουπ'], 'διογένης') # check read access self.create_container('φάκελος') odata = self.upload_object('φάκελος', 'ο1')[1] r = self.head(url, user='διογένης') self.assertEqual(r.status_code, 403) r = self.get(url, user='διογένης') self.assertEqual(r.status_code, 403) # share for read url = join_urls(self.pithos_path, self.user, 'φάκελος', 'ο1') r = self.post(url, content_type='', HTTP_X_OBJECT_SHARING='read=%s:γκρουπ' % self.user) self.assertEqual(r.status_code, 202) r = self.head(url, user='διογένης') self.assertEqual(r.status_code, 200) r = self.get(url, user='διογένης') self.assertEqual(r.status_code, 200) # check write access appended_data = get_random_data() r = self.post(url, user='διογένης', data=appended_data, content_type='application/octet-stream', HTTP_CONTENT_LENGTH=str(len(appended_data)), HTTP_CONTENT_RANGE='bytes */*') self.assertEqual(r.status_code, 403) # share for write url = join_urls(self.pithos_path, self.user, 'φάκελος', 'ο1') r = self.post(url, content_type='', HTTP_X_OBJECT_SHARING='write=%s:γκρουπ' % self.user) self.assertEqual(r.status_code, 202) r = self.post(url, user='διογένης', data=appended_data, content_type='application/octet-stream', HTTP_CONTENT_LENGTH=str(len(appended_data)), HTTP_CONTENT_RANGE='bytes */*') self.assertEqual(r.status_code, 204) r = self.get(url, user='διογένης') self.assertEqual(r.status_code, 200) self.assertEqual(r.content, odata + appended_data) gname = ('a' * 256).capitalize() headers = {'HTTP_X_ACCOUNT_GROUP_%s' % gname: 'β'} url = join_urls(self.pithos_path, self.user) r = self.post(url, **headers) self.assertEqual(r.status_code, 202) groups = self.get_account_groups() self.assertTrue(gname in groups) self.assertEqual(groups[gname], 'β') gname = ('a' * 257).capitalize() headers = {'HTTP_X_ACCOUNT_GROUP_%s' % gname: 'β'} url = join_urls(self.pithos_path, self.user) r = self.post(url, **headers) self.assertEqual(r.status_code, 400) def test_group_delete(self): # create a group headers = {'HTTP_X_ACCOUNT_GROUP_γκρουπ': 'chazapis,διογένης'} url = join_urls(self.pithos_path, self.user) r = self.post(url, **headers) self.assertEqual(r.status_code, 202) groups = self.get_account_groups() self.assertTrue('γκρουπ' in groups) self.assertEqual(groups['γκρουπ'], 'chazapis,διογένης') headers = {'HTTP_X_ACCOUNT_GROUP_γκρουπ': ''} r = self.post('%s?update=' % url, **headers) self.assertEqual(r.status_code, 202) groups = self.get_account_groups() self.assertTrue('γκρουπ' not in groups) def test_manifestation(self): self.create_container('κουβάς') prefix = 'μέρη/' data = '' for i in range(5): part = '%s%d' % (prefix, i) data += self.upload_object('κουβάς', part)[1] self.create_container('φάκελος') url = join_urls(self.pithos_path, self.user, 'φάκελος', 'άπαντα') r = self.put(url, data='', HTTP_X_OBJECT_MANIFEST='κουβάς/%s' % prefix) self.assertEqual(r.status_code, 201) r = self.head(url) self.assertEqual(r.status_code, 200) r = self.get(url) self.assertEqual(r.status_code, 200) self.assertEqual(r.content, data) # wrong manifestation url = join_urls(self.pithos_path, self.user, 'φάκελος', 'άπαντα') r = self.put(url, data='', HTTP_X_OBJECT_MANIFEST='κουβάς/λάθος') self.assertEqual(r.status_code, 201) r = self.get(url) self.assertEqual(r.status_code, 200) self.assertTrue(r.content != data) def test_update_from_another_object(self): self.create_container('κουβάς') initial_data = self.upload_object('κουβάς', 'νέο')[1] length = TEST_BLOCK_SIZE + random.randint(1, TEST_BLOCK_SIZE - 1) src_data = self.upload_object('κουβάς', 'πηγή', length=length)[1] url = join_urls(self.pithos_path, self.user, 'κουβάς', 'νέο') r = self.post(url, content_type='', HTTP_CONTENT_RANGE='bytes */*', HTTP_X_SOURCE_OBJECT='/κουβάς/πηγή') self.assertEqual(r.status_code, 204) r = self.get(url) self.assertEqual(r.status_code, 200) self.assertEqual(r.content, initial_data + src_data)
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1523, 29, 1624, 24, 199, 199, 3, 1898, 334, 35, 9, 7129, 13, 7280, 21772, 7278, 428, 14, 33, 14, 199, 3, 199, 3, 961, 2240, 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, 961, 2240, 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, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 504, 299, 448, 736, 14, 1246, 14, 396, 492, 510, 448, 736, 2642, 597, 12, 7393, 63, 8475, 63, 4305, 199, 504, 299, 448, 736, 14, 1246, 14, 396, 14, 1974, 492, 664, 63, 2355, 63, 576, 199, 199, 504, 9560, 685, 545, 14, 773, 492, 4263, 63, 3603, 199, 199, 504, 4011, 492, 6313, 199, 199, 646, 2196, 421, 199, 533, 1379, 7087, 8, 48, 448, 736, 2642, 597, 304, 272, 327, 318, 3613, 8, 277, 304, 272, 327, 259, 1613, 8, 774, 7087, 12, 291, 680, 5996, 342, 272, 327, 259, 291, 14, 751, 275, 283, 140, 230, 18346, 139, 107, 20136, 17123, 21694, 25128, 7, 339, 347, 511, 63, 981, 63, 3600, 8, 277, 304, 267, 22559, 275, 283, 140, 229, 139, 106, 26839, 15339, 28085, 15407, 25128, 7, 267, 291, 14, 981, 63, 3600, 8, 11690, 9, 267, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 22559, 9, 267, 519, 275, 291, 14, 2993, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 14785, 9, 398, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 15333, 275, 519, 14, 1317, 14, 1294, 2258, 78, 358, 267, 291, 14, 1815, 360, 140, 229, 139, 106, 26839, 15339, 28085, 15407, 25128, 7, 315, 15333, 9, 339, 347, 511, 63, 981, 63, 785, 8, 277, 304, 267, 22559, 275, 283, 140, 229, 139, 106, 26839, 15339, 28085, 15407, 25128, 7, 267, 641, 313, 275, 283, 13500, 17444, 17123, 16426, 26839, 15339, 31940, 24461, 15339, 17444, 15407, 7, 267, 291, 14, 981, 63, 3600, 8, 11690, 9, 267, 312, 576, 275, 291, 14, 5064, 63, 785, 8, 11690, 12, 641, 313, 2788, 17, 61, 398, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 22559, 12, 641, 313, 9, 267, 519, 275, 291, 14, 2993, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 398, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 291, 14, 629, 8, 82, 14, 1317, 12, 312, 576, 9, 398, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 22559, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 2251, 275, 519, 14, 1317, 14, 1294, 2258, 78, 358, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 291, 14, 1815, 360, 13500, 17444, 17123, 16426, 26839, 15339, 31940, 24461, 15339, 17444, 15407, 7, 315, 2251, 9, 339, 347, 511, 63, 1574, 63, 785, 8, 277, 304, 267, 2928, 63, 3600, 275, 283, 140, 229, 139, 106, 26839, 15339, 28085, 15407, 25128, 7, 267, 2928, 63, 785, 275, 283, 13500, 17444, 17123, 16426, 26839, 15339, 31940, 24461, 15339, 17444, 15407, 7, 267, 2053, 63, 3600, 275, 283, 13500, 17444, 17123, 31940, 28916, 18346, 13500, 140, 229, 13500, 7, 267, 2053, 63, 785, 275, 283, 13500, 20136, 140, 229, 13500, 28085, 139, 256, 25128, 13, 13500, 17444, 17123, 31940, 28916, 18346, 13500, 140, 229, 15407, 7, 398, 291, 14, 981, 63, 3600, 8, 2164, 63, 3600, 9, 267, 291, 14, 5064, 63, 785, 8, 2164, 63, 3600, 12, 2928, 63, 785, 9, 398, 291, 14, 981, 63, 3600, 8, 2614, 63, 3600, 9, 267, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 2053, 63, 3600, 12, 717, 2053, 63, 785, 9, 267, 291, 14, 524, 8, 633, 12, 666, 4581, 326, 3101, 63, 56, 63, 16188, 63, 12491, 534, 3149, 83, 3149, 83, 7, 450, 334, 2164, 63, 3600, 12, 2928, 63, 785, 430, 398, 327, 702, 5724, 909, 3495, 267, 519, 275, 291, 14, 2993, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 398, 327, 702, 1350, 909, 3495, 267, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 2928, 63, 3600, 12, 717, 2928, 63, 785, 9, 267, 519, 275, 291, 14, 2993, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 398, 327, 769, 1350, 3970, 2251, 267, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 2928, 63, 3600, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 2251 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1523, 29, 1624, 24, 199, 199, 3, 1898, 334, 35, 9, 7129, 13, 7280, 21772, 7278, 428, 14, 33, 14, 199, 3, 199, 3, 961, 2240, 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, 961, 2240, 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, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 504, 299, 448, 736, 14, 1246, 14, 396, 492, 510, 448, 736, 2642, 597, 12, 7393, 63, 8475, 63, 4305, 199, 504, 299, 448, 736, 14, 1246, 14, 396, 14, 1974, 492, 664, 63, 2355, 63, 576, 199, 199, 504, 9560, 685, 545, 14, 773, 492, 4263, 63, 3603, 199, 199, 504, 4011, 492, 6313, 199, 199, 646, 2196, 421, 199, 533, 1379, 7087, 8, 48, 448, 736, 2642, 597, 304, 272, 327, 318, 3613, 8, 277, 304, 272, 327, 259, 1613, 8, 774, 7087, 12, 291, 680, 5996, 342, 272, 327, 259, 291, 14, 751, 275, 283, 140, 230, 18346, 139, 107, 20136, 17123, 21694, 25128, 7, 339, 347, 511, 63, 981, 63, 3600, 8, 277, 304, 267, 22559, 275, 283, 140, 229, 139, 106, 26839, 15339, 28085, 15407, 25128, 7, 267, 291, 14, 981, 63, 3600, 8, 11690, 9, 267, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 22559, 9, 267, 519, 275, 291, 14, 2993, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 14785, 9, 398, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 15333, 275, 519, 14, 1317, 14, 1294, 2258, 78, 358, 267, 291, 14, 1815, 360, 140, 229, 139, 106, 26839, 15339, 28085, 15407, 25128, 7, 315, 15333, 9, 339, 347, 511, 63, 981, 63, 785, 8, 277, 304, 267, 22559, 275, 283, 140, 229, 139, 106, 26839, 15339, 28085, 15407, 25128, 7, 267, 641, 313, 275, 283, 13500, 17444, 17123, 16426, 26839, 15339, 31940, 24461, 15339, 17444, 15407, 7, 267, 291, 14, 981, 63, 3600, 8, 11690, 9, 267, 312, 576, 275, 291, 14, 5064, 63, 785, 8, 11690, 12, 641, 313, 2788, 17, 61, 398, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 22559, 12, 641, 313, 9, 267, 519, 275, 291, 14, 2993, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 398, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 291, 14, 629, 8, 82, 14, 1317, 12, 312, 576, 9, 398, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 22559, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 2251, 275, 519, 14, 1317, 14, 1294, 2258, 78, 358, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 291, 14, 1815, 360, 13500, 17444, 17123, 16426, 26839, 15339, 31940, 24461, 15339, 17444, 15407, 7, 315, 2251, 9, 339, 347, 511, 63, 1574, 63, 785, 8, 277, 304, 267, 2928, 63, 3600, 275, 283, 140, 229, 139, 106, 26839, 15339, 28085, 15407, 25128, 7, 267, 2928, 63, 785, 275, 283, 13500, 17444, 17123, 16426, 26839, 15339, 31940, 24461, 15339, 17444, 15407, 7, 267, 2053, 63, 3600, 275, 283, 13500, 17444, 17123, 31940, 28916, 18346, 13500, 140, 229, 13500, 7, 267, 2053, 63, 785, 275, 283, 13500, 20136, 140, 229, 13500, 28085, 139, 256, 25128, 13, 13500, 17444, 17123, 31940, 28916, 18346, 13500, 140, 229, 15407, 7, 398, 291, 14, 981, 63, 3600, 8, 2164, 63, 3600, 9, 267, 291, 14, 5064, 63, 785, 8, 2164, 63, 3600, 12, 2928, 63, 785, 9, 398, 291, 14, 981, 63, 3600, 8, 2614, 63, 3600, 9, 267, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 2053, 63, 3600, 12, 717, 2053, 63, 785, 9, 267, 291, 14, 524, 8, 633, 12, 666, 4581, 326, 3101, 63, 56, 63, 16188, 63, 12491, 534, 3149, 83, 3149, 83, 7, 450, 334, 2164, 63, 3600, 12, 2928, 63, 785, 430, 398, 327, 702, 5724, 909, 3495, 267, 519, 275, 291, 14, 2993, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 398, 327, 702, 1350, 909, 3495, 267, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 2928, 63, 3600, 12, 717, 2928, 63, 785, 9, 267, 519, 275, 291, 14, 2993, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 398, 327, 769, 1350, 3970, 2251, 267, 1166, 275, 4263, 63, 3603, 8, 277, 14, 80, 448, 736, 63, 515, 12, 291, 14, 751, 12, 2928, 63, 3600, 9, 267, 519, 275, 291, 14, 362, 8, 633, 9, 267, 291, 14, 629, 8, 82, 14, 1205, 63, 600, 12, 1926, 9, 267, 2251, 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, 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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 ]
garnaat/troposphere
troposphere/sqs.py
27
1054
# Copyright (c) 2012-2013, Mark Peek <mark@peek.org> # All rights reserved. # # See LICENSE file for full license. from . import AWSObject, AWSProperty from .validators import integer try: from awacs.aws import Policy policytypes = (dict, Policy) except ImportError: policytypes = dict, class RedrivePolicy(AWSProperty): props = { 'deadLetterTargetArn': (basestring, False), 'maxReceiveCount': (integer, False), } class Queue(AWSObject): resource_type = "AWS::SQS::Queue" props = { 'DelaySeconds': (integer, False), 'MaximumMessageSize': (integer, False), 'MessageRetentionPeriod': (integer, False), 'QueueName': (basestring, False), 'ReceiveMessageWaitTimeSeconds': (integer, False), 'RedrivePolicy': (RedrivePolicy, False), 'VisibilityTimeout': (integer, False), } class QueuePolicy(AWSObject): resource_type = "AWS::SQS::QueuePolicy" props = { 'PolicyDocument': (policytypes, False), 'Queues': (list, True), }
bsd-2-clause
[ 3, 1898, 334, 67, 9, 6029, 13, 6965, 12, 7173, 510, 4374, 665, 1657, 32, 13164, 14, 1308, 30, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 1666, 5113, 570, 367, 2615, 4190, 14, 199, 199, 504, 1275, 492, 10168, 1692, 12, 10168, 3697, 199, 504, 1275, 11346, 492, 3000, 199, 893, 26, 272, 687, 26936, 645, 83, 14, 7231, 492, 18141, 272, 4592, 1313, 275, 334, 807, 12, 18141, 9, 199, 2590, 3545, 26, 272, 4592, 1313, 275, 1211, 12, 421, 199, 533, 9572, 6053, 4845, 8, 13226, 3697, 304, 272, 10792, 275, 469, 267, 283, 10957, 23496, 4277, 20498, 356, 334, 17628, 12, 756, 395, 267, 283, 988, 14235, 2353, 356, 334, 4115, 12, 756, 395, 272, 789, 421, 199, 533, 10703, 8, 13226, 1692, 304, 272, 2073, 63, 466, 275, 298, 13226, 447, 18445, 51, 447, 3737, 2, 339, 10792, 275, 469, 267, 283, 10796, 13165, 356, 334, 4115, 12, 756, 395, 267, 283, 10915, 2209, 2320, 356, 334, 4115, 12, 756, 395, 267, 283, 2209, 497, 9553, 15518, 356, 334, 4115, 12, 756, 395, 267, 283, 3737, 985, 356, 334, 17628, 12, 756, 395, 267, 283, 14235, 2209, 7536, 1366, 13165, 356, 334, 4115, 12, 756, 395, 267, 283, 10858, 6053, 4845, 356, 334, 10858, 6053, 4845, 12, 756, 395, 267, 283, 24735, 6372, 356, 334, 4115, 12, 756, 395, 272, 789, 421, 199, 533, 10703, 4845, 8, 13226, 1692, 304, 272, 2073, 63, 466, 275, 298, 13226, 447, 18445, 51, 447, 3737, 4845, 2, 339, 10792, 275, 469, 267, 283, 4845, 5564, 356, 334, 3185, 1313, 12, 756, 395, 267, 283, 3737, 83, 356, 334, 513, 12, 715, 395, 272, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 6029, 13, 6965, 12, 7173, 510, 4374, 665, 1657, 32, 13164, 14, 1308, 30, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 1666, 5113, 570, 367, 2615, 4190, 14, 199, 199, 504, 1275, 492, 10168, 1692, 12, 10168, 3697, 199, 504, 1275, 11346, 492, 3000, 199, 893, 26, 272, 687, 26936, 645, 83, 14, 7231, 492, 18141, 272, 4592, 1313, 275, 334, 807, 12, 18141, 9, 199, 2590, 3545, 26, 272, 4592, 1313, 275, 1211, 12, 421, 199, 533, 9572, 6053, 4845, 8, 13226, 3697, 304, 272, 10792, 275, 469, 267, 283, 10957, 23496, 4277, 20498, 356, 334, 17628, 12, 756, 395, 267, 283, 988, 14235, 2353, 356, 334, 4115, 12, 756, 395, 272, 789, 421, 199, 533, 10703, 8, 13226, 1692, 304, 272, 2073, 63, 466, 275, 298, 13226, 447, 18445, 51, 447, 3737, 2, 339, 10792, 275, 469, 267, 283, 10796, 13165, 356, 334, 4115, 12, 756, 395, 267, 283, 10915, 2209, 2320, 356, 334, 4115, 12, 756, 395, 267, 283, 2209, 497, 9553, 15518, 356, 334, 4115, 12, 756, 395, 267, 283, 3737, 985, 356, 334, 17628, 12, 756, 395, 267, 283, 14235, 2209, 7536, 1366, 13165, 356, 334, 4115, 12, 756, 395, 267, 283, 10858, 6053, 4845, 356, 334, 10858, 6053, 4845, 12, 756, 395, 267, 283, 24735, 6372, 356, 334, 4115, 12, 756, 395, 272, 789, 421, 199, 533, 10703, 4845, 8, 13226, 1692, 304, 272, 2073, 63, 466, 275, 298, 13226, 447, 18445, 51, 447, 3737, 4845, 2, 339, 10792, 275, 469, 267, 283, 4845, 5564, 356, 334, 3185, 1313, 12, 756, 395, 267, 283, 3737, 83, 356, 334, 513, 12, 715, 395, 272, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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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 ]
Baumelbi/IntroPython2016
Solutions/Session02/fizz_buzz.py
3
1591
#!/usr/bin/env python """ Fizz Buzz examples -- from most straightforward, to most compact. """ # basic approach: def fizzbuzz1(n): for i in range(1, n + 1): if i % 3 == 0 and i % 5 == 0: print("FizzBuzz") elif i % 3 == 0: print ("Fizz") elif i % 5 == 0: print ("Buzz") else: print(i) def fizzbuzz2(n): """ Why evaluate i%3 and i%5 twice? """ for i in range(1, n + 1): msg = '' if i % 3 == 0: msg += "Fizz" if i % 5 == 0: msg += "Buzz" if msg: print(msg) else: print(i) def fizzbuzz3(n): """ Or print on one line... """ for i in range(1, n + 1): num = True if i % 3 == 0: print("\nFizz", end='') num = False if i % 5 == 0: if num: print() print("Buzz", end='') num = False else: if num: print("\n", i, end='') def fizzbuzz4(n): """ use conditional expressions: """ for i in range(1, n + 1): msg = "Fizz" if i % 3 == 0 else '' msg += "Buzz" if i % 5 == 0 else '' print(msg or i) def fizzbuzz5(n): """ a one liner """ for i in range(1, n + 1): print (("Fizz" * (not (i % 3)) + "Buzz" * (not (i % 5))) or i) if __name__ == "__main__": fizzbuzz1(16) print() fizzbuzz2(16) print() fizzbuzz3(16) print() fizzbuzz4(16) print() fizzbuzz4(16) print()
unlicense
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 624, 199, 38, 28981, 4779, 4348, 7251, 1553, 687, 4750, 23669, 6688, 12, 370, 4750, 23314, 14, 199, 624, 421, 199, 3, 5678, 18140, 26, 199, 318, 289, 28981, 464, 4348, 17, 8, 78, 304, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 267, 340, 284, 450, 650, 508, 378, 436, 284, 450, 959, 508, 378, 26, 288, 870, 480, 38, 28981, 1713, 4348, 531, 267, 916, 284, 450, 650, 508, 378, 26, 288, 870, 1689, 38, 28981, 531, 267, 916, 284, 450, 959, 508, 378, 26, 288, 870, 1689, 1713, 4348, 531, 267, 587, 26, 288, 870, 8, 73, 9, 421, 199, 318, 289, 28981, 464, 4348, 18, 8, 78, 304, 272, 408, 272, 6827, 9352, 284, 5, 19, 436, 284, 5, 21, 13373, 31, 272, 408, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 267, 1499, 275, 2125, 267, 340, 284, 450, 650, 508, 378, 26, 288, 1499, 847, 298, 38, 28981, 2, 267, 340, 284, 450, 959, 508, 378, 26, 288, 1499, 847, 298, 1713, 4348, 2, 267, 340, 1499, 26, 288, 870, 8, 1328, 9, 267, 587, 26, 288, 870, 8, 73, 9, 421, 199, 318, 289, 28981, 464, 4348, 19, 8, 78, 304, 272, 408, 272, 4236, 870, 641, 1373, 1004, 1396, 272, 408, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 267, 1967, 275, 715, 267, 340, 284, 450, 650, 508, 378, 26, 288, 870, 4582, 78, 38, 28981, 401, 1284, 13275, 288, 1967, 275, 756, 267, 340, 284, 450, 959, 508, 378, 26, 288, 340, 1967, 26, 355, 870, 342, 288, 870, 480, 1713, 4348, 401, 1284, 13275, 288, 1967, 275, 756, 267, 587, 26, 288, 340, 1967, 26, 355, 870, 4582, 78, 401, 284, 12, 1284, 13275, 421, 199, 318, 289, 28981, 464, 4348, 20, 8, 78, 304, 272, 408, 272, 675, 12303, 8455, 26, 272, 408, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 267, 1499, 275, 298, 38, 28981, 2, 340, 284, 450, 650, 508, 378, 587, 2125, 267, 1499, 847, 298, 1713, 4348, 2, 340, 284, 450, 959, 508, 378, 587, 2125, 267, 870, 8, 1328, 503, 284, 9, 421, 199, 318, 289, 28981, 464, 4348, 21, 8, 78, 304, 272, 408, 272, 282, 1373, 7403, 281, 272, 408, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 870, 19110, 38, 28981, 2, 627, 334, 1397, 334, 73, 450, 650, 430, 435, 298, 1713, 4348, 2, 627, 334, 1397, 334, 73, 450, 959, 1724, 503, 284, 9, 421, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 289, 28981, 464, 4348, 17, 8, 975, 9, 272, 870, 342, 272, 289, 28981, 464, 4348, 18, 8, 975, 9, 272, 870, 342, 272, 289, 28981, 464, 4348, 19, 8, 975, 9, 272, 870, 342, 272, 289, 28981, 464, 4348, 20, 8, 975, 9, 272, 870, 342, 272, 289, 28981, 464, 4348, 20, 8, 975, 9, 272, 870, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 624, 199, 38, 28981, 4779, 4348, 7251, 1553, 687, 4750, 23669, 6688, 12, 370, 4750, 23314, 14, 199, 624, 421, 199, 3, 5678, 18140, 26, 199, 318, 289, 28981, 464, 4348, 17, 8, 78, 304, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 267, 340, 284, 450, 650, 508, 378, 436, 284, 450, 959, 508, 378, 26, 288, 870, 480, 38, 28981, 1713, 4348, 531, 267, 916, 284, 450, 650, 508, 378, 26, 288, 870, 1689, 38, 28981, 531, 267, 916, 284, 450, 959, 508, 378, 26, 288, 870, 1689, 1713, 4348, 531, 267, 587, 26, 288, 870, 8, 73, 9, 421, 199, 318, 289, 28981, 464, 4348, 18, 8, 78, 304, 272, 408, 272, 6827, 9352, 284, 5, 19, 436, 284, 5, 21, 13373, 31, 272, 408, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 267, 1499, 275, 2125, 267, 340, 284, 450, 650, 508, 378, 26, 288, 1499, 847, 298, 38, 28981, 2, 267, 340, 284, 450, 959, 508, 378, 26, 288, 1499, 847, 298, 1713, 4348, 2, 267, 340, 1499, 26, 288, 870, 8, 1328, 9, 267, 587, 26, 288, 870, 8, 73, 9, 421, 199, 318, 289, 28981, 464, 4348, 19, 8, 78, 304, 272, 408, 272, 4236, 870, 641, 1373, 1004, 1396, 272, 408, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 267, 1967, 275, 715, 267, 340, 284, 450, 650, 508, 378, 26, 288, 870, 4582, 78, 38, 28981, 401, 1284, 13275, 288, 1967, 275, 756, 267, 340, 284, 450, 959, 508, 378, 26, 288, 340, 1967, 26, 355, 870, 342, 288, 870, 480, 1713, 4348, 401, 1284, 13275, 288, 1967, 275, 756, 267, 587, 26, 288, 340, 1967, 26, 355, 870, 4582, 78, 401, 284, 12, 1284, 13275, 421, 199, 318, 289, 28981, 464, 4348, 20, 8, 78, 304, 272, 408, 272, 675, 12303, 8455, 26, 272, 408, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 267, 1499, 275, 298, 38, 28981, 2, 340, 284, 450, 650, 508, 378, 587, 2125, 267, 1499, 847, 298, 1713, 4348, 2, 340, 284, 450, 959, 508, 378, 587, 2125, 267, 870, 8, 1328, 503, 284, 9, 421, 199, 318, 289, 28981, 464, 4348, 21, 8, 78, 304, 272, 408, 272, 282, 1373, 7403, 281, 272, 408, 272, 367, 284, 315, 1425, 8, 17, 12, 302, 435, 413, 304, 870, 19110, 38, 28981, 2, 627, 334, 1397, 334, 73, 450, 650, 430, 435, 298, 1713, 4348, 2, 627, 334, 1397, 334, 73, 450, 959, 1724, 503, 284, 9, 421, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 272, 289, 28981, 464, 4348, 17, 8, 975, 9, 272, 870, 342, 272, 289, 28981, 464, 4348, 18, 8, 975, 9, 272, 870, 342, 272, 289, 28981, 464, 4348, 19, 8, 975, 9, 272, 870, 342, 272, 289, 28981, 464, 4348, 20, 8, 975, 9, 272, 870, 342, 272, 289, 28981, 464, 4348, 20, 8, 975, 9, 272, 870, 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, 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, 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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 ]
edxnercel/edx-platform
common/djangoapps/track/tracker.py
239
2374
""" Module that tracks analytics events by sending them to different configurable backends. The backends can be configured using Django settings as the example below:: TRACKING_BACKENDS = { 'tracker_name': { 'ENGINE': 'class.name.for.backend', 'OPTIONS': { 'host': ... , 'port': ... , ... } } } """ import inspect from importlib import import_module from dogapi import dog_stats_api from django.conf import settings from track.backends import BaseBackend __all__ = ['send'] backends = {} def _initialize_backends_from_django_settings(): """ Initialize the event tracking backends according to the configuration in django settings """ backends.clear() config = getattr(settings, 'TRACKING_BACKENDS', {}) for name, values in config.iteritems(): # Ignore empty values to turn-off default tracker backends if values: engine = values['ENGINE'] options = values.get('OPTIONS', {}) backends[name] = _instantiate_backend_from_name(engine, options) def _instantiate_backend_from_name(name, options): """ Instantiate an event tracker backend from the full module path to the backend class. Useful when setting backends from configuration files. """ # Parse backend name try: parts = name.split('.') module_name = '.'.join(parts[:-1]) class_name = parts[-1] except IndexError: raise ValueError('Invalid event track backend %s' % name) # Get and verify the backend class try: module = import_module(module_name) cls = getattr(module, class_name) if not inspect.isclass(cls) or not issubclass(cls, BaseBackend): raise TypeError except (ValueError, AttributeError, TypeError, ImportError): raise ValueError('Cannot find event track backend %s' % name) backend = cls(**options) return backend @dog_stats_api.timed('track.send') def send(event): """ Send an event object to all the initialized backends. """ dog_stats_api.increment('track.send.count') for name, backend in backends.iteritems(): with dog_stats_api.timer('track.send.backend.{0}'.format(name)): backend.send(event) _initialize_backends_from_django_settings()
agpl-3.0
[ 624, 199, 2377, 626, 18917, 30159, 4474, 701, 10209, 3062, 370, 3365, 199, 888, 15684, 14745, 14, 199, 199, 1918, 14745, 883, 506, 7526, 1808, 5634, 2202, 465, 314, 2893, 199, 12843, 447, 819, 9074, 3099, 1206, 63, 28988, 275, 469, 489, 283, 8877, 63, 354, 356, 469, 881, 283, 15956, 356, 283, 533, 14, 354, 14, 509, 14, 4620, 297, 881, 283, 8808, 356, 469, 1598, 283, 1102, 356, 2263, 2360, 1598, 283, 719, 356, 2263, 2360, 1598, 2263, 881, 789, 489, 789, 523, 789, 199, 199, 624, 199, 199, 646, 6485, 199, 504, 14802, 492, 492, 63, 578, 199, 199, 504, 23454, 1246, 492, 23454, 63, 3200, 63, 1246, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 199, 504, 4426, 14, 7765, 492, 3523, 8447, 421, 199, 363, 452, 363, 275, 788, 2254, 418, 421, 199, 7765, 275, 1052, 421, 199, 318, 485, 8489, 63, 7765, 63, 504, 63, 1176, 63, 1751, 837, 272, 408, 272, 11578, 314, 1566, 15161, 14745, 7182, 370, 314, 272, 2897, 315, 1639, 2202, 339, 408, 272, 14745, 14, 3584, 342, 339, 1101, 275, 2519, 8, 1751, 12, 283, 19755, 1206, 63, 28988, 297, 5009, 339, 367, 536, 12, 1338, 315, 1101, 14, 4611, 837, 267, 327, 14092, 2701, 1338, 370, 7485, 13, 1997, 849, 15271, 14745, 267, 340, 1338, 26, 288, 6869, 275, 1338, 459, 15956, 418, 288, 1511, 275, 1338, 14, 362, 360, 8808, 297, 5009, 288, 14745, 59, 354, 61, 275, 485, 3615, 18973, 63, 4620, 63, 504, 63, 354, 8, 3908, 12, 1511, 9, 421, 199, 318, 485, 3615, 18973, 63, 4620, 63, 504, 63, 354, 8, 354, 12, 1511, 304, 272, 408, 272, 32092, 376, 1566, 15271, 4865, 687, 314, 2615, 859, 931, 370, 272, 314, 4865, 1021, 14, 18491, 1380, 4260, 14745, 687, 2897, 272, 1584, 14, 339, 408, 272, 327, 6077, 4865, 536, 339, 862, 26, 267, 4184, 275, 536, 14, 1294, 7563, 267, 859, 63, 354, 275, 15671, 904, 8, 4181, 4439, 17, 566, 267, 1021, 63, 354, 275, 4184, 1988, 17, 61, 272, 871, 7888, 26, 267, 746, 1722, 360, 3364, 1566, 4426, 4865, 450, 83, 7, 450, 536, 9, 339, 327, 2372, 436, 4911, 314, 4865, 1021, 339, 862, 26, 267, 859, 275, 492, 63, 578, 8, 578, 63, 354, 9, 267, 843, 275, 2519, 8, 578, 12, 1021, 63, 354, 9, 267, 340, 440, 6485, 14, 28450, 8, 1886, 9, 503, 440, 11602, 8, 1886, 12, 3523, 8447, 304, 288, 746, 3146, 272, 871, 334, 3393, 12, 4281, 12, 3146, 12, 3545, 304, 267, 746, 1722, 360, 6612, 2342, 1566, 4426, 4865, 450, 83, 7, 450, 536, 9, 339, 4865, 275, 843, 3682, 1419, 9, 339, 372, 4865, 421, 199, 32, 13889, 63, 3200, 63, 1246, 14, 26687, 360, 3885, 14, 2254, 358, 199, 318, 3222, 8, 1430, 304, 272, 408, 272, 10217, 376, 1566, 909, 370, 1006, 314, 10038, 14745, 14, 339, 408, 272, 23454, 63, 3200, 63, 1246, 14, 9728, 360, 3885, 14, 2254, 14, 835, 358, 339, 367, 536, 12, 4865, 315, 14745, 14, 4611, 837, 267, 543, 23454, 63, 3200, 63, 1246, 14, 7414, 360, 3885, 14, 2254, 14, 4620, 23379, 16, 5285, 908, 8, 354, 2298, 288, 4865, 14, 2254, 8, 1430, 9, 421, 199, 63, 8489, 63, 7765, 63, 504, 63, 1176, 63, 1751, 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 ]
[ 199, 2377, 626, 18917, 30159, 4474, 701, 10209, 3062, 370, 3365, 199, 888, 15684, 14745, 14, 199, 199, 1918, 14745, 883, 506, 7526, 1808, 5634, 2202, 465, 314, 2893, 199, 12843, 447, 819, 9074, 3099, 1206, 63, 28988, 275, 469, 489, 283, 8877, 63, 354, 356, 469, 881, 283, 15956, 356, 283, 533, 14, 354, 14, 509, 14, 4620, 297, 881, 283, 8808, 356, 469, 1598, 283, 1102, 356, 2263, 2360, 1598, 283, 719, 356, 2263, 2360, 1598, 2263, 881, 789, 489, 789, 523, 789, 199, 199, 624, 199, 199, 646, 6485, 199, 504, 14802, 492, 492, 63, 578, 199, 199, 504, 23454, 1246, 492, 23454, 63, 3200, 63, 1246, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 199, 504, 4426, 14, 7765, 492, 3523, 8447, 421, 199, 363, 452, 363, 275, 788, 2254, 418, 421, 199, 7765, 275, 1052, 421, 199, 318, 485, 8489, 63, 7765, 63, 504, 63, 1176, 63, 1751, 837, 272, 408, 272, 11578, 314, 1566, 15161, 14745, 7182, 370, 314, 272, 2897, 315, 1639, 2202, 339, 408, 272, 14745, 14, 3584, 342, 339, 1101, 275, 2519, 8, 1751, 12, 283, 19755, 1206, 63, 28988, 297, 5009, 339, 367, 536, 12, 1338, 315, 1101, 14, 4611, 837, 267, 327, 14092, 2701, 1338, 370, 7485, 13, 1997, 849, 15271, 14745, 267, 340, 1338, 26, 288, 6869, 275, 1338, 459, 15956, 418, 288, 1511, 275, 1338, 14, 362, 360, 8808, 297, 5009, 288, 14745, 59, 354, 61, 275, 485, 3615, 18973, 63, 4620, 63, 504, 63, 354, 8, 3908, 12, 1511, 9, 421, 199, 318, 485, 3615, 18973, 63, 4620, 63, 504, 63, 354, 8, 354, 12, 1511, 304, 272, 408, 272, 32092, 376, 1566, 15271, 4865, 687, 314, 2615, 859, 931, 370, 272, 314, 4865, 1021, 14, 18491, 1380, 4260, 14745, 687, 2897, 272, 1584, 14, 339, 408, 272, 327, 6077, 4865, 536, 339, 862, 26, 267, 4184, 275, 536, 14, 1294, 7563, 267, 859, 63, 354, 275, 15671, 904, 8, 4181, 4439, 17, 566, 267, 1021, 63, 354, 275, 4184, 1988, 17, 61, 272, 871, 7888, 26, 267, 746, 1722, 360, 3364, 1566, 4426, 4865, 450, 83, 7, 450, 536, 9, 339, 327, 2372, 436, 4911, 314, 4865, 1021, 339, 862, 26, 267, 859, 275, 492, 63, 578, 8, 578, 63, 354, 9, 267, 843, 275, 2519, 8, 578, 12, 1021, 63, 354, 9, 267, 340, 440, 6485, 14, 28450, 8, 1886, 9, 503, 440, 11602, 8, 1886, 12, 3523, 8447, 304, 288, 746, 3146, 272, 871, 334, 3393, 12, 4281, 12, 3146, 12, 3545, 304, 267, 746, 1722, 360, 6612, 2342, 1566, 4426, 4865, 450, 83, 7, 450, 536, 9, 339, 4865, 275, 843, 3682, 1419, 9, 339, 372, 4865, 421, 199, 32, 13889, 63, 3200, 63, 1246, 14, 26687, 360, 3885, 14, 2254, 358, 199, 318, 3222, 8, 1430, 304, 272, 408, 272, 10217, 376, 1566, 909, 370, 1006, 314, 10038, 14745, 14, 339, 408, 272, 23454, 63, 3200, 63, 1246, 14, 9728, 360, 3885, 14, 2254, 14, 835, 358, 339, 367, 536, 12, 4865, 315, 14745, 14, 4611, 837, 267, 543, 23454, 63, 3200, 63, 1246, 14, 7414, 360, 3885, 14, 2254, 14, 4620, 23379, 16, 5285, 908, 8, 354, 2298, 288, 4865, 14, 2254, 8, 1430, 9, 421, 199, 63, 8489, 63, 7765, 63, 504, 63, 1176, 63, 1751, 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, 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, 0 ]
Dogeparty/dogepartyd
lib/broadcast.py
4
12334
#! /usr/bin/python3 """ Broadcast a message, with or without a price. Multiple messages per block are allowed. Bets are be made on the 'timestamp' field, and not the block index. An address is a feed of broadcasts. Feeds may be locked with a broadcast whose text field is identical to ‘lock’ (case insensitive). Bets on a feed reference the address that is the source of the feed in an output which includes the (latest) required fee. Broadcasts without a price may not be used for betting. Broadcasts about events with a small number of possible outcomes (e.g. sports games), should be written, for example, such that a price of 1 XCP means one outcome, 2 XCP means another, etc., which schema should be described in the 'text' field. fee_fraction: .05 XCP means 5%. It may be greater than 1, however; but because it is stored as a four‐byte integer, it may not be greater than about 42. """ import struct import decimal D = decimal.Decimal from fractions import Fraction import logging from . import (util, exceptions, config, bitcoin) from . import (bet) FORMAT = '>IdI52p' LENGTH = 4 + 8 + 4 + 52 ID = 30 def validate (db, source, timestamp, value, fee_fraction_int, text): problems = [] if fee_fraction_int > 4294967295: problems.append('fee fraction greater than 42.94967295') if timestamp < 0: problems.append('negative timestamp') if not source: problems.append('null source address') # Check previous broadcast in this feed. cursor = db.cursor() broadcasts = list(cursor.execute('''SELECT * FROM broadcasts WHERE (status = ? AND source = ?) ORDER BY tx_index ASC''', ('valid', source))) cursor.close() if broadcasts: last_broadcast = broadcasts[-1] if last_broadcast['locked']: problems.append('locked feed') elif timestamp <= last_broadcast['timestamp']: problems.append('feed timestamps not monotonically increasing') return problems def compose (db, source, timestamp, value, fee_fraction, text): # Store the fee fraction as an integer. fee_fraction_int = int(fee_fraction * 1e8) problems = validate(db, source, timestamp, value, fee_fraction_int, text) if problems: raise exceptions.BroadcastError(problems) data = config.PREFIX + struct.pack(config.TXTYPE_FORMAT, ID) data += struct.pack(FORMAT, timestamp, value, fee_fraction_int, text.encode('utf-8')) if len(data) > 80: raise exceptions.BroadcastError('Text is greater than 52 bytes.') return (source, [], data) def parse (db, tx, message): cursor = db.cursor() # Unpack message. try: assert len(message) == LENGTH timestamp, value, fee_fraction_int, text = struct.unpack(FORMAT, message) text = text.decode('utf-8') status = 'valid' except (AssertionError, struct.error) as e: timestamp, value, fee_fraction_int, text = 0, None, 0, None status = 'invalid: could not unpack' if status == 'valid': # For SQLite3 timestamp = min(timestamp, config.MAX_INT) value = min(value, config.MAX_INT) problems = validate(db, tx['source'], timestamp, value, fee_fraction_int, text) if problems: status = 'invalid: ' + '; '.join(problems) # Lock? lock = False if text and text.lower() == 'lock': lock = True timestamp, value, fee_fraction_int, text = 0, None, None, None else: lock = False # Add parsed transaction to message-type–specific table. bindings = { 'tx_index': tx['tx_index'], 'tx_hash': tx['tx_hash'], 'block_index': tx['block_index'], 'source': tx['source'], 'timestamp': timestamp, 'value': value, 'fee_fraction_int': fee_fraction_int, 'text': text, 'locked': lock, 'status': status, } sql='insert into broadcasts values(:tx_index, :tx_hash, :block_index, :source, :timestamp, :value, :fee_fraction_int, :text, :locked, :status)' cursor.execute(sql, bindings) # Negative values (default to ignore). if value == None or value < 0: # Cancel Open Bets? if value == -2: cursor.execute('''SELECT * FROM bets \ WHERE (status = ? AND feed_address = ?)''', ('open', tx['source'])) for i in list(cursor): bet.cancel_bet(db, i, 'dropped', tx['block_index']) # Cancel Pending Bet Matches? if value == -3: cursor.execute('''SELECT * FROM bet_matches \ WHERE (status = ? AND feed_address = ?)''', ('pending', tx['source'])) for bet_match in list(cursor): bet.cancel_bet_match(db, bet_match, 'dropped', tx['block_index']) cursor.close() return # Handle bet matches that use this feed. cursor.execute('''SELECT * FROM bet_matches \ WHERE (status=? AND feed_address=?) ORDER BY tx1_index ASC, tx0_index ASC''', ('pending', tx['source'])) for bet_match in cursor.fetchall(): broadcast_bet_match_cursor = db.cursor() bet_match_id = bet_match['tx0_hash'] + bet_match['tx1_hash'] bet_match_status = None # Calculate total funds held in escrow and total fee to be paid if # the bet match is settled. Escrow less fee is amount to be paid back # to betters. total_escrow = bet_match['forward_quantity'] + bet_match['backward_quantity'] fee_fraction = fee_fraction_int / config.UNIT fee = int(fee_fraction * total_escrow) # Truncate. escrow_less_fee = total_escrow - fee # Get known bet match type IDs. cfd_type_id = util.BET_TYPE_ID['BullCFD'] + util.BET_TYPE_ID['BearCFD'] equal_type_id = util.BET_TYPE_ID['Equal'] + util.BET_TYPE_ID['NotEqual'] # Get the bet match type ID of this bet match. bet_match_type_id = bet_match['tx0_bet_type'] + bet_match['tx1_bet_type'] # Contract for difference, with determinate settlement date. if bet_match_type_id == cfd_type_id: # Recognise tx0, tx1 as the bull, bear (in the right direction). if bet_match['tx0_bet_type'] < bet_match['tx1_bet_type']: bull_address = bet_match['tx0_address'] bear_address = bet_match['tx1_address'] bull_escrow = bet_match['forward_quantity'] bear_escrow = bet_match['backward_quantity'] else: bull_address = bet_match['tx1_address'] bear_address = bet_match['tx0_address'] bull_escrow = bet_match['backward_quantity'] bear_escrow = bet_match['forward_quantity'] leverage = Fraction(bet_match['leverage'], 5040) initial_value = bet_match['initial_value'] bear_credit = bear_escrow - (value - initial_value) * leverage * config.UNIT bull_credit = escrow_less_fee - bear_credit bear_credit = round(bear_credit) bull_credit = round(bull_credit) # Liquidate, as necessary. if bull_credit >= escrow_less_fee or bull_credit <= 0: if bull_credit >= escrow_less_fee: bull_credit = escrow_less_fee bear_credit = 0 util.credit(db, tx['block_index'], bull_address, config.XCP, bull_credit) bet_match_status = 'settled: liquidated for bull' elif bull_credit <= 0: bull_credit = 0 bear_credit = escrow_less_fee util.credit(db, tx['block_index'], bear_address, config.XCP, bear_credit) bet_match_status = 'settled: liquidated for bear' # Pay fee to feed. util.credit(db, tx['block_index'], bet_match['feed_address'], config.XCP, fee) # For logging purposes. bindings = { 'bet_match_id': bet_match_id, 'bet_match_type_id': bet_match_type_id, 'block_index': tx['block_index'], 'settled': False, 'bull_credit': bull_credit, 'bear_credit': bear_credit, 'winner': None, 'escrow_less_fee': None, 'fee': fee } sql='insert into bet_match_resolutions values(:bet_match_id, :bet_match_type_id, :block_index, :settled, :bull_credit, :bear_credit, :winner, :escrow_less_fee, :fee)' cursor.execute(sql, bindings) # Settle (if not liquidated). elif timestamp >= bet_match['deadline']: bet_match_status = 'settled' util.credit(db, tx['block_index'], bull_address, config.XCP, bull_credit) util.credit(db, tx['block_index'], bear_address, config.XCP, bear_credit) # Pay fee to feed. util.credit(db, tx['block_index'], bet_match['feed_address'], config.XCP, fee) # For logging purposes. bindings = { 'bet_match_id': bet_match_id, 'bet_match_type_id': bet_match_type_id, 'block_index': tx['block_index'], 'settled': True, 'bull_credit': bull_credit, 'bear_credit': bear_credit, 'winner': None, 'escrow_less_fee': None, 'fee': fee } sql='insert into bet_match_resolutions values(:bet_match_id, :bet_match_type_id, :block_index, :settled, :bull_credit, :bear_credit, :winner, :escrow_less_fee, :fee)' cursor.execute(sql, bindings) # Equal[/NotEqual] bet. elif bet_match_type_id == equal_type_id and timestamp >= bet_match['deadline']: # Recognise tx0, tx1 as the bull, bear (in the right direction). if bet_match['tx0_bet_type'] < bet_match['tx1_bet_type']: equal_address = bet_match['tx0_address'] notequal_address = bet_match['tx1_address'] else: equal_address = bet_match['tx1_address'] notequal_address = bet_match['tx0_address'] # Decide who won, and credit appropriately. if value == bet_match['target_value']: winner = 'Equal' util.credit(db, tx['block_index'], equal_address, config.XCP, escrow_less_fee) bet_match_status = 'settled: for equal' else: winner = 'NotEqual' util.credit(db, tx['block_index'], notequal_address, config.XCP, escrow_less_fee) bet_match_status = 'settled: for notequal' # Pay fee to feed. util.credit(db, tx['block_index'], bet_match['feed_address'], config.XCP, fee) # For logging purposes. bindings = { 'bet_match_id': bet_match_id, 'bet_match_type_id': bet_match_type_id, 'block_index': tx['block_index'], 'settled': None, 'bull_credit': None, 'bear_credit': None, 'winner': winner, 'escrow_less_fee': escrow_less_fee, 'fee': fee } sql='insert into bet_match_resolutions values(:bet_match_id, :bet_match_type_id, :block_index, :settled, :bull_credit, :bear_credit, :winner, :escrow_less_fee, :fee)' cursor.execute(sql, bindings) # Update the bet match’s status. if bet_match_status: bindings = { 'status': bet_match_status, 'bet_match_id': bet_match['tx0_hash'] + bet_match['tx1_hash'] } sql='update bet_matches set status = :status where id = :bet_match_id' cursor.execute(sql, bindings) util.message(db, tx['block_index'], 'update', 'bet_matches', bindings) broadcast_bet_match_cursor.close() cursor.close() # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
mit
[ 3168, 1182, 2647, 15, 1393, 15, 1548, 19, 199, 199, 624, 199, 12105, 282, 1245, 12, 543, 503, 1928, 282, 8033, 14, 199, 199, 8433, 3788, 1126, 1853, 787, 4370, 14, 699, 8716, 787, 506, 6326, 641, 314, 283, 3954, 7, 199, 698, 12, 436, 440, 314, 1853, 1478, 14, 199, 199, 2493, 2287, 365, 282, 4733, 402, 11180, 83, 14, 7949, 5923, 1443, 506, 14233, 543, 282, 11180, 7447, 199, 505, 901, 365, 13130, 370, 27430, 247, 831, 21045, 334, 2546, 27845, 680, 699, 8716, 641, 282, 4733, 3659, 199, 1589, 2287, 626, 365, 314, 1350, 402, 314, 4733, 315, 376, 1072, 1314, 6952, 314, 199, 8, 7410, 9, 1415, 14751, 14, 199, 199, 12105, 83, 1928, 282, 8033, 1443, 440, 506, 1202, 367, 2907, 1337, 14, 699, 5659, 83, 3595, 4474, 199, 1045, 282, 7425, 1329, 402, 3962, 15955, 83, 334, 69, 14, 71, 14, 308, 5203, 9219, 83, 395, 1077, 506, 199, 8938, 12, 367, 2893, 12, 4066, 626, 282, 8033, 402, 413, 1323, 2890, 4910, 1373, 15955, 12, 499, 1323, 2890, 4910, 199, 13565, 12, 5423, 2020, 1314, 4177, 1077, 506, 11736, 315, 314, 283, 505, 7, 901, 14, 199, 199, 11195, 63, 13054, 26, 1275, 1717, 1323, 2890, 4910, 959, 17229, 2779, 1443, 506, 8932, 2419, 413, 12, 13432, 27, 1325, 199, 20684, 652, 365, 5489, 465, 282, 11648, 8477, 239, 4414, 3000, 12, 652, 1443, 440, 506, 8932, 2419, 3595, 199, 2260, 14, 199, 624, 199, 199, 646, 2702, 199, 646, 6107, 199, 36, 275, 6107, 14, 6745, 199, 504, 28213, 2452, 492, 17980, 199, 646, 2050, 199, 199, 504, 1275, 492, 334, 1974, 12, 4967, 12, 1101, 12, 27214, 9, 199, 504, 1275, 492, 334, 9549, 9, 199, 199, 4807, 275, 12696, 1304, 41, 2528, 80, 7, 199, 9127, 275, 841, 435, 1695, 435, 841, 435, 14589, 199, 998, 275, 4233, 421, 199, 318, 4107, 334, 697, 12, 1350, 12, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 304, 272, 8826, 275, 942, 339, 340, 14751, 63, 13054, 63, 442, 690, 21504, 11405, 26, 267, 8826, 14, 740, 360, 11195, 12347, 8932, 2419, 5685, 14, 15674, 1822, 11405, 358, 339, 340, 4913, 665, 378, 26, 8826, 14, 740, 360, 7371, 4913, 358, 339, 340, 440, 1350, 26, 267, 8826, 14, 740, 360, 2307, 1350, 2287, 358, 272, 327, 2670, 4136, 11180, 315, 642, 4733, 14, 272, 3920, 275, 1592, 14, 3937, 342, 272, 11180, 83, 275, 769, 8, 3937, 14, 2526, 10505, 4859, 627, 4442, 11180, 83, 6038, 334, 1205, 275, 5805, 2401, 1350, 275, 5805, 9, 16044, 6515, 4773, 63, 1080, 20955, 18108, 661, 1078, 297, 1350, 1724, 272, 3920, 14, 1600, 342, 272, 340, 11180, 83, 26, 267, 2061, 63, 10786, 275, 11180, 83, 1988, 17, 61, 267, 340, 2061, 63, 10786, 459, 9325, 2565, 288, 8826, 14, 740, 360, 9325, 4733, 358, 267, 916, 4913, 2695, 2061, 63, 10786, 459, 3954, 2565, 288, 8826, 14, 740, 360, 3871, 22496, 440, 3485, 357, 265, 7288, 22255, 358, 339, 372, 8826, 199, 199, 318, 23366, 334, 697, 12, 1350, 12, 4913, 12, 574, 12, 14751, 63, 13054, 12, 1318, 304, 339, 327, 13874, 314, 14751, 12347, 465, 376, 3000, 14, 272, 14751, 63, 13054, 63, 442, 275, 1109, 8, 11195, 63, 13054, 627, 413, 69, 24, 9, 339, 8826, 275, 4107, 8, 697, 12, 1350, 12, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 9, 272, 340, 8826, 26, 746, 4967, 14, 12105, 547, 8, 22959, 9, 339, 666, 275, 1101, 14, 6351, 435, 2702, 14, 1389, 8, 888, 14, 10051, 2711, 63, 4807, 12, 2870, 9, 272, 666, 847, 2702, 14, 1389, 8, 4807, 12, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 717, 1318, 14, 2143, 360, 1624, 13, 24, 1333, 272, 340, 822, 8, 576, 9, 690, 5939, 26, 267, 746, 4967, 14, 12105, 547, 360, 1872, 365, 8932, 2419, 14589, 2783, 2659, 272, 372, 334, 1365, 12, 990, 666, 9, 199, 199, 318, 2198, 334, 697, 12, 4773, 12, 1245, 304, 272, 3920, 275, 1592, 14, 3937, 342, 339, 327, 31017, 1245, 14, 272, 862, 26, 267, 702, 822, 8, 1188, 9, 508, 491, 32106, 267, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 275, 2702, 14, 5301, 8, 4807, 12, 1245, 9, 267, 1318, 275, 1318, 14, 2708, 360, 1624, 13, 24, 358, 267, 2004, 275, 283, 1078, 7, 272, 871, 334, 14844, 12, 2702, 14, 705, 9, 465, 325, 26, 267, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 275, 378, 12, 488, 12, 378, 12, 488, 267, 2004, 275, 283, 3197, 26, 4293, 440, 7787, 7, 339, 340, 2004, 508, 283, 1078, 356, 267, 327, 2104, 19245, 19, 267, 4913, 275, 1748, 8, 3954, 12, 1101, 14, 4283, 63, 2919, 9, 267, 574, 275, 1748, 8, 585, 12, 1101, 14, 4283, 63, 2919, 9, 398, 8826, 275, 4107, 8, 697, 12, 4773, 459, 1365, 995, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 9, 267, 340, 8826, 26, 2004, 275, 283, 3197, 26, 283, 435, 14289, 1987, 904, 8, 22959, 9, 339, 327, 15536, 31, 272, 4650, 275, 756, 272, 340, 1318, 436, 1318, 14, 2325, 342, 508, 283, 831, 356, 267, 4650, 275, 715, 267, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 275, 378, 12, 488, 12, 488, 12, 488, 272, 587, 26, 267, 4650, 275, 756, 339, 327, 2654, 4565, 6008, 370, 1245, 13, 466, 8477, 242, 6100, 1817, 14, 272, 17792, 275, 469, 267, 283, 2347, 63, 1080, 356, 4773, 459, 2347, 63, 1080, 995, 267, 283, 2347, 63, 2227, 356, 4773, 459, 2347, 63, 2227, 995, 267, 283, 1457, 63, 1080, 356, 4773, 459, 1457, 63, 1080, 995, 267, 283, 1365, 356, 4773, 459, 1365, 995, 267, 283, 3954, 356, 4913, 12, 267, 283, 585, 356, 574, 12, 267, 283, 11195, 63, 13054, 63, 442, 356, 14751, 63, 13054, 63, 442, 12, 267, 283, 505, 356, 1318, 12, 267, 283, 9325, 356, 4650, 12, 267, 283, 1205, 356, 2004, 12, 272, 789, 272, 3875, 534, 3176, 1901, 11180, 83, 1338, 8, 26, 2347, 63 ]
[ 1182, 2647, 15, 1393, 15, 1548, 19, 199, 199, 624, 199, 12105, 282, 1245, 12, 543, 503, 1928, 282, 8033, 14, 199, 199, 8433, 3788, 1126, 1853, 787, 4370, 14, 699, 8716, 787, 506, 6326, 641, 314, 283, 3954, 7, 199, 698, 12, 436, 440, 314, 1853, 1478, 14, 199, 199, 2493, 2287, 365, 282, 4733, 402, 11180, 83, 14, 7949, 5923, 1443, 506, 14233, 543, 282, 11180, 7447, 199, 505, 901, 365, 13130, 370, 27430, 247, 831, 21045, 334, 2546, 27845, 680, 699, 8716, 641, 282, 4733, 3659, 199, 1589, 2287, 626, 365, 314, 1350, 402, 314, 4733, 315, 376, 1072, 1314, 6952, 314, 199, 8, 7410, 9, 1415, 14751, 14, 199, 199, 12105, 83, 1928, 282, 8033, 1443, 440, 506, 1202, 367, 2907, 1337, 14, 699, 5659, 83, 3595, 4474, 199, 1045, 282, 7425, 1329, 402, 3962, 15955, 83, 334, 69, 14, 71, 14, 308, 5203, 9219, 83, 395, 1077, 506, 199, 8938, 12, 367, 2893, 12, 4066, 626, 282, 8033, 402, 413, 1323, 2890, 4910, 1373, 15955, 12, 499, 1323, 2890, 4910, 199, 13565, 12, 5423, 2020, 1314, 4177, 1077, 506, 11736, 315, 314, 283, 505, 7, 901, 14, 199, 199, 11195, 63, 13054, 26, 1275, 1717, 1323, 2890, 4910, 959, 17229, 2779, 1443, 506, 8932, 2419, 413, 12, 13432, 27, 1325, 199, 20684, 652, 365, 5489, 465, 282, 11648, 8477, 239, 4414, 3000, 12, 652, 1443, 440, 506, 8932, 2419, 3595, 199, 2260, 14, 199, 624, 199, 199, 646, 2702, 199, 646, 6107, 199, 36, 275, 6107, 14, 6745, 199, 504, 28213, 2452, 492, 17980, 199, 646, 2050, 199, 199, 504, 1275, 492, 334, 1974, 12, 4967, 12, 1101, 12, 27214, 9, 199, 504, 1275, 492, 334, 9549, 9, 199, 199, 4807, 275, 12696, 1304, 41, 2528, 80, 7, 199, 9127, 275, 841, 435, 1695, 435, 841, 435, 14589, 199, 998, 275, 4233, 421, 199, 318, 4107, 334, 697, 12, 1350, 12, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 304, 272, 8826, 275, 942, 339, 340, 14751, 63, 13054, 63, 442, 690, 21504, 11405, 26, 267, 8826, 14, 740, 360, 11195, 12347, 8932, 2419, 5685, 14, 15674, 1822, 11405, 358, 339, 340, 4913, 665, 378, 26, 8826, 14, 740, 360, 7371, 4913, 358, 339, 340, 440, 1350, 26, 267, 8826, 14, 740, 360, 2307, 1350, 2287, 358, 272, 327, 2670, 4136, 11180, 315, 642, 4733, 14, 272, 3920, 275, 1592, 14, 3937, 342, 272, 11180, 83, 275, 769, 8, 3937, 14, 2526, 10505, 4859, 627, 4442, 11180, 83, 6038, 334, 1205, 275, 5805, 2401, 1350, 275, 5805, 9, 16044, 6515, 4773, 63, 1080, 20955, 18108, 661, 1078, 297, 1350, 1724, 272, 3920, 14, 1600, 342, 272, 340, 11180, 83, 26, 267, 2061, 63, 10786, 275, 11180, 83, 1988, 17, 61, 267, 340, 2061, 63, 10786, 459, 9325, 2565, 288, 8826, 14, 740, 360, 9325, 4733, 358, 267, 916, 4913, 2695, 2061, 63, 10786, 459, 3954, 2565, 288, 8826, 14, 740, 360, 3871, 22496, 440, 3485, 357, 265, 7288, 22255, 358, 339, 372, 8826, 199, 199, 318, 23366, 334, 697, 12, 1350, 12, 4913, 12, 574, 12, 14751, 63, 13054, 12, 1318, 304, 339, 327, 13874, 314, 14751, 12347, 465, 376, 3000, 14, 272, 14751, 63, 13054, 63, 442, 275, 1109, 8, 11195, 63, 13054, 627, 413, 69, 24, 9, 339, 8826, 275, 4107, 8, 697, 12, 1350, 12, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 9, 272, 340, 8826, 26, 746, 4967, 14, 12105, 547, 8, 22959, 9, 339, 666, 275, 1101, 14, 6351, 435, 2702, 14, 1389, 8, 888, 14, 10051, 2711, 63, 4807, 12, 2870, 9, 272, 666, 847, 2702, 14, 1389, 8, 4807, 12, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 717, 1318, 14, 2143, 360, 1624, 13, 24, 1333, 272, 340, 822, 8, 576, 9, 690, 5939, 26, 267, 746, 4967, 14, 12105, 547, 360, 1872, 365, 8932, 2419, 14589, 2783, 2659, 272, 372, 334, 1365, 12, 990, 666, 9, 199, 199, 318, 2198, 334, 697, 12, 4773, 12, 1245, 304, 272, 3920, 275, 1592, 14, 3937, 342, 339, 327, 31017, 1245, 14, 272, 862, 26, 267, 702, 822, 8, 1188, 9, 508, 491, 32106, 267, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 275, 2702, 14, 5301, 8, 4807, 12, 1245, 9, 267, 1318, 275, 1318, 14, 2708, 360, 1624, 13, 24, 358, 267, 2004, 275, 283, 1078, 7, 272, 871, 334, 14844, 12, 2702, 14, 705, 9, 465, 325, 26, 267, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 275, 378, 12, 488, 12, 378, 12, 488, 267, 2004, 275, 283, 3197, 26, 4293, 440, 7787, 7, 339, 340, 2004, 508, 283, 1078, 356, 267, 327, 2104, 19245, 19, 267, 4913, 275, 1748, 8, 3954, 12, 1101, 14, 4283, 63, 2919, 9, 267, 574, 275, 1748, 8, 585, 12, 1101, 14, 4283, 63, 2919, 9, 398, 8826, 275, 4107, 8, 697, 12, 4773, 459, 1365, 995, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 9, 267, 340, 8826, 26, 2004, 275, 283, 3197, 26, 283, 435, 14289, 1987, 904, 8, 22959, 9, 339, 327, 15536, 31, 272, 4650, 275, 756, 272, 340, 1318, 436, 1318, 14, 2325, 342, 508, 283, 831, 356, 267, 4650, 275, 715, 267, 4913, 12, 574, 12, 14751, 63, 13054, 63, 442, 12, 1318, 275, 378, 12, 488, 12, 488, 12, 488, 272, 587, 26, 267, 4650, 275, 756, 339, 327, 2654, 4565, 6008, 370, 1245, 13, 466, 8477, 242, 6100, 1817, 14, 272, 17792, 275, 469, 267, 283, 2347, 63, 1080, 356, 4773, 459, 2347, 63, 1080, 995, 267, 283, 2347, 63, 2227, 356, 4773, 459, 2347, 63, 2227, 995, 267, 283, 1457, 63, 1080, 356, 4773, 459, 1457, 63, 1080, 995, 267, 283, 1365, 356, 4773, 459, 1365, 995, 267, 283, 3954, 356, 4913, 12, 267, 283, 585, 356, 574, 12, 267, 283, 11195, 63, 13054, 63, 442, 356, 14751, 63, 13054, 63, 442, 12, 267, 283, 505, 356, 1318, 12, 267, 283, 9325, 356, 4650, 12, 267, 283, 1205, 356, 2004, 12, 272, 789, 272, 3875, 534, 3176, 1901, 11180, 83, 1338, 8, 26, 2347, 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,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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 ]
qrkourier/ansible
lib/ansible/utils/module_docs_fragments/ce.py
126
2957
# # # 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/>. class ModuleDocFragment(object): # Standard files documentation fragment DOCUMENTATION = """ options: provider: description: - A dict object containing connection details. default: null suboptions: host: description: - Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport. required: true port: description: - Specifies the port to use when building the connection to the remote device. This value applies to either I(cli) or I(netconf). The port value will default to the appropriate transport common port if none is provided in the task. (cli=22, netconf=22). required: false default: 0 (use common port) username: description: - Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate the CLI login. If the value is not specified in the task, the value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead. required: false password: description: - Specifies the password to use to authenticate the connection to the remote device. This is a common argument used for cli transports. If the value is not specified in the task, the value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead. required: false default: null ssh_keyfile: description: - Specifies the SSH key to use to authenticate the connection to the remote device. This argument is used for the I(cli) transport. If the value is not specified in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE) will be used instead. required: false transport: description: - Configures the transport connection to use when connecting to the remote device. The transport argument supports connectivity to the device over cli (ssh). required: true default: cli """
gpl-3.0
[ 3, 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, 421, 199, 533, 5673, 3768, 11080, 8, 785, 304, 339, 327, 9739, 1584, 3794, 7956, 272, 29970, 2594, 275, 408, 199, 1419, 26, 523, 5022, 26, 272, 1369, 26, 489, 446, 437, 1211, 909, 3035, 1950, 2436, 14, 272, 849, 26, 2973, 272, 26265, 26, 489, 1591, 26, 267, 1369, 26, 881, 446, 11015, 314, 10237, 1591, 536, 503, 2287, 367, 18170, 370, 314, 3982, 288, 2243, 1806, 314, 2013, 7773, 14, 221, 710, 574, 402, 1591, 365, 1202, 465, 288, 314, 5724, 2287, 367, 314, 7773, 14, 267, 1415, 26, 2549, 489, 1844, 26, 267, 1369, 26, 881, 446, 11015, 314, 1844, 370, 675, 1380, 10015, 314, 1950, 370, 314, 3982, 288, 2243, 14, 221, 961, 574, 12966, 370, 1902, 473, 8, 2764, 9, 503, 473, 8, 18242, 680, 221, 710, 1844, 288, 574, 911, 849, 370, 314, 5827, 7773, 2863, 1844, 340, 288, 7179, 365, 2741, 315, 314, 2120, 14, 221, 334, 2764, 29, 1081, 12, 1851, 2190, 29, 1081, 680, 267, 1415, 26, 3055, 267, 849, 26, 378, 334, 1180, 2863, 1844, 9, 489, 3434, 26, 267, 1369, 26, 881, 446, 4094, 1482, 314, 3434, 370, 675, 370, 12895, 314, 1950, 370, 288, 314, 3982, 2243, 14, 221, 961, 574, 365, 1202, 370, 12895, 314, 14214, 4676, 14, 288, 982, 314, 574, 365, 440, 2013, 315, 314, 2120, 12, 314, 574, 402, 3734, 288, 1750, 445, 8, 8490, 63, 7278, 63, 11958, 9, 911, 506, 1202, 3140, 14, 267, 1415, 26, 3055, 489, 2505, 26, 267, 1369, 26, 881, 446, 11015, 314, 2505, 370, 675, 370, 12895, 314, 1950, 370, 288, 314, 3982, 2243, 14, 221, 961, 365, 282, 2863, 1423, 1202, 367, 5053, 288, 7773, 83, 14, 982, 314, 574, 365, 440, 2013, 315, 314, 2120, 12, 314, 288, 574, 402, 3734, 1750, 445, 8, 8490, 63, 7278, 63, 9032, 9, 911, 506, 1202, 3140, 14, 267, 1415, 26, 3055, 267, 849, 26, 2973, 489, 8635, 63, 21856, 26, 267, 1369, 26, 881, 446, 11015, 314, 12027, 790, 370, 675, 370, 12895, 314, 1950, 370, 288, 314, 3982, 2243, 14, 221, 961, 1423, 365, 1202, 367, 314, 473, 8, 2764, 9, 288, 7773, 14, 982, 314, 574, 365, 440, 2013, 315, 314, 2120, 12, 314, 288, 574, 402, 3734, 1750, 445, 8, 8490, 63, 7278, 63, 13716, 63, 3078, 3817, 9, 911, 506, 1202, 3140, 14, 267, 1415, 26, 3055, 489, 7773, 26, 267, 1369, 26, 881, 446, 4094, 1482, 314, 7773, 1950, 370, 675, 1380, 18170, 370, 314, 288, 3982, 2243, 14, 221, 710, 7773, 1423, 5171, 20170, 370, 314, 288, 2243, 1806, 5053, 334, 5510, 680, 267, 1415, 26, 2549, 267, 849, 26, 5053, 199, 199, 624, 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 ]
[ 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, 421, 199, 533, 5673, 3768, 11080, 8, 785, 304, 339, 327, 9739, 1584, 3794, 7956, 272, 29970, 2594, 275, 408, 199, 1419, 26, 523, 5022, 26, 272, 1369, 26, 489, 446, 437, 1211, 909, 3035, 1950, 2436, 14, 272, 849, 26, 2973, 272, 26265, 26, 489, 1591, 26, 267, 1369, 26, 881, 446, 11015, 314, 10237, 1591, 536, 503, 2287, 367, 18170, 370, 314, 3982, 288, 2243, 1806, 314, 2013, 7773, 14, 221, 710, 574, 402, 1591, 365, 1202, 465, 288, 314, 5724, 2287, 367, 314, 7773, 14, 267, 1415, 26, 2549, 489, 1844, 26, 267, 1369, 26, 881, 446, 11015, 314, 1844, 370, 675, 1380, 10015, 314, 1950, 370, 314, 3982, 288, 2243, 14, 221, 961, 574, 12966, 370, 1902, 473, 8, 2764, 9, 503, 473, 8, 18242, 680, 221, 710, 1844, 288, 574, 911, 849, 370, 314, 5827, 7773, 2863, 1844, 340, 288, 7179, 365, 2741, 315, 314, 2120, 14, 221, 334, 2764, 29, 1081, 12, 1851, 2190, 29, 1081, 680, 267, 1415, 26, 3055, 267, 849, 26, 378, 334, 1180, 2863, 1844, 9, 489, 3434, 26, 267, 1369, 26, 881, 446, 4094, 1482, 314, 3434, 370, 675, 370, 12895, 314, 1950, 370, 288, 314, 3982, 2243, 14, 221, 961, 574, 365, 1202, 370, 12895, 314, 14214, 4676, 14, 288, 982, 314, 574, 365, 440, 2013, 315, 314, 2120, 12, 314, 574, 402, 3734, 288, 1750, 445, 8, 8490, 63, 7278, 63, 11958, 9, 911, 506, 1202, 3140, 14, 267, 1415, 26, 3055, 489, 2505, 26, 267, 1369, 26, 881, 446, 11015, 314, 2505, 370, 675, 370, 12895, 314, 1950, 370, 288, 314, 3982, 2243, 14, 221, 961, 365, 282, 2863, 1423, 1202, 367, 5053, 288, 7773, 83, 14, 982, 314, 574, 365, 440, 2013, 315, 314, 2120, 12, 314, 288, 574, 402, 3734, 1750, 445, 8, 8490, 63, 7278, 63, 9032, 9, 911, 506, 1202, 3140, 14, 267, 1415, 26, 3055, 267, 849, 26, 2973, 489, 8635, 63, 21856, 26, 267, 1369, 26, 881, 446, 11015, 314, 12027, 790, 370, 675, 370, 12895, 314, 1950, 370, 288, 314, 3982, 2243, 14, 221, 961, 1423, 365, 1202, 367, 314, 473, 8, 2764, 9, 288, 7773, 14, 982, 314, 574, 365, 440, 2013, 315, 314, 2120, 12, 314, 288, 574, 402, 3734, 1750, 445, 8, 8490, 63, 7278, 63, 13716, 63, 3078, 3817, 9, 911, 506, 1202, 3140, 14, 267, 1415, 26, 3055, 489, 7773, 26, 267, 1369, 26, 881, 446, 4094, 1482, 314, 7773, 1950, 370, 675, 1380, 18170, 370, 314, 288, 3982, 2243, 14, 221, 710, 7773, 1423, 5171, 20170, 370, 314, 288, 2243, 1806, 5053, 334, 5510, 680, 267, 1415, 26, 2549, 267, 849, 26, 5053, 199, 199, 624, 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, 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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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 ]
sergeii/swat-julia-admin
fabfile/settings.py
1
3323
# -*- coding: utf-8 -*- import os from unipath import Path from fabric.api import * env.kits = { 'swat4': { 'mod': 'Mod', 'content': 'Content', 'server': 'Swat4DedicatedServer.exe', 'ini': 'Swat4DedicatedServer.ini', }, 'swat4exp': { 'mod': 'ModX', 'content': 'ContentExpansion', 'server': 'Swat4XDedicatedServer.exe', 'ini': 'Swat4XDedicatedServer.ini', }, } env.roledefs = { 'ucc': ['vm-ubuntu-swat'], 'server': ['vm-ubuntu-swat'], } env.paths = { 'here': Path(os.path.dirname(__file__)).parent, } env.paths.update({ 'dist': env.paths['here'].child('dist'), 'compiled': env.paths['here'].child('compiled'), }) env.ucc = { 'path': Path('/home/sergei/swat4ucc/'), 'git': 'git@home:public/swat4#origin/ucc-fake-am', 'packages': ( ('Utils', 'git@home:swat/swat-utils'), ('Julia', 'git@home:swat/swat-julia'), ('JuliaAdmin', 'git@home:swat/swat-julia-admin'), ), } env.server = { 'path': Path('/home/sergei/swat4server/'), 'git': 'git@home:public/swat4#origin/server-bs', 'settings': { '+[Engine.GameEngine]': ( 'ServerActors=Utils.Package', 'ServerActors=Julia.Core', 'ServerActors=JuliaAdmin.Extension', ), # '[AMMod.AMGameMod]': ( # 'DisableMod=True', # ), '[Julia.Core]': ( 'Enabled=True', ), # '[Julia.Cache]': ( # 'CacheTime=10', # ), '[JuliaAdmin.Extension]': ( 'Enabled=True', 'DisallowVIPVoice=True', 'AutoBalance=True', 'AutoBalanceTime=10', 'AutoBalanceAction=', 'AutoBalanceActionLimit=2', 'DisallowWords=f*ck', 'DisallowWordsAction=kick', 'DisallowWordsActionLimit=2', 'DisallowWordsIgnoreAdmins=False', 'DisallowWordsAlertAdmins=True', 'DisallowNames=*fu*ck*', 'DisallowNames=cun*t', 'DisallowNamesAction=forcemute', 'DisallowNamesActionTime=10', 'DisallowNamesActionWarnings=50', 'ProtectNames=|MYT|* pass', 'ProtectNames=serge lol ', 'ProtectNames=foo bar ham ', 'ProtectNamesAction=kickban', 'ProtectNamesActionTime=300', 'ProtectNamesActionWarnings=100', 'ProtectNamesIgnoreAdmins=True', 'FilterText=False', 'FilterTextIgnoreAdmins=True', 'FriendlyFire=(Weapons="TaSEr stun Gun",IgnoreAdmins=True,Alert=True,Action="kick",ActionLimit=2)', 'FriendlyFire=(Weapons="Pepper Spray",Alert=True,ActionLimit=5,Action="forcelesslethal")', 'FriendlyFire=(Weapons="Pepper-ball",Alert=True,ActionLimit=10,Action="forcelesslethal")', 'FriendlyFire=(Weapons="Flashbang,Stinger",Alert=True,ActionLimit=5,Action="forcelesslethal")', 'FriendlyFire=(Weapons="Less Lethal Shotgun",Alert=True,ActionLimit=5,Action="forcenoweapons")', ), } } env.dist = { 'version': '1.1.1', 'extra': ( env.paths['here'].child('LICENSE'), env.paths['here'].child('README.html'), env.paths['here'].child('CHANGES.html'), ) }
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 747, 199, 199, 504, 15439, 515, 492, 6912, 199, 504, 2630, 14, 1246, 492, 627, 421, 199, 1813, 14, 75, 1405, 275, 469, 272, 283, 3519, 292, 20, 356, 469, 267, 283, 1494, 356, 283, 9871, 297, 267, 283, 1317, 356, 283, 2714, 297, 267, 283, 1000, 356, 283, 10941, 292, 20, 872, 24489, 3120, 14, 5803, 297, 267, 283, 2730, 356, 283, 10941, 292, 20, 872, 24489, 3120, 14, 2730, 297, 272, 1660, 272, 283, 3519, 292, 20, 1474, 356, 469, 267, 283, 1494, 356, 283, 9871, 56, 297, 267, 283, 1317, 356, 283, 2714, 26048, 297, 267, 283, 1000, 356, 283, 10941, 292, 20, 56, 872, 24489, 3120, 14, 5803, 297, 267, 283, 2730, 356, 283, 10941, 292, 20, 56, 872, 24489, 3120, 14, 2730, 297, 272, 1660, 199, 93, 199, 199, 1813, 14, 3756, 8710, 275, 469, 272, 283, 8451, 356, 788, 2611, 13, 21151, 13, 3519, 292, 995, 272, 283, 1000, 356, 788, 2611, 13, 21151, 13, 3519, 292, 995, 199, 93, 199, 199, 1813, 14, 3771, 275, 469, 272, 283, 1681, 356, 6912, 8, 736, 14, 515, 14, 3475, 3460, 493, 363, 4992, 1708, 12, 199, 93, 199, 199, 1813, 14, 3771, 14, 873, 2561, 272, 283, 2686, 356, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 2686, 659, 272, 283, 8427, 356, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 8427, 659, 199, 1552, 199, 199, 1813, 14, 8451, 275, 469, 272, 283, 515, 356, 6912, 2336, 4219, 15, 332, 303, 73, 15, 3519, 292, 20, 8451, 20467, 272, 283, 3187, 356, 283, 3187, 32, 4219, 26, 3455, 15, 3519, 292, 20, 3, 6493, 15, 8451, 13, 3183, 13, 455, 297, 272, 283, 5154, 356, 334, 267, 661, 7535, 297, 283, 3187, 32, 4219, 26, 3519, 292, 15, 3519, 292, 13, 1208, 659, 267, 661, 42, 13987, 65, 297, 283, 3187, 32, 4219, 26, 3519, 292, 15, 3519, 292, 13, 74, 13987, 65, 659, 267, 661, 42, 13987, 65, 4880, 297, 283, 3187, 32, 4219, 26, 3519, 292, 15, 3519, 292, 13, 74, 13987, 65, 13, 2113, 659, 272, 2318, 199, 93, 199, 199, 1813, 14, 1000, 275, 469, 272, 283, 515, 356, 6912, 2336, 4219, 15, 332, 303, 73, 15, 3519, 292, 20, 1000, 20467, 272, 283, 3187, 356, 283, 3187, 32, 4219, 26, 3455, 15, 3519, 292, 20, 3, 6493, 15, 1000, 13, 1533, 297, 272, 283, 1751, 356, 469, 267, 6681, 59, 8524, 14, 11454, 8524, 61, 356, 334, 288, 283, 3120, 12258, 83, 29, 7535, 14, 8599, 297, 288, 283, 3120, 12258, 83, 29, 42, 13987, 65, 14, 5402, 297, 288, 283, 3120, 12258, 83, 29, 42, 13987, 65, 4880, 14, 6382, 297, 267, 2318, 267, 327, 6730, 1156, 9871, 14, 1156, 11454, 9871, 61, 356, 334, 267, 327, 258, 283, 13707, 9871, 29, 549, 297, 267, 327, 2318, 267, 6730, 42, 13987, 65, 14, 5402, 61, 356, 334, 288, 283, 6589, 29, 549, 297, 267, 2318, 267, 327, 6730, 42, 13987, 65, 14, 4437, 61, 356, 334, 267, 327, 258, 283, 4437, 1366, 29, 709, 297, 267, 327, 2318, 267, 6730, 42, 13987, 65, 4880, 14, 6382, 61, 356, 334, 288, 283, 6589, 29, 549, 297, 288, 283, 2825, 3306, 54, 11253, 79, 1885, 29, 549, 297, 288, 283, 3358, 27106, 29, 549, 297, 288, 283, 3358, 27106, 1366, 29, 709, 297, 288, 283, 3358, 27106, 3310, 4009, 288, 283, 3358, 27106, 3310, 8407, 29, 18, 297, 288, 283, 2825, 3306, 23759, 29, 70, 10, 346, 297, 288, 283, 2825, 3306, 23759, 3310, 29, 31257, 297, 288, 283, 2825, 3306, 23759, 3310, 8407, 29, 18, 297, 288, 283, 2825, 3306, 23759, 9495, 4880, 83, 29, 797, 297, 288, 283, 2825, 3306, 23759, 18758, 4880, 83, 29, 549, 297, 288, 283, 2825, 3306, 5866, 29, 10, 13499, 10, 346, 7693, 288, 283, 2825, 3306, 5866, 29, 67, 324, 10, 84, 297, 288, 283, 2825, 3306, 5866, 3310, 29, 3990, 12423, 297, 288, 283, 2825, 3306, 5866, 3310, 1366, 29, 709, 297, 288, 283, 2825, 3306, 5866, 3310, 15921, 29, 1400, 297, 288, 283, 919, 5302, 5866, 26777, 12339, 52, 92, 10, 986, 297, 288, 283, 919, 5302, 5866, 29, 332, 303, 259, 560, 76, 257, 1656, 288, 283, 919, 5302, 5866, 29, 1421, 257, 4681, 257, 24868, 1656, 288, 283, 919, 5302, 5866, 3310, 29, 31257, 13206, 297, 288, 283, 919, 5302, 5866, 3310, 1366, 29, 5863, 297, 288, 283, 919, 5302, 5866, 3310, 15921, 29, 1960, 297, 288, 283, 919, 5302, 5866, 9495, 4880, 83, 29, 549, 297, 288, 283, 4131, 1872, 29, 797, 297, 288, 283, 4131, 1872, 9495, 4880, 83, 29, 549, 297, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 22620, 51, 539, 410, 324, 598, 324, 401, 9495, 4880, 83, 29, 549, 12, 18758, 29, 549, 12, 3310, 628, 31257, 401, 3310, 8407, 29, 18, 3196, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 48, 1545, 529, 8360, 803, 401, 18758, 29, 549, 12, 3310, 8407, 29, 21, 12, 3310, 628, 3990, 2003, 274, 273, 279, 30901, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 48, 1545, 529, 13, 8571, 401, 18758, 29, 549, 12, 3310, 8407, 29, 709, 12, 3310, 628, 3990, 2003, 274, 273, 279, 30901, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 29189, 66, 621, 12, 933, 7886, 401, 18758, 29, 549, 12, 3310, 8407, 29, 21, 12, 3310, 628, 3990, 2003, 274, 273, 279, 30901, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 10958, 7005, 273, 279, 5244, 357, 17924, 401, 18758, 29, 549, 12, 3310, 8407, 29, 21, 12, 3310, 628, 509, 2497, 583, 69, 439, 4654, 30901, 267, 2318, 272, 789, 199, 93, 199, 199, 1813, 14, 2686, 275, 469, 272, 283, 1023, 356, 283, 17, 14, 17, 14, 17, 297, 272, 283, 2911, 356, 334, 267, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 3961, 659, 267, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 18195, 14, 1360, 659, 267, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 17858, 654, 14, 1360, 659, 272, 776, 199, 93, 199, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 747, 199, 199, 504, 15439, 515, 492, 6912, 199, 504, 2630, 14, 1246, 492, 627, 421, 199, 1813, 14, 75, 1405, 275, 469, 272, 283, 3519, 292, 20, 356, 469, 267, 283, 1494, 356, 283, 9871, 297, 267, 283, 1317, 356, 283, 2714, 297, 267, 283, 1000, 356, 283, 10941, 292, 20, 872, 24489, 3120, 14, 5803, 297, 267, 283, 2730, 356, 283, 10941, 292, 20, 872, 24489, 3120, 14, 2730, 297, 272, 1660, 272, 283, 3519, 292, 20, 1474, 356, 469, 267, 283, 1494, 356, 283, 9871, 56, 297, 267, 283, 1317, 356, 283, 2714, 26048, 297, 267, 283, 1000, 356, 283, 10941, 292, 20, 56, 872, 24489, 3120, 14, 5803, 297, 267, 283, 2730, 356, 283, 10941, 292, 20, 56, 872, 24489, 3120, 14, 2730, 297, 272, 1660, 199, 93, 199, 199, 1813, 14, 3756, 8710, 275, 469, 272, 283, 8451, 356, 788, 2611, 13, 21151, 13, 3519, 292, 995, 272, 283, 1000, 356, 788, 2611, 13, 21151, 13, 3519, 292, 995, 199, 93, 199, 199, 1813, 14, 3771, 275, 469, 272, 283, 1681, 356, 6912, 8, 736, 14, 515, 14, 3475, 3460, 493, 363, 4992, 1708, 12, 199, 93, 199, 199, 1813, 14, 3771, 14, 873, 2561, 272, 283, 2686, 356, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 2686, 659, 272, 283, 8427, 356, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 8427, 659, 199, 1552, 199, 199, 1813, 14, 8451, 275, 469, 272, 283, 515, 356, 6912, 2336, 4219, 15, 332, 303, 73, 15, 3519, 292, 20, 8451, 20467, 272, 283, 3187, 356, 283, 3187, 32, 4219, 26, 3455, 15, 3519, 292, 20, 3, 6493, 15, 8451, 13, 3183, 13, 455, 297, 272, 283, 5154, 356, 334, 267, 661, 7535, 297, 283, 3187, 32, 4219, 26, 3519, 292, 15, 3519, 292, 13, 1208, 659, 267, 661, 42, 13987, 65, 297, 283, 3187, 32, 4219, 26, 3519, 292, 15, 3519, 292, 13, 74, 13987, 65, 659, 267, 661, 42, 13987, 65, 4880, 297, 283, 3187, 32, 4219, 26, 3519, 292, 15, 3519, 292, 13, 74, 13987, 65, 13, 2113, 659, 272, 2318, 199, 93, 199, 199, 1813, 14, 1000, 275, 469, 272, 283, 515, 356, 6912, 2336, 4219, 15, 332, 303, 73, 15, 3519, 292, 20, 1000, 20467, 272, 283, 3187, 356, 283, 3187, 32, 4219, 26, 3455, 15, 3519, 292, 20, 3, 6493, 15, 1000, 13, 1533, 297, 272, 283, 1751, 356, 469, 267, 6681, 59, 8524, 14, 11454, 8524, 61, 356, 334, 288, 283, 3120, 12258, 83, 29, 7535, 14, 8599, 297, 288, 283, 3120, 12258, 83, 29, 42, 13987, 65, 14, 5402, 297, 288, 283, 3120, 12258, 83, 29, 42, 13987, 65, 4880, 14, 6382, 297, 267, 2318, 267, 327, 6730, 1156, 9871, 14, 1156, 11454, 9871, 61, 356, 334, 267, 327, 258, 283, 13707, 9871, 29, 549, 297, 267, 327, 2318, 267, 6730, 42, 13987, 65, 14, 5402, 61, 356, 334, 288, 283, 6589, 29, 549, 297, 267, 2318, 267, 327, 6730, 42, 13987, 65, 14, 4437, 61, 356, 334, 267, 327, 258, 283, 4437, 1366, 29, 709, 297, 267, 327, 2318, 267, 6730, 42, 13987, 65, 4880, 14, 6382, 61, 356, 334, 288, 283, 6589, 29, 549, 297, 288, 283, 2825, 3306, 54, 11253, 79, 1885, 29, 549, 297, 288, 283, 3358, 27106, 29, 549, 297, 288, 283, 3358, 27106, 1366, 29, 709, 297, 288, 283, 3358, 27106, 3310, 4009, 288, 283, 3358, 27106, 3310, 8407, 29, 18, 297, 288, 283, 2825, 3306, 23759, 29, 70, 10, 346, 297, 288, 283, 2825, 3306, 23759, 3310, 29, 31257, 297, 288, 283, 2825, 3306, 23759, 3310, 8407, 29, 18, 297, 288, 283, 2825, 3306, 23759, 9495, 4880, 83, 29, 797, 297, 288, 283, 2825, 3306, 23759, 18758, 4880, 83, 29, 549, 297, 288, 283, 2825, 3306, 5866, 29, 10, 13499, 10, 346, 7693, 288, 283, 2825, 3306, 5866, 29, 67, 324, 10, 84, 297, 288, 283, 2825, 3306, 5866, 3310, 29, 3990, 12423, 297, 288, 283, 2825, 3306, 5866, 3310, 1366, 29, 709, 297, 288, 283, 2825, 3306, 5866, 3310, 15921, 29, 1400, 297, 288, 283, 919, 5302, 5866, 26777, 12339, 52, 92, 10, 986, 297, 288, 283, 919, 5302, 5866, 29, 332, 303, 259, 560, 76, 257, 1656, 288, 283, 919, 5302, 5866, 29, 1421, 257, 4681, 257, 24868, 1656, 288, 283, 919, 5302, 5866, 3310, 29, 31257, 13206, 297, 288, 283, 919, 5302, 5866, 3310, 1366, 29, 5863, 297, 288, 283, 919, 5302, 5866, 3310, 15921, 29, 1960, 297, 288, 283, 919, 5302, 5866, 9495, 4880, 83, 29, 549, 297, 288, 283, 4131, 1872, 29, 797, 297, 288, 283, 4131, 1872, 9495, 4880, 83, 29, 549, 297, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 22620, 51, 539, 410, 324, 598, 324, 401, 9495, 4880, 83, 29, 549, 12, 18758, 29, 549, 12, 3310, 628, 31257, 401, 3310, 8407, 29, 18, 3196, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 48, 1545, 529, 8360, 803, 401, 18758, 29, 549, 12, 3310, 8407, 29, 21, 12, 3310, 628, 3990, 2003, 274, 273, 279, 30901, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 48, 1545, 529, 13, 8571, 401, 18758, 29, 549, 12, 3310, 8407, 29, 709, 12, 3310, 628, 3990, 2003, 274, 273, 279, 30901, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 29189, 66, 621, 12, 933, 7886, 401, 18758, 29, 549, 12, 3310, 8407, 29, 21, 12, 3310, 628, 3990, 2003, 274, 273, 279, 30901, 288, 283, 38, 11974, 13081, 2687, 6004, 439, 4654, 628, 10958, 7005, 273, 279, 5244, 357, 17924, 401, 18758, 29, 549, 12, 3310, 8407, 29, 21, 12, 3310, 628, 509, 2497, 583, 69, 439, 4654, 30901, 267, 2318, 272, 789, 199, 93, 199, 199, 1813, 14, 2686, 275, 469, 272, 283, 1023, 356, 283, 17, 14, 17, 14, 17, 297, 272, 283, 2911, 356, 334, 267, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 3961, 659, 267, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 18195, 14, 1360, 659, 267, 2589, 14, 3771, 459, 1681, 2278, 1739, 360, 17858, 654, 14, 1360, 659, 272, 776, 199, 93, 199, 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,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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, 0, 0, 0 ]
geekboxzone/lollipop_external_chromium_org_tools_grit
grit/tool/transl2tc.py
62
10859
#!/usr/bin/env python # Copyright (c) 2012 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. '''The 'grit transl2tc' tool. ''' from grit import grd_reader from grit import util from grit.tool import interface from grit.tool import rc2grd from grit.extern import tclib class TranslationToTc(interface.Tool): '''A tool for importing existing translations in RC format into the Translation Console. Usage: grit -i GRD transl2tc [-l LIMITS] [RCOPTS] SOURCE_RC TRANSLATED_RC OUT_FILE The tool needs a "source" RC file, i.e. in English, and an RC file that is a translation of precisely the source RC file (not of an older or newer version). The tool also requires you to provide a .grd file (input file) e.g. using the -i global option or the GRIT_INPUT environment variable. The tool uses information from your .grd file to correct placeholder names in the translations and ensure that only translatable items and translations still being used are output. This tool will accept all the same RCOPTS as the 'grit rc2grd' tool. To get a list of these options, run 'grit help rc2grd'. Additionally, you can use the -l option (which must be the first option to the tool) to specify a file containing a list of message IDs to which output should be limited. This is only useful if you are limiting the output to your XMB files using the 'grit xmb' tool's -l option. See 'grit help xmb' for how to generate a file containing a list of the message IDs in an XMB file. The tool will scan through both of the RC files as well as any HTML files they refer to, and match together the source messages and translated messages. It will output a file (OUTPUT_FILE) you can import directly into the TC using the Bulk Translation Upload tool. ''' def ShortDescription(self): return 'Import existing translations in RC format into the TC' def Setup(self, globopt, args): '''Sets the instance up for use. ''' self.SetOptions(globopt) self.rc2grd = rc2grd.Rc2Grd() self.rc2grd.SetOptions(globopt) self.limits = None if len(args) and args[0] == '-l': self.limits = util.ReadFile(args[1], util.RAW_TEXT).split('\n') args = args[2:] return self.rc2grd.ParseOptions(args) def Run(self, globopt, args): args = self.Setup(globopt, args) if len(args) != 3: self.Out('This tool takes exactly three arguments:\n' ' 1. The path to the original RC file\n' ' 2. The path to the translated RC file\n' ' 3. The output file path.\n') return 2 grd = grd_reader.Parse(self.o.input, debug=self.o.extra_verbose) grd.RunGatherers() source_rc = util.ReadFile(args[0], self.rc2grd.input_encoding) transl_rc = util.ReadFile(args[1], self.rc2grd.input_encoding) translations = self.ExtractTranslations(grd, source_rc, args[0], transl_rc, args[1]) with util.WrapOutputStream(open(args[2], 'w')) as output_file: self.WriteTranslations(output_file, translations.items()) self.Out('Wrote output file %s' % args[2]) def ExtractTranslations(self, current_grd, source_rc, source_path, transl_rc, transl_path): '''Extracts translations from the translated RC file, matching them with translations in the source RC file to calculate their ID, and correcting placeholders, limiting output to translateables, etc. using the supplied .grd file which is the current .grd file for your project. If this object's 'limits' attribute is not None but a list, the output of this function will be further limited to include only messages that have message IDs in the 'limits' list. Args: current_grd: grit.node.base.Node child, that has had RunGatherers() run on it source_rc: Complete text of source RC file source_path: Path to the source RC file transl_rc: Complete text of translated RC file transl_path: Path to the translated RC file Return: { id1 : text1, '12345678' : 'Hello USERNAME, howzit?' } ''' source_grd = self.rc2grd.Process(source_rc, source_path) self.VerboseOut('Read %s into GRIT format, running gatherers.\n' % source_path) source_grd.SetOutputLanguage(current_grd.output_language) source_grd.SetDefines(current_grd.defines) source_grd.RunGatherers(debug=self.o.extra_verbose) transl_grd = self.rc2grd.Process(transl_rc, transl_path) transl_grd.SetOutputLanguage(current_grd.output_language) transl_grd.SetDefines(current_grd.defines) self.VerboseOut('Read %s into GRIT format, running gatherers.\n' % transl_path) transl_grd.RunGatherers(debug=self.o.extra_verbose) self.VerboseOut('Done running gatherers for %s.\n' % transl_path) # Proceed to create a map from ID to translation, getting the ID from the # source GRD and the translation from the translated GRD. id2transl = {} for source_node in source_grd: source_cliques = source_node.GetCliques() if not len(source_cliques): continue assert 'name' in source_node.attrs, 'All nodes with cliques should have an ID' node_id = source_node.attrs['name'] self.ExtraVerboseOut('Processing node %s\n' % node_id) transl_node = transl_grd.GetNodeById(node_id) if transl_node: transl_cliques = transl_node.GetCliques() if not len(transl_cliques) == len(source_cliques): self.Out( 'Warning: Translation for %s has wrong # of cliques, skipping.\n' % node_id) continue else: self.Out('Warning: No translation for %s, skipping.\n' % node_id) continue if source_node.name == 'message': # Fixup placeholders as well as possible based on information from # the current .grd file if they are 'TODO_XXXX' placeholders. We need # to fixup placeholders in the translated message so that it looks right # and we also need to fixup placeholders in the source message so that # its calculated ID will match the current message. current_node = current_grd.GetNodeById(node_id) if current_node: assert len(source_cliques) == len(current_node.GetCliques()) == 1 source_msg = source_cliques[0].GetMessage() current_msg = current_node.GetCliques()[0].GetMessage() # Only do this for messages whose source version has not changed. if (source_msg.GetRealContent() != current_msg.GetRealContent()): self.VerboseOut('Info: Message %s has changed; skipping\n' % node_id) else: transl_msg = transl_cliques[0].GetMessage() transl_content = transl_msg.GetContent() current_content = current_msg.GetContent() source_content = source_msg.GetContent() ok_to_fixup = True if (len(transl_content) != len(current_content)): # message structure of translation is different, don't try fixup ok_to_fixup = False if ok_to_fixup: for ix in range(len(transl_content)): if isinstance(transl_content[ix], tclib.Placeholder): if not isinstance(current_content[ix], tclib.Placeholder): ok_to_fixup = False # structure has changed break if (transl_content[ix].GetOriginal() != current_content[ix].GetOriginal()): ok_to_fixup = False # placeholders have likely been reordered break else: # translated part is not a placeholder but a string if isinstance(current_content[ix], tclib.Placeholder): ok_to_fixup = False # placeholders have likely been reordered break if not ok_to_fixup: self.VerboseOut( 'Info: Structure of message %s has changed; skipping.\n' % node_id) else: def Fixup(content, ix): if (isinstance(content[ix], tclib.Placeholder) and content[ix].GetPresentation().startswith('TODO_')): assert isinstance(current_content[ix], tclib.Placeholder) # Get the placeholder ID and example from the current message content[ix] = current_content[ix] for ix in range(len(transl_content)): Fixup(transl_content, ix) Fixup(source_content, ix) # Only put each translation once into the map. Warn if translations # for the same message are different. for ix in range(len(transl_cliques)): source_msg = source_cliques[ix].GetMessage() source_msg.GenerateId() # needed to refresh ID based on new placeholders message_id = source_msg.GetId() translated_content = transl_cliques[ix].GetMessage().GetPresentableContent() if message_id in id2transl: existing_translation = id2transl[message_id] if existing_translation != translated_content: original_text = source_cliques[ix].GetMessage().GetPresentableContent() self.Out('Warning: Two different translations for "%s":\n' ' Translation 1: "%s"\n' ' Translation 2: "%s"\n' % (original_text, existing_translation, translated_content)) else: id2transl[message_id] = translated_content # Remove translations for messages that do not occur in the current .grd # or have been marked as not translateable, or do not occur in the 'limits' # list (if it has been set). current_message_ids = current_grd.UberClique().AllMessageIds() for message_id in id2transl.keys(): if (message_id not in current_message_ids or not current_grd.UberClique().BestClique(message_id).IsTranslateable() or (self.limits and message_id not in self.limits)): del id2transl[message_id] return id2transl @staticmethod def WriteTranslations(output_file, translations): '''Writes the provided list of translations to the provided output file in the format used by the TC's Bulk Translation Upload tool. The file must be UTF-8 encoded. Args: output_file: util.WrapOutputStream(open('bingo.out', 'w')) translations: [ [id1, text1], ['12345678', 'Hello USERNAME, howzit?'] ] Return: None ''' for id, text in translations: text = text.replace('<', '&lt;').replace('>', '&gt;') output_file.write(id) output_file.write(' ') output_file.write(text) output_file.write('\n')
bsd-2-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 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, 2344, 1918, 283, 7928, 84, 1752, 76, 18, 3641, 7, 4744, 14, 199, 2344, 421, 199, 504, 486, 11133, 492, 486, 6883, 63, 5503, 199, 504, 486, 11133, 492, 4884, 199, 504, 486, 11133, 14, 3557, 492, 3217, 199, 504, 486, 11133, 14, 3557, 492, 4819, 18, 2587, 68, 199, 199, 504, 486, 11133, 14, 18587, 492, 14415, 773, 421, 199, 533, 25224, 1378, 52, 67, 8, 3266, 14, 5157, 304, 523, 1449, 33, 4744, 367, 16306, 3411, 15547, 315, 29256, 1475, 1901, 314, 199, 18483, 19809, 14, 199, 199, 7692, 26, 199, 199, 7928, 84, 446, 73, 598, 15543, 1752, 76, 18, 3641, 5243, 76, 5138, 51, 61, 359, 50, 1439, 4189, 51, 61, 25470, 63, 8205, 18634, 4929, 6989, 63, 8205, 5738, 63, 3817, 199, 199, 1918, 4744, 4839, 282, 298, 1365, 2, 29256, 570, 12, 284, 14, 69, 14, 315, 20144, 12, 436, 376, 29256, 570, 626, 365, 282, 199, 6893, 402, 28334, 590, 314, 1350, 29256, 570, 334, 1397, 402, 376, 12731, 503, 15666, 1015, 680, 199, 199, 1918, 4744, 2597, 5074, 1265, 370, 5647, 282, 1275, 2587, 68, 570, 334, 1210, 570, 9, 325, 14, 71, 14, 1808, 314, 199, 13, 73, 2288, 945, 503, 314, 21772, 649, 63, 7321, 3734, 1750, 14, 221, 710, 4744, 4440, 199, 11697, 687, 2195, 1275, 2587, 68, 570, 370, 3211, 10069, 1561, 315, 314, 199, 13982, 436, 4868, 626, 1454, 1752, 25099, 2974, 436, 15547, 5139, 199, 1235, 316, 1202, 787, 1072, 14, 199, 199, 2765, 4744, 911, 4729, 1006, 314, 2011, 820, 1439, 4189, 51, 465, 314, 283, 7928, 84, 4819, 18, 2587, 68, 7, 4744, 14, 221, 4005, 664, 199, 65, 769, 402, 3520, 1511, 12, 1255, 283, 7928, 84, 1720, 4819, 18, 2587, 68, 1370, 199, 199, 2767, 22565, 12, 1265, 883, 675, 314, 446, 76, 945, 334, 6777, 1471, 506, 314, 1642, 945, 370, 314, 199, 3557, 9, 370, 4165, 282, 570, 3035, 282, 769, 402, 1245, 11449, 370, 1314, 1072, 1077, 199, 1235, 13988, 14, 221, 961, 365, 1454, 2997, 340, 1265, 787, 2304, 316, 314, 1072, 370, 2195, 1323, 4567, 199, 1725, 1808, 314, 283, 7928, 84, 671, 887, 7, 4744, 1159, 446, 76, 945, 14, 221, 1666, 283, 7928, 84, 1720, 671, 887, 7, 367, 4212, 370, 199, 4208, 282, 570, 3035, 282, 769, 402, 314, 1245, 11449, 315, 376, 1323, 4567, 570, 14, 199, 199, 1918, 4744, 911, 8000, 4012, 3865, 402, 314, 29256, 1584, 465, 5521, 465, 1263, 4163, 1584, 2985, 199, 21928, 370, 12, 436, 1336, 10451, 314, 1350, 3788, 436, 14598, 3788, 14, 221, 2779, 199, 14117, 1072, 282, 570, 334, 8414, 63, 3817, 9, 1265, 883, 492, 5370, 1901, 314, 377, 35, 1808, 314, 199, 26033, 25224, 19149, 4744, 14, 199, 2344, 819, 347, 20124, 5831, 8, 277, 304, 272, 372, 283, 6295, 3411, 15547, 315, 29256, 1475, 1901, 314, 377, 35, 7, 819, 347, 12439, 8, 277, 12, 5739, 2992, 12, 1249, 304, 272, 1449, 9899, 314, 1256, 1536, 367, 675, 14, 272, 1449, 272, 291, 14, 1084, 4558, 8, 6463, 2992, 9, 272, 291, 14, 1195, 18, 2587, 68, 275, 4819, 18, 2587, 68, 14, 19360, 18, 39, 6883, 342, 272, 291, 14, 1195, 18, 2587, 68, 14, 1084, 4558, 8, 6463, 2992, 9, 272, 291, 14, 9368, 275, 488, 272, 340, 822, 8, 589, 9, 436, 1249, 59, 16, 61, 508, 2475, 76, 356, 489, 291, 14, 9368, 275, 4884, 14, 32356, 8, 589, 59, 17, 467, 4884, 14, 4307, 63, 3876, 680, 1294, 2258, 78, 358, 489, 1249, 275, 1249, 59, 18, 2938, 272, 372, 291, 14, 1195, 18, 2587, 68, 14, 4003, 4558, 8, 589, 9, 819, 347, 3378, 8, 277, 12, 5739, 2992, 12, 1249, 304, 272, 1249, 275, 291, 14, 8555, 8, 6463, 2992, 12, 1249, 9, 339, 340, 822, 8, 589, 9, 1137, 650, 26, 489, 291, 14, 2204, 360, 2765, 4744, 6181, 8840, 7795, 2368, 3427, 78, 7, 1467, 283, 221, 413, 14, 710, 931, 370, 314, 3379, 29256, 570, 60, 78, 7, 1467, 283, 221, 499, 14, 710, 931, 370, 314, 14598, 29256, 570, 60, 78, 7, 1467, 283, 221, 650, 14, 710, 1072, 570, 931, 3134, 78, 358, 489, 372, 499, 339, 486, 6883, 275, 486, 6883, 63, 5503, 14, 4003, 8, 277, 14, 79, 14, 1210, 12, 3105, 29, 277, 14, 79, 14, 2911, 63, 3832, 9, 272, 486, 6883, 14, 2540, 17295, 16990, 2393, 342, 339, 1350, 63, 1195, 275, 4884, 14, 32356, 8, 589, 59, 16, 467, 291, 14, 1195, 18, 2587, 68, 14, 1210, 63, 2991, 9, 272, 1752, 76, 63, 1195, 275, 4884, 14, 32356, 8, 589, 59, 17, 467, 291, 14, 1195, 18, 2587, 68, 14, 1210, 63, 2991, 9, 272, 15547, 275, 291, 14, 12147, 3188, 6011, 8, 2587, 68, 12, 4490, 1350, 63, 1195, 12, 1249, 59, 16, 467, 4490, 1752, 76, 63, 1195, 12, 1249, 59, 17, 566, 339, 543, 4884, 14, 15991, 10390, 8, 1490, 8, 589, 59, 18, 467, 283, 87, 1333, 465, 1072, 63, 493, 26, 489, 291, 14, 3534, 3188, 6011, 8, 1199, 63, 493, 12, 15547, 14, 1744, 1012, 339, 291, 14, 2204, 360, 55, 22665, 1072, 570, 450, 83, 7, 450, 1249, 59, 18, 566, 819, 347, 12892, 3188, 6011, 8, 277, 12, 1453, 63, 2587, 68, 12, 1350, 63, 1195, 12, 1350, 63, 515, 12, 6163, 1752, 76, 63, 1195, 12, 1752, 76, 63, 515, 304, 272, 1449, 12147, 83, 15547, 687, 314, 14598, 29256, 570, 12, 4877, 3062, 543, 272, 15547, 315, 314, 1350, 29256, 570, 370, 8671, 3932, 2870, 12, 436, 3211, 316, 272, 24987, 12, 2304, 316, 1072, 370, 9028, 5921, 12, 5423, 14, 1808, 314, 6841, 272, 1275, 2587, 68, 570, 1314, 365, 314, 1453, 1275, 2587, 68, 570, 367, 2195, 2199, 14, 339, 982, 642, 909, 1159, 283, 9368, 7, 2225, 365, 440, 488, 1325, 282, 769, 12 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 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, 2344, 1918, 283, 7928, 84, 1752, 76, 18, 3641, 7, 4744, 14, 199, 2344, 421, 199, 504, 486, 11133, 492, 486, 6883, 63, 5503, 199, 504, 486, 11133, 492, 4884, 199, 504, 486, 11133, 14, 3557, 492, 3217, 199, 504, 486, 11133, 14, 3557, 492, 4819, 18, 2587, 68, 199, 199, 504, 486, 11133, 14, 18587, 492, 14415, 773, 421, 199, 533, 25224, 1378, 52, 67, 8, 3266, 14, 5157, 304, 523, 1449, 33, 4744, 367, 16306, 3411, 15547, 315, 29256, 1475, 1901, 314, 199, 18483, 19809, 14, 199, 199, 7692, 26, 199, 199, 7928, 84, 446, 73, 598, 15543, 1752, 76, 18, 3641, 5243, 76, 5138, 51, 61, 359, 50, 1439, 4189, 51, 61, 25470, 63, 8205, 18634, 4929, 6989, 63, 8205, 5738, 63, 3817, 199, 199, 1918, 4744, 4839, 282, 298, 1365, 2, 29256, 570, 12, 284, 14, 69, 14, 315, 20144, 12, 436, 376, 29256, 570, 626, 365, 282, 199, 6893, 402, 28334, 590, 314, 1350, 29256, 570, 334, 1397, 402, 376, 12731, 503, 15666, 1015, 680, 199, 199, 1918, 4744, 2597, 5074, 1265, 370, 5647, 282, 1275, 2587, 68, 570, 334, 1210, 570, 9, 325, 14, 71, 14, 1808, 314, 199, 13, 73, 2288, 945, 503, 314, 21772, 649, 63, 7321, 3734, 1750, 14, 221, 710, 4744, 4440, 199, 11697, 687, 2195, 1275, 2587, 68, 570, 370, 3211, 10069, 1561, 315, 314, 199, 13982, 436, 4868, 626, 1454, 1752, 25099, 2974, 436, 15547, 5139, 199, 1235, 316, 1202, 787, 1072, 14, 199, 199, 2765, 4744, 911, 4729, 1006, 314, 2011, 820, 1439, 4189, 51, 465, 314, 283, 7928, 84, 4819, 18, 2587, 68, 7, 4744, 14, 221, 4005, 664, 199, 65, 769, 402, 3520, 1511, 12, 1255, 283, 7928, 84, 1720, 4819, 18, 2587, 68, 1370, 199, 199, 2767, 22565, 12, 1265, 883, 675, 314, 446, 76, 945, 334, 6777, 1471, 506, 314, 1642, 945, 370, 314, 199, 3557, 9, 370, 4165, 282, 570, 3035, 282, 769, 402, 1245, 11449, 370, 1314, 1072, 1077, 199, 1235, 13988, 14, 221, 961, 365, 1454, 2997, 340, 1265, 787, 2304, 316, 314, 1072, 370, 2195, 1323, 4567, 199, 1725, 1808, 314, 283, 7928, 84, 671, 887, 7, 4744, 1159, 446, 76, 945, 14, 221, 1666, 283, 7928, 84, 1720, 671, 887, 7, 367, 4212, 370, 199, 4208, 282, 570, 3035, 282, 769, 402, 314, 1245, 11449, 315, 376, 1323, 4567, 570, 14, 199, 199, 1918, 4744, 911, 8000, 4012, 3865, 402, 314, 29256, 1584, 465, 5521, 465, 1263, 4163, 1584, 2985, 199, 21928, 370, 12, 436, 1336, 10451, 314, 1350, 3788, 436, 14598, 3788, 14, 221, 2779, 199, 14117, 1072, 282, 570, 334, 8414, 63, 3817, 9, 1265, 883, 492, 5370, 1901, 314, 377, 35, 1808, 314, 199, 26033, 25224, 19149, 4744, 14, 199, 2344, 819, 347, 20124, 5831, 8, 277, 304, 272, 372, 283, 6295, 3411, 15547, 315, 29256, 1475, 1901, 314, 377, 35, 7, 819, 347, 12439, 8, 277, 12, 5739, 2992, 12, 1249, 304, 272, 1449, 9899, 314, 1256, 1536, 367, 675, 14, 272, 1449, 272, 291, 14, 1084, 4558, 8, 6463, 2992, 9, 272, 291, 14, 1195, 18, 2587, 68, 275, 4819, 18, 2587, 68, 14, 19360, 18, 39, 6883, 342, 272, 291, 14, 1195, 18, 2587, 68, 14, 1084, 4558, 8, 6463, 2992, 9, 272, 291, 14, 9368, 275, 488, 272, 340, 822, 8, 589, 9, 436, 1249, 59, 16, 61, 508, 2475, 76, 356, 489, 291, 14, 9368, 275, 4884, 14, 32356, 8, 589, 59, 17, 467, 4884, 14, 4307, 63, 3876, 680, 1294, 2258, 78, 358, 489, 1249, 275, 1249, 59, 18, 2938, 272, 372, 291, 14, 1195, 18, 2587, 68, 14, 4003, 4558, 8, 589, 9, 819, 347, 3378, 8, 277, 12, 5739, 2992, 12, 1249, 304, 272, 1249, 275, 291, 14, 8555, 8, 6463, 2992, 12, 1249, 9, 339, 340, 822, 8, 589, 9, 1137, 650, 26, 489, 291, 14, 2204, 360, 2765, 4744, 6181, 8840, 7795, 2368, 3427, 78, 7, 1467, 283, 221, 413, 14, 710, 931, 370, 314, 3379, 29256, 570, 60, 78, 7, 1467, 283, 221, 499, 14, 710, 931, 370, 314, 14598, 29256, 570, 60, 78, 7, 1467, 283, 221, 650, 14, 710, 1072, 570, 931, 3134, 78, 358, 489, 372, 499, 339, 486, 6883, 275, 486, 6883, 63, 5503, 14, 4003, 8, 277, 14, 79, 14, 1210, 12, 3105, 29, 277, 14, 79, 14, 2911, 63, 3832, 9, 272, 486, 6883, 14, 2540, 17295, 16990, 2393, 342, 339, 1350, 63, 1195, 275, 4884, 14, 32356, 8, 589, 59, 16, 467, 291, 14, 1195, 18, 2587, 68, 14, 1210, 63, 2991, 9, 272, 1752, 76, 63, 1195, 275, 4884, 14, 32356, 8, 589, 59, 17, 467, 291, 14, 1195, 18, 2587, 68, 14, 1210, 63, 2991, 9, 272, 15547, 275, 291, 14, 12147, 3188, 6011, 8, 2587, 68, 12, 4490, 1350, 63, 1195, 12, 1249, 59, 16, 467, 4490, 1752, 76, 63, 1195, 12, 1249, 59, 17, 566, 339, 543, 4884, 14, 15991, 10390, 8, 1490, 8, 589, 59, 18, 467, 283, 87, 1333, 465, 1072, 63, 493, 26, 489, 291, 14, 3534, 3188, 6011, 8, 1199, 63, 493, 12, 15547, 14, 1744, 1012, 339, 291, 14, 2204, 360, 55, 22665, 1072, 570, 450, 83, 7, 450, 1249, 59, 18, 566, 819, 347, 12892, 3188, 6011, 8, 277, 12, 1453, 63, 2587, 68, 12, 1350, 63, 1195, 12, 1350, 63, 515, 12, 6163, 1752, 76, 63, 1195, 12, 1752, 76, 63, 515, 304, 272, 1449, 12147, 83, 15547, 687, 314, 14598, 29256, 570, 12, 4877, 3062, 543, 272, 15547, 315, 314, 1350, 29256, 570, 370, 8671, 3932, 2870, 12, 436, 3211, 316, 272, 24987, 12, 2304, 316, 1072, 370, 9028, 5921, 12, 5423, 14, 1808, 314, 6841, 272, 1275, 2587, 68, 570, 1314, 365, 314, 1453, 1275, 2587, 68, 570, 367, 2195, 2199, 14, 339, 982, 642, 909, 1159, 283, 9368, 7, 2225, 365, 440, 488, 1325, 282, 769, 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, 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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 ]
Lekensteyn/buildbot
master/buildbot/test/unit/test_data_steps.py
8
13691
# This file is part of Buildbot. Buildbot 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, version 2. # # 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 General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # Copyright Buildbot Team Members from __future__ import absolute_import from __future__ import print_function from twisted.internet import defer from twisted.internet import reactor from twisted.trial import unittest from buildbot.data import steps from buildbot.test.fake import fakedb from buildbot.test.fake import fakemaster from buildbot.test.util import endpoint from buildbot.test.util import interfaces from buildbot.util import epoch2datetime TIME1 = 2001111 TIME2 = 2002222 TIME3 = 2003333 class StepEndpoint(endpoint.EndpointMixin, unittest.TestCase): endpointClass = steps.StepEndpoint resourceTypeClass = steps.Step def setUp(self): self.setUpEndpoint() self.db.insertTestData([ fakedb.Worker(id=47, name='linux'), fakedb.Builder(id=77), fakedb.Master(id=88), fakedb.Buildset(id=8822), fakedb.BuildRequest(id=82, buildsetid=8822), fakedb.Build(id=30, builderid=77, number=7, masterid=88, buildrequestid=82, workerid=47), fakedb.Step(id=70, number=0, name='one', buildid=30, started_at=TIME1, complete_at=TIME2, results=0), fakedb.Step(id=71, number=1, name='two', buildid=30, started_at=TIME2, complete_at=TIME3, results=2, urls_json='[{"name":"url","url":"http://url"}]'), fakedb.Step(id=72, number=2, name='three', buildid=30, started_at=TIME3, hidden=True), ]) def tearDown(self): self.tearDownEndpoint() @defer.inlineCallbacks def test_get_existing(self): step = yield self.callGet(('steps', 72)) self.validateData(step) self.assertEqual(step, { 'buildid': 30, 'complete': False, 'complete_at': None, 'name': u'three', 'number': 2, 'results': None, 'started_at': epoch2datetime(TIME3), 'state_string': u'', 'stepid': 72, 'urls': [], 'hidden': True}) @defer.inlineCallbacks def test_get_existing_buildid_name(self): step = yield self.callGet(('builds', 30, 'steps', 'two')) self.validateData(step) self.assertEqual(step['stepid'], 71) @defer.inlineCallbacks def test_get_existing_buildid_number(self): step = yield self.callGet(('builds', 30, 'steps', 1)) self.validateData(step) self.assertEqual(step['stepid'], 71) @defer.inlineCallbacks def test_get_existing_builder_name(self): step = yield self.callGet(('builders', 77, 'builds', 7, 'steps', 'two')) self.validateData(step) self.assertEqual(step['stepid'], 71) @defer.inlineCallbacks def test_get_existing_builder_number(self): step = yield self.callGet(('builders', 77, 'builds', 7, 'steps', 1)) self.validateData(step) self.assertEqual(step['stepid'], 71) @defer.inlineCallbacks def test_get_missing(self): step = yield self.callGet(('steps', 9999)) self.assertEqual(step, None) class StepsEndpoint(endpoint.EndpointMixin, unittest.TestCase): endpointClass = steps.StepsEndpoint resourceTypeClass = steps.Step def setUp(self): self.setUpEndpoint() self.db.insertTestData([ fakedb.Worker(id=47, name='linux'), fakedb.Builder(id=77), fakedb.Master(id=88), fakedb.Buildset(id=8822), fakedb.BuildRequest(id=82, buildsetid=8822), fakedb.Build(id=30, builderid=77, number=7, masterid=88, buildrequestid=82, workerid=47), fakedb.Build(id=31, builderid=77, number=8, masterid=88, buildrequestid=82, workerid=47), fakedb.Step(id=70, number=0, name='one', buildid=30, started_at=TIME1, complete_at=TIME2, results=0), fakedb.Step(id=71, number=1, name='two', buildid=30, started_at=TIME2, complete_at=TIME3, results=2, urls_json='[{"name":"url","url":"http://url"}]'), fakedb.Step(id=72, number=2, name='three', buildid=30, started_at=TIME3), fakedb.Step(id=73, number=0, name='otherbuild', buildid=31, started_at=TIME2), ]) def tearDown(self): self.tearDownEndpoint() @defer.inlineCallbacks def test_get_buildid(self): steps = yield self.callGet(('builds', 30, 'steps')) [self.validateData(step) for step in steps] self.assertEqual([s['number'] for s in steps], [0, 1, 2]) @defer.inlineCallbacks def test_get_builder(self): steps = yield self.callGet(('builders', 77, 'builds', 7, 'steps')) [self.validateData(step) for step in steps] self.assertEqual([s['number'] for s in steps], [0, 1, 2]) class Step(interfaces.InterfaceTests, unittest.TestCase): def setUp(self): self.master = fakemaster.make_master(testcase=self, wantMq=True, wantDb=True, wantData=True) self.rtype = steps.Step(self.master) def test_signature_newStep(self): @self.assertArgSpecMatches( self.master.data.updates.addStep, # fake self.rtype.addStep) # real def newStep(self, buildid, name): pass @defer.inlineCallbacks def test_newStep(self): stepid, number, name = yield self.rtype.addStep(buildid=10, name=u'name') msgBody = { 'buildid': 10, 'complete': False, 'complete_at': None, 'name': name, 'number': number, 'results': None, 'started_at': None, 'state_string': u'pending', 'stepid': stepid, 'urls': [], 'hidden': False, } self.master.mq.assertProductions([ (('builds', '10', 'steps', str(stepid), 'new'), msgBody), (('steps', str(stepid), 'new'), msgBody), ]) step = yield self.master.db.steps.getStep(stepid) self.assertEqual(step, { 'buildid': 10, 'complete_at': None, 'id': stepid, 'name': name, 'number': number, 'results': None, 'started_at': None, 'state_string': u'pending', 'urls': [], 'hidden': False, }) @defer.inlineCallbacks def test_fake_newStep(self): self.assertEqual( len((yield self.master.data.updates.addStep(buildid=10, name=u'ten'))), 3) def test_signature_startStep(self): @self.assertArgSpecMatches( self.master.data.updates.startStep, # fake self.rtype.startStep) # real def newStep(self, stepid): pass @defer.inlineCallbacks def test_startStep(self): self.patch(reactor, 'seconds', lambda: TIME1) yield self.master.db.steps.addStep(buildid=10, name=u'ten', state_string=u'pending') yield self.rtype.startStep(stepid=100) msgBody = { 'buildid': 10, 'complete': False, 'complete_at': None, 'name': u'ten', 'number': 0, 'results': None, 'started_at': epoch2datetime(TIME1), 'state_string': u'pending', 'stepid': 100, 'urls': [], 'hidden': False, } self.master.mq.assertProductions([ (('builds', '10', 'steps', str(100), 'started'), msgBody), (('steps', str(100), 'started'), msgBody), ]) step = yield self.master.db.steps.getStep(100) self.assertEqual(step, { 'buildid': 10, 'complete_at': None, 'id': 100, 'name': u'ten', 'number': 0, 'results': None, 'started_at': epoch2datetime(TIME1), 'state_string': u'pending', 'urls': [], 'hidden': False, }) def test_signature_setStepStateString(self): @self.assertArgSpecMatches( self.master.data.updates.setStepStateString, # fake self.rtype.setStepStateString) # real def setStepStateString(self, stepid, state_string): pass @defer.inlineCallbacks def test_setStepStateString(self): yield self.master.db.steps.addStep(buildid=10, name=u'ten', state_string=u'pending') yield self.rtype.setStepStateString(stepid=100, state_string=u'hi') msgBody = { 'buildid': 10, 'complete': False, 'complete_at': None, 'name': u'ten', 'number': 0, 'results': None, 'started_at': None, 'state_string': u'hi', 'stepid': 100, 'urls': [], 'hidden': False, } self.master.mq.assertProductions([ (('builds', '10', 'steps', str(100), 'updated'), msgBody), (('steps', str(100), 'updated'), msgBody), ]) step = yield self.master.db.steps.getStep(100) self.assertEqual(step, { 'buildid': 10, 'complete_at': None, 'id': 100, 'name': u'ten', 'number': 0, 'results': None, 'started_at': None, 'state_string': u'hi', 'urls': [], 'hidden': False, }) def test_signature_finishStep(self): @self.assertArgSpecMatches( self.master.data.updates.finishStep, # fake self.rtype.finishStep) # real def finishStep(self, stepid, results, hidden): pass @defer.inlineCallbacks def test_finishStep(self): yield self.master.db.steps.addStep(buildid=10, name=u'ten', state_string=u'pending') self.patch(reactor, 'seconds', lambda: TIME1) yield self.rtype.startStep(stepid=100) self.patch(reactor, 'seconds', lambda: TIME2) self.master.mq.clearProductions() yield self.rtype.finishStep(stepid=100, results=9, hidden=False) msgBody = { 'buildid': 10, 'complete': True, 'complete_at': epoch2datetime(TIME2), 'name': u'ten', 'number': 0, 'results': 9, 'started_at': epoch2datetime(TIME1), 'state_string': u'pending', 'stepid': 100, 'urls': [], 'hidden': False, } self.master.mq.assertProductions([ (('builds', '10', 'steps', str(100), 'finished'), msgBody), (('steps', str(100), 'finished'), msgBody), ]) step = yield self.master.db.steps.getStep(100) self.assertEqual(step, { 'buildid': 10, 'complete_at': epoch2datetime(TIME2), 'id': 100, 'name': u'ten', 'number': 0, 'results': 9, 'started_at': epoch2datetime(TIME1), 'state_string': u'pending', 'urls': [], 'hidden': False, }) def test_signature_addStepURL(self): @self.assertArgSpecMatches( self.master.data.updates.addStepURL, # fake self.rtype.addStepURL) # real def addStepURL(self, stepid, name, url): pass @defer.inlineCallbacks def test_addStepURL(self): yield self.master.db.steps.addStep(buildid=10, name=u'ten', state_string=u'pending') yield self.rtype.addStepURL(stepid=100, name=u"foo", url=u"bar") msgBody = { 'buildid': 10, 'complete': False, 'complete_at': None, 'name': u'ten', 'number': 0, 'results': None, 'started_at': None, 'state_string': u'pending', 'stepid': 100, 'urls': [{u'name': u'foo', u'url': u'bar'}], 'hidden': False, } self.master.mq.assertProductions([ (('builds', '10', 'steps', str(100), 'updated'), msgBody), (('steps', str(100), 'updated'), msgBody), ]) step = yield self.master.db.steps.getStep(100) self.assertEqual(step, { 'buildid': 10, 'complete_at': None, 'id': 100, 'name': u'ten', 'number': 0, 'results': None, 'started_at': None, 'state_string': u'pending', 'urls': [{u'name': u'foo', u'url': u'bar'}], 'hidden': False, })
gpl-2.0
[ 3, 961, 570, 365, 1777, 402, 6516, 3018, 14, 221, 6516, 3018, 365, 2867, 2032, 26, 1265, 883, 199, 3, 3604, 652, 436, 15, 269, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 199, 3, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 12, 1015, 499, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 2428, 199, 3, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 3169, 503, 3092, 199, 3, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 1696, 1684, 844, 367, 1655, 199, 3, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 3180, 543, 199, 3, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 8026, 199, 3, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 11315, 13, 10067, 8217, 14, 199, 3, 199, 3, 1898, 6516, 3018, 11682, 14409, 83, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 7390, 14, 4901, 492, 10133, 199, 504, 7390, 14, 4901, 492, 9655, 199, 504, 7390, 14, 14443, 492, 2882, 199, 199, 504, 21306, 14, 576, 492, 7124, 199, 504, 21306, 14, 396, 14, 3183, 492, 289, 16702, 66, 199, 504, 21306, 14, 396, 14, 3183, 492, 4026, 4133, 199, 504, 21306, 14, 396, 14, 1974, 492, 6037, 199, 504, 21306, 14, 396, 14, 1974, 492, 8386, 199, 504, 21306, 14, 1974, 492, 9463, 18, 2083, 199, 199, 4961, 17, 275, 1926, 6984, 199, 4961, 18, 275, 1926, 9993, 199, 4961, 19, 275, 1926, 6772, 421, 199, 533, 13382, 11442, 8, 6520, 14, 11442, 4256, 12, 2882, 14, 1746, 304, 339, 6037, 2543, 275, 7124, 14, 7801, 11442, 272, 2073, 804, 2543, 275, 7124, 14, 7801, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 5996, 11442, 342, 267, 291, 14, 697, 14, 3176, 16550, 779, 288, 289, 16702, 66, 14, 12678, 8, 344, 29, 2417, 12, 536, 534, 5135, 659, 288, 289, 16702, 66, 14, 6437, 8, 344, 29, 1138, 395, 288, 289, 16702, 66, 14, 12288, 8, 344, 29, 1299, 395, 288, 289, 16702, 66, 14, 3425, 409, 8, 344, 29, 1299, 1081, 395, 288, 289, 16702, 66, 14, 3425, 2017, 8, 344, 29, 2564, 12, 1900, 261, 5700, 29, 1299, 1081, 395, 288, 289, 16702, 66, 14, 3425, 8, 344, 29, 1216, 12, 1032, 24446, 1677, 29, 1138, 12, 1329, 29, 23, 12, 333, 9209, 1677, 29, 1299, 12, 586, 1900, 1069, 344, 29, 2564, 12, 7239, 344, 29, 2417, 395, 288, 289, 16702, 66, 14, 7801, 8, 344, 29, 2760, 12, 1329, 29, 16, 12, 536, 534, 368, 297, 1032, 382, 14887, 29, 1216, 12, 717, 8239, 63, 292, 29, 4961, 17, 12, 4890, 63, 292, 29, 4961, 18, 12, 2058, 29, 16, 395, 288, 289, 16702, 66, 14, 7801, 8, 344, 29, 3172, 12, 1329, 29, 17, 12, 536, 534, 5601, 297, 1032, 382, 14887, 29, 1216, 12, 717, 8239, 63, 292, 29, 4961, 18, 12, 4890, 63, 292, 29, 4961, 19, 12, 2058, 29, 18, 12, 717, 8187, 63, 1001, 30845, 6641, 354, 5122, 633, 2266, 633, 5122, 1014, 921, 633, 3570, 26987, 288, 289, 16702, 66, 14, 7801, 8, 344, 29, 2819, 12, 1329, 29, 18, 12, 536, 534, 10480, 297, 1032, 382, 14887, 29, 1216, 12, 717, 8239, 63, 292, 29, 4961, 19, 12, 8752, 29, 549, 395, 267, 4794, 339, 347, 6766, 8, 277, 304, 267, 291, 14, 12336, 11442, 342, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 5895, 297, 15323, 430, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 12, 469, 288, 283, 464, 382, 14887, 356, 4233, 12, 288, 283, 4883, 356, 756, 12, 288, 283, 4883, 63, 292, 356, 488, 12, 288, 283, 354, 356, 399, 1133, 72, 850, 297, 288, 283, 1955, 356, 499, 12, 288, 283, 2604, 356, 488, 12, 288, 283, 8924, 63, 292, 356, 9463, 18, 2083, 8, 4961, 19, 395, 288, 283, 929, 63, 875, 356, 399, 6448, 288, 283, 2926, 344, 356, 15323, 12, 288, 283, 3603, 356, 990, 288, 283, 5642, 356, 715, 1552, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 63, 464, 382, 14887, 63, 354, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 10838, 297, 4233, 12, 283, 5895, 297, 283, 5601, 1333, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 459, 2926, 344, 995, 17245, 9, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 63, 464, 382, 14887, 63, 1955, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 10838, 297, 4233, 12, 283, 5895, 297, 413, 430, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 459, 2926, 344, 995, 17245, 9, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 63, 5649, 63, 354, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 20968, 297, 8375, 12, 283, 10838, 297, 1520, 12, 283, 5895, 297, 283, 5601, 1333, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 459, 2926, 344, 995, 17245, 9, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 63, 5649, 63, 1955, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 20968, 297, 8375, 12, 283, 10838, 297, 1520, 12, 283, 5895, 297, 413, 430, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 459, 2926, 344, 995, 17245, 9, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 4752, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 5895, 297, 221, 5008, 430, 267, 291, 14, 629, 8, 2926, 12, 488, 9, 421, 199, 533, 428, 6224, 11442, 8, 6520, 14, 11442, 4256, 12, 2882, 14, 1746, 304, 339, 6037, 2543, 275, 7124 ]
[ 961, 570, 365, 1777, 402, 6516, 3018, 14, 221, 6516, 3018, 365, 2867, 2032, 26, 1265, 883, 199, 3, 3604, 652, 436, 15, 269, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 199, 3, 844, 465, 3267, 701, 314, 2868, 2290, 2752, 12, 1015, 499, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 2428, 199, 3, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 3169, 503, 3092, 199, 3, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 1696, 1684, 844, 367, 1655, 199, 3, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 3180, 543, 199, 3, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 8026, 199, 3, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 11315, 13, 10067, 8217, 14, 199, 3, 199, 3, 1898, 6516, 3018, 11682, 14409, 83, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 7390, 14, 4901, 492, 10133, 199, 504, 7390, 14, 4901, 492, 9655, 199, 504, 7390, 14, 14443, 492, 2882, 199, 199, 504, 21306, 14, 576, 492, 7124, 199, 504, 21306, 14, 396, 14, 3183, 492, 289, 16702, 66, 199, 504, 21306, 14, 396, 14, 3183, 492, 4026, 4133, 199, 504, 21306, 14, 396, 14, 1974, 492, 6037, 199, 504, 21306, 14, 396, 14, 1974, 492, 8386, 199, 504, 21306, 14, 1974, 492, 9463, 18, 2083, 199, 199, 4961, 17, 275, 1926, 6984, 199, 4961, 18, 275, 1926, 9993, 199, 4961, 19, 275, 1926, 6772, 421, 199, 533, 13382, 11442, 8, 6520, 14, 11442, 4256, 12, 2882, 14, 1746, 304, 339, 6037, 2543, 275, 7124, 14, 7801, 11442, 272, 2073, 804, 2543, 275, 7124, 14, 7801, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 5996, 11442, 342, 267, 291, 14, 697, 14, 3176, 16550, 779, 288, 289, 16702, 66, 14, 12678, 8, 344, 29, 2417, 12, 536, 534, 5135, 659, 288, 289, 16702, 66, 14, 6437, 8, 344, 29, 1138, 395, 288, 289, 16702, 66, 14, 12288, 8, 344, 29, 1299, 395, 288, 289, 16702, 66, 14, 3425, 409, 8, 344, 29, 1299, 1081, 395, 288, 289, 16702, 66, 14, 3425, 2017, 8, 344, 29, 2564, 12, 1900, 261, 5700, 29, 1299, 1081, 395, 288, 289, 16702, 66, 14, 3425, 8, 344, 29, 1216, 12, 1032, 24446, 1677, 29, 1138, 12, 1329, 29, 23, 12, 333, 9209, 1677, 29, 1299, 12, 586, 1900, 1069, 344, 29, 2564, 12, 7239, 344, 29, 2417, 395, 288, 289, 16702, 66, 14, 7801, 8, 344, 29, 2760, 12, 1329, 29, 16, 12, 536, 534, 368, 297, 1032, 382, 14887, 29, 1216, 12, 717, 8239, 63, 292, 29, 4961, 17, 12, 4890, 63, 292, 29, 4961, 18, 12, 2058, 29, 16, 395, 288, 289, 16702, 66, 14, 7801, 8, 344, 29, 3172, 12, 1329, 29, 17, 12, 536, 534, 5601, 297, 1032, 382, 14887, 29, 1216, 12, 717, 8239, 63, 292, 29, 4961, 18, 12, 4890, 63, 292, 29, 4961, 19, 12, 2058, 29, 18, 12, 717, 8187, 63, 1001, 30845, 6641, 354, 5122, 633, 2266, 633, 5122, 1014, 921, 633, 3570, 26987, 288, 289, 16702, 66, 14, 7801, 8, 344, 29, 2819, 12, 1329, 29, 18, 12, 536, 534, 10480, 297, 1032, 382, 14887, 29, 1216, 12, 717, 8239, 63, 292, 29, 4961, 19, 12, 8752, 29, 549, 395, 267, 4794, 339, 347, 6766, 8, 277, 304, 267, 291, 14, 12336, 11442, 342, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 5895, 297, 15323, 430, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 12, 469, 288, 283, 464, 382, 14887, 356, 4233, 12, 288, 283, 4883, 356, 756, 12, 288, 283, 4883, 63, 292, 356, 488, 12, 288, 283, 354, 356, 399, 1133, 72, 850, 297, 288, 283, 1955, 356, 499, 12, 288, 283, 2604, 356, 488, 12, 288, 283, 8924, 63, 292, 356, 9463, 18, 2083, 8, 4961, 19, 395, 288, 283, 929, 63, 875, 356, 399, 6448, 288, 283, 2926, 344, 356, 15323, 12, 288, 283, 3603, 356, 990, 288, 283, 5642, 356, 715, 1552, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 63, 464, 382, 14887, 63, 354, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 10838, 297, 4233, 12, 283, 5895, 297, 283, 5601, 1333, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 459, 2926, 344, 995, 17245, 9, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 63, 464, 382, 14887, 63, 1955, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 10838, 297, 4233, 12, 283, 5895, 297, 413, 430, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 459, 2926, 344, 995, 17245, 9, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 63, 5649, 63, 354, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 20968, 297, 8375, 12, 283, 10838, 297, 1520, 12, 283, 5895, 297, 283, 5601, 1333, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 459, 2926, 344, 995, 17245, 9, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 5952, 63, 5649, 63, 1955, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 20968, 297, 8375, 12, 283, 10838, 297, 1520, 12, 283, 5895, 297, 413, 430, 267, 291, 14, 3502, 1451, 8, 2926, 9, 267, 291, 14, 629, 8, 2926, 459, 2926, 344, 995, 17245, 9, 339, 768, 11610, 14, 24813, 272, 347, 511, 63, 362, 63, 4752, 8, 277, 304, 267, 3650, 275, 1995, 291, 14, 1250, 1002, 4725, 5895, 297, 221, 5008, 430, 267, 291, 14, 629, 8, 2926, 12, 488, 9, 421, 199, 533, 428, 6224, 11442, 8, 6520, 14, 11442, 4256, 12, 2882, 14, 1746, 304,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1, 1, 1, 1, 1, 1, 1, 1, 1 ]
yungyuc/solvcon
solvcon/io/tests/test_vtk.py
2
1549
# -*- coding: UTF-8 -*- import os from unittest import TestCase from ...testing import loadfile from .. import gambit class WriteTest(TestCase): __test__ = False blk = None str_neu_vtk = None def assertLines(self, str1, str2): """ Compare two input strings line by line. """ import sys lines1 = str1.splitlines() lines2 = str2.splitlines() self.assertEqual(len(lines1), len(lines2)) iswin = sys.platform.startswith('win') nlines = len(lines1) i = 0 while i < nlines: oline = lines1[i] nline = lines2[i] # compare only non-float lines. if not iswin or 'e' not in oline.lower(): self.assertEqual(oline, nline) i += 1 def test_legacy(self): from io import StringIO from .. import vtk outf = StringIO() writer = vtk.VtkLegacyUstGridWriter(self.blk) writer.write(outf) str_blk_vtk = outf.getvalue() # compare new result with old result line by line. self.assertLines(self.str_neu_vtk, str_blk_vtk) """class TestWriteSingle(WriteTest): __test__ = True blk = gambit.GambitNeutral(loadfile('sample.neu')).toblock( fpdtype='float32') str_neu_vtk = loadfile('sample.neu.single.vtk')""" class TestWriteDouble(WriteTest): __test__ = True blk = gambit.GambitNeutral(loadfile('sample.neu')).toblock( fpdtype='float64') str_neu_vtk = loadfile('sample.neu.double.vtk')
bsd-3-clause
[ 3, 1882, 2803, 26, 9094, 13, 24, 1882, 421, 199, 646, 747, 199, 504, 2882, 492, 7640, 199, 504, 2263, 4776, 492, 2248, 493, 199, 504, 2508, 492, 486, 455, 2075, 199, 199, 533, 6990, 774, 8, 1746, 304, 272, 636, 396, 363, 275, 756, 272, 22742, 275, 488, 272, 620, 63, 685, 85, 63, 11919, 275, 488, 339, 347, 702, 9863, 8, 277, 12, 620, 17, 12, 620, 18, 304, 267, 408, 267, 18955, 2877, 1324, 3326, 1004, 701, 1004, 14, 267, 408, 267, 492, 984, 267, 2385, 17, 275, 620, 17, 14, 7644, 342, 267, 2385, 18, 275, 620, 18, 14, 7644, 342, 267, 291, 14, 629, 8, 552, 8, 1278, 17, 395, 822, 8, 1278, 18, 430, 267, 365, 2676, 275, 984, 14, 3246, 14, 2460, 360, 2676, 358, 267, 302, 1278, 275, 822, 8, 1278, 17, 9, 267, 284, 275, 378, 267, 1830, 284, 665, 302, 1278, 26, 288, 312, 604, 275, 2385, 17, 59, 73, 61, 288, 302, 604, 275, 2385, 18, 59, 73, 61, 288, 327, 6540, 1454, 2222, 13, 1609, 2385, 14, 288, 340, 440, 365, 2676, 503, 283, 69, 7, 440, 315, 312, 604, 14, 2325, 837, 355, 291, 14, 629, 8, 393, 1132, 12, 302, 604, 9, 288, 284, 847, 413, 20950, 347, 511, 63, 10000, 8, 277, 304, 267, 687, 5890, 492, 5228, 267, 687, 2508, 492, 11144, 267, 27552, 275, 5228, 342, 267, 7060, 275, 11144, 14, 54, 2663, 22628, 53, 270, 7900, 6261, 8, 277, 14, 14023, 9, 267, 7060, 14, 952, 8, 548, 70, 9, 267, 620, 63, 14023, 63, 11919, 275, 27552, 14, 7150, 342, 267, 327, 6540, 892, 754, 543, 2269, 754, 1004, 701, 1004, 14, 267, 291, 14, 479, 9863, 8, 277, 14, 495, 63, 685, 85, 63, 11919, 12, 620, 63, 14023, 63, 11919, 9, 199, 199, 624, 533, 1379, 3534, 7200, 8, 3534, 774, 304, 272, 636, 396, 363, 275, 715, 272, 22742, 275, 486, 455, 2075, 14, 39, 455, 2075, 4698, 29358, 8, 912, 493, 360, 3271, 14, 685, 85, 11103, 475, 1457, 8, 267, 4090, 2271, 534, 1609, 708, 358, 272, 620, 63, 685, 85, 63, 11919, 275, 2248, 493, 360, 3271, 14, 685, 85, 14, 4780, 14, 11919, 358, 624, 199, 199, 533, 1379, 3534, 7281, 8, 3534, 774, 304, 272, 636, 396, 363, 275, 715, 272, 22742, 275, 486, 455, 2075, 14, 39, 455, 2075, 4698, 29358, 8, 912, 493, 360, 3271, 14, 685, 85, 11103, 475, 1457, 8, 267, 4090, 2271, 534, 1609, 772, 358, 272, 620, 63, 685, 85, 63, 11919, 275, 2248, 493, 360, 3271, 14, 685, 85, 14, 3157, 14, 11919, 358, 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 ]
[ 1882, 2803, 26, 9094, 13, 24, 1882, 421, 199, 646, 747, 199, 504, 2882, 492, 7640, 199, 504, 2263, 4776, 492, 2248, 493, 199, 504, 2508, 492, 486, 455, 2075, 199, 199, 533, 6990, 774, 8, 1746, 304, 272, 636, 396, 363, 275, 756, 272, 22742, 275, 488, 272, 620, 63, 685, 85, 63, 11919, 275, 488, 339, 347, 702, 9863, 8, 277, 12, 620, 17, 12, 620, 18, 304, 267, 408, 267, 18955, 2877, 1324, 3326, 1004, 701, 1004, 14, 267, 408, 267, 492, 984, 267, 2385, 17, 275, 620, 17, 14, 7644, 342, 267, 2385, 18, 275, 620, 18, 14, 7644, 342, 267, 291, 14, 629, 8, 552, 8, 1278, 17, 395, 822, 8, 1278, 18, 430, 267, 365, 2676, 275, 984, 14, 3246, 14, 2460, 360, 2676, 358, 267, 302, 1278, 275, 822, 8, 1278, 17, 9, 267, 284, 275, 378, 267, 1830, 284, 665, 302, 1278, 26, 288, 312, 604, 275, 2385, 17, 59, 73, 61, 288, 302, 604, 275, 2385, 18, 59, 73, 61, 288, 327, 6540, 1454, 2222, 13, 1609, 2385, 14, 288, 340, 440, 365, 2676, 503, 283, 69, 7, 440, 315, 312, 604, 14, 2325, 837, 355, 291, 14, 629, 8, 393, 1132, 12, 302, 604, 9, 288, 284, 847, 413, 20950, 347, 511, 63, 10000, 8, 277, 304, 267, 687, 5890, 492, 5228, 267, 687, 2508, 492, 11144, 267, 27552, 275, 5228, 342, 267, 7060, 275, 11144, 14, 54, 2663, 22628, 53, 270, 7900, 6261, 8, 277, 14, 14023, 9, 267, 7060, 14, 952, 8, 548, 70, 9, 267, 620, 63, 14023, 63, 11919, 275, 27552, 14, 7150, 342, 267, 327, 6540, 892, 754, 543, 2269, 754, 1004, 701, 1004, 14, 267, 291, 14, 479, 9863, 8, 277, 14, 495, 63, 685, 85, 63, 11919, 12, 620, 63, 14023, 63, 11919, 9, 199, 199, 624, 533, 1379, 3534, 7200, 8, 3534, 774, 304, 272, 636, 396, 363, 275, 715, 272, 22742, 275, 486, 455, 2075, 14, 39, 455, 2075, 4698, 29358, 8, 912, 493, 360, 3271, 14, 685, 85, 11103, 475, 1457, 8, 267, 4090, 2271, 534, 1609, 708, 358, 272, 620, 63, 685, 85, 63, 11919, 275, 2248, 493, 360, 3271, 14, 685, 85, 14, 4780, 14, 11919, 358, 624, 199, 199, 533, 1379, 3534, 7281, 8, 3534, 774, 304, 272, 636, 396, 363, 275, 715, 272, 22742, 275, 486, 455, 2075, 14, 39, 455, 2075, 4698, 29358, 8, 912, 493, 360, 3271, 14, 685, 85, 11103, 475, 1457, 8, 267, 4090, 2271, 534, 1609, 772, 358, 272, 620, 63, 685, 85, 63, 11919, 275, 2248, 493, 360, 3271, 14, 685, 85, 14, 3157, 14, 11919, 358, 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, 0 ]
[ 1, 1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Storm/st2
st2api/st2api/controllers/v1/actionexecutions.py
3
42024
# Copyright 2020 The StackStorm Authors. # Copyright 2019 Extreme Networks, 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. from typing import Optional import copy import re import sys import gzip import traceback import six import orjson import jsonschema from oslo_config import cfg from six.moves import http_client from mongoengine.queryset.visitor import Q from st2api.controllers.base import BaseRestControllerMixin from st2api.controllers.resource import ResourceController from st2api.controllers.resource import BaseResourceIsolationControllerMixin from st2api.controllers.v1.execution_views import ExecutionViewsController from st2api.controllers.v1.execution_views import SUPPORTED_FILTERS from st2common import log as logging from st2common.constants import action as action_constants from st2common.exceptions import actionrunner as runner_exc from st2common.exceptions import apivalidation as validation_exc from st2common.exceptions import param as param_exc from st2common.exceptions import trace as trace_exc from st2common.models.api.action import LiveActionAPI from st2common.models.api.action import LiveActionCreateAPI from st2common.models.api.base import cast_argument_value from st2common.models.api.execution import ActionExecutionAPI from st2common.models.db.auth import UserDB from st2common.persistence.liveaction import LiveAction from st2common.persistence.execution import ActionExecution from st2common.persistence.execution import ActionExecutionOutput from st2common.router import abort from st2common.router import Response from st2common.router import NotFoundException from st2common.services import action as action_service from st2common.services import executions as execution_service from st2common.services import trace as trace_service from st2common.util import isotime from st2common.util import action_db as action_utils from st2common.util import param as param_utils from st2common.util.jsonify import try_loads from st2common.rbac.types import PermissionType from st2common.rbac.backends import get_rbac_backend __all__ = ["ActionExecutionsController"] LOG = logging.getLogger(__name__) # Note: We initialize filters here and not in the constructor SUPPORTED_EXECUTIONS_FILTERS = copy.deepcopy(SUPPORTED_FILTERS) SUPPORTED_EXECUTIONS_FILTERS.update( {"timestamp_gt": "start_timestamp.gt", "timestamp_lt": "start_timestamp.lt"} ) MONITOR_THREAD_EMPTY_Q_SLEEP_TIME = 5 MONITOR_THREAD_NO_WORKERS_SLEEP_TIME = 1 class ActionExecutionsControllerMixin(BaseRestControllerMixin): """ Mixin class with shared methods. """ model = ActionExecutionAPI access = ActionExecution # Those two attributes are mandatory so we can correctly determine and mask secret execution # parameters mandatory_include_fields_retrieve = [ "action.parameters", "action.output_schema", "runner.runner_parameters", "runner.output_key", "parameters", # Attributes below are mandatory for RBAC installations "action.pack", "action.uid", # Required when rbac.permission_isolation is enabled "context", ] # A list of attributes which can be specified using ?exclude_attributes filter # NOTE: Allowing user to exclude attribute such as action and runner would break secrets # masking valid_exclude_attributes = ["result", "trigger_instance", "status"] def _handle_schedule_execution( self, liveaction_api, requester_user, context_string=None, show_secrets=False ): """ :param liveaction: LiveActionAPI object. :type liveaction: :class:`LiveActionAPI` """ if not requester_user: requester_user = UserDB(name=cfg.CONF.system_user.user) # Assert action ref is valid action_ref = liveaction_api.action action_db = action_utils.get_action_by_ref(action_ref) if not action_db: message = 'Action "%s" cannot be found.' % (action_ref) LOG.warning(message) abort(http_client.BAD_REQUEST, message) # Assert the permissions permission_type = PermissionType.ACTION_EXECUTE rbac_utils = get_rbac_backend().get_utils_class() rbac_utils.assert_user_has_resource_db_permission( user_db=requester_user, resource_db=action_db, permission_type=permission_type, ) # Validate that the authenticated user is admin if user query param is provided user = liveaction_api.user or requester_user.name rbac_utils.assert_user_is_admin_if_user_query_param_is_provided( user_db=requester_user, user=user ) try: return self._schedule_execution( liveaction=liveaction_api, requester_user=requester_user, user=user, context_string=context_string, show_secrets=show_secrets, action_db=action_db, ) except ValueError as e: LOG.exception("Unable to execute action.") abort(http_client.BAD_REQUEST, six.text_type(e)) except jsonschema.ValidationError as e: LOG.exception("Unable to execute action. Parameter validation failed.") abort( http_client.BAD_REQUEST, re.sub("u'([^']*)'", r"'\1'", getattr(e, "message", six.text_type(e))), ) except trace_exc.TraceNotFoundException as e: abort(http_client.BAD_REQUEST, six.text_type(e)) except validation_exc.ValueValidationException as e: raise e except Exception as e: LOG.exception("Unable to execute action. Unexpected error encountered.") abort(http_client.INTERNAL_SERVER_ERROR, six.text_type(e)) def _schedule_execution( self, liveaction, requester_user, action_db, user=None, context_string=None, show_secrets=False, ): # Initialize execution context if it does not exist. if not hasattr(liveaction, "context"): liveaction.context = dict() liveaction.context["user"] = user liveaction.context["pack"] = action_db.pack LOG.debug("User is: %s" % liveaction.context["user"]) # Retrieve other st2 context from request header. if context_string: context = try_loads(context_string) if not isinstance(context, dict): raise ValueError( "Unable to convert st2-context from the headers into JSON" f" (was {type(context)})." ) liveaction.context.update(context) # Include RBAC context (if RBAC is available and enabled) if cfg.CONF.rbac.enable: user_db = UserDB(name=user) rbac_service = get_rbac_backend().get_service_class() role_dbs = rbac_service.get_roles_for_user( user_db=user_db, include_remote=True ) roles = [role_db.name for role_db in role_dbs] liveaction.context["rbac"] = {"user": user, "roles": roles} # Schedule the action execution. liveaction_db = LiveActionAPI.to_model(liveaction) runnertype_db = action_utils.get_runnertype_by_name( action_db.runner_type["name"] ) try: liveaction_db.parameters = param_utils.render_live_params( runnertype_db.runner_parameters, action_db.parameters, liveaction_db.parameters, liveaction_db.context, ) except param_exc.ParamException: # We still need to create a request, so liveaction_db is assigned an ID liveaction_db, actionexecution_db = action_service.create_request( liveaction=liveaction_db, action_db=action_db, runnertype_db=runnertype_db, ) # By this point the execution is already in the DB therefore need to mark it failed. _, e, tb = sys.exc_info() action_service.update_status( liveaction=liveaction_db, new_status=action_constants.LIVEACTION_STATUS_FAILED, result={ "error": six.text_type(e), "traceback": "".join(traceback.format_tb(tb, 20)), }, ) # Might be a good idea to return the actual ActionExecution rather than bubble up # the exception. raise validation_exc.ValueValidationException(six.text_type(e)) # The request should be created after the above call to render_live_params # so any templates in live parameters have a chance to render. liveaction_db, actionexecution_db = action_service.create_request( liveaction=liveaction_db, action_db=action_db, runnertype_db=runnertype_db ) _, actionexecution_db = action_service.publish_request( liveaction_db, actionexecution_db ) mask_secrets = self._get_mask_secrets(requester_user, show_secrets=show_secrets) execution_api = ActionExecutionAPI.from_model( actionexecution_db, mask_secrets=mask_secrets ) return Response(json=execution_api, status=http_client.CREATED) def _get_result_object(self, id): """ Retrieve result object for the provided action execution. :param id: Action execution ID. :type id: ``str`` :rtype: ``dict`` """ fields = ["result"] action_exec_db = ( self.access.impl.model.objects.filter(id=id).only(*fields).get() ) return action_exec_db.result def _get_children( self, id_, requester_user, depth=-1, result_fmt=None, show_secrets=False ): # make sure depth is int. Url encoding will make it a string and needs to # be converted back in that case. depth = int(depth) LOG.debug("retrieving children for id: %s with depth: %s", id_, depth) descendants = execution_service.get_descendants( actionexecution_id=id_, descendant_depth=depth, result_fmt=result_fmt ) mask_secrets = self._get_mask_secrets(requester_user, show_secrets=show_secrets) return [ self.model.from_model(descendant, mask_secrets=mask_secrets) for descendant in descendants ] class BaseActionExecutionNestedController( ActionExecutionsControllerMixin, ResourceController ): # Note: We need to override "get_one" and "get_all" to return 404 since nested controller # don't implement thos methods # ResourceController attributes query_options = {} supported_filters = {} def get_all(self): abort(http_client.NOT_FOUND) def get_one(self, id): abort(http_client.NOT_FOUND) class ActionExecutionChildrenController(BaseActionExecutionNestedController): def get_one( self, id, requester_user, depth=-1, result_fmt=None, show_secrets=False ): """ Retrieve children for the provided action execution. :rtype: ``list`` """ if not requester_user: requester_user = UserDB(name=cfg.CONF.system_user.user) from_model_kwargs = { "mask_secrets": self._get_mask_secrets( requester_user, show_secrets=show_secrets ) } execution_db = self._get_one_by_id( id=id, requester_user=requester_user, from_model_kwargs=from_model_kwargs, permission_type=PermissionType.EXECUTION_VIEW, ) id = str(execution_db.id) return self._get_children( id_=id, depth=depth, result_fmt=result_fmt, requester_user=requester_user, show_secrets=show_secrets, ) class ActionExecutionAttributeController(BaseActionExecutionNestedController): valid_exclude_attributes = [ "action__pack", "action__uid", ] + ActionExecutionsControllerMixin.valid_exclude_attributes def get(self, id, attribute, requester_user): """ Retrieve a particular attribute for the provided action execution. Handles requests: GET /executions/<id>/attribute/<attribute name> :rtype: ``dict`` """ fields = [attribute, "action__pack", "action__uid"] try: fields = self._validate_exclude_fields(fields) except ValueError: valid_attributes = ", ".join( ActionExecutionsControllerMixin.valid_exclude_attributes ) msg = 'Invalid attribute "%s" specified. Valid attributes are: %s' % ( attribute, valid_attributes, ) raise ValueError(msg) action_exec_db = ( self.access.impl.model.objects.filter(id=id).only(*fields).get() ) permission_type = PermissionType.EXECUTION_VIEW rbac_utils = get_rbac_backend().get_utils_class() rbac_utils.assert_user_has_resource_db_permission( user_db=requester_user, resource_db=action_exec_db, permission_type=permission_type, ) result = getattr(action_exec_db, attribute, None) return Response(json=result, status=http_client.OK) class ActionExecutionRawResultController(BaseActionExecutionNestedController): def get( self, id, requester_user, download=False, compress=False, pretty_format=False ): """ Retrieve raw action execution result object as a JSON string or optionally force result download as a (compressed) file. This is primarily to be used in scenarios where executions contain large results and JSON loading and parsing it can be slow (e.g. in the st2web) and we just want to display raw result. :param compress: True to compress the response using gzip (may come handy for executions with large results). :param download: True to force downloading result to a file. :param pretty_format: True to pretty format returned JSON data - this adds quite some overhead compared to the default behavior where we don't pretty format the result. Handles requests: GET /executions/<id>/result[?download=1][&compress=1] TODO: Maybe we should also support pre-signed URLs for sharing externally with other people? It of course won't contain all the exection related data, but just sharing the result can come handy in many situations. :rtype: ``str`` """ # NOTE: Here we intentionally use as_pymongo() to avoid mongoengine layer even for old style # data try: result = ( self.access.impl.model.objects.filter(id=id) .only("result") .as_pymongo()[0] ) except IndexError: raise NotFoundException("Execution with id %s not found" % (id)) if isinstance(result["result"], dict): # For backward compatibility we also support old non JSON field storage format if pretty_format: response_body = orjson.dumps( result["result"], option=orjson.OPT_INDENT_2 ) else: response_body = orjson.dumps(result["result"]) else: # For new JSON storage format we just use raw value since it's already JSON serialized # string response_body = result["result"] if pretty_format: # Pretty format is not a default behavior since it adds quite some overhead (e.g. # 10-30ms for non pretty format for 4 MB json vs ~120 ms for pretty formatted) response_body = orjson.dumps( orjson.loads(result["result"]), option=orjson.OPT_INDENT_2 ) response = Response() response.headers["Content-Type"] = "text/json" if download: filename = "execution_%s_result.json" % (id) if compress: filename += ".gz" response.headers["Content-Disposition"] = "attachment; filename=%s" % ( filename ) if compress: response.headers["Content-Type"] = "application/x-gzip" response.headers["Content-Encoding"] = "gzip" response_body = gzip.compress(response_body) response.body = response_body return response class ActionExecutionOutputController( ActionExecutionsControllerMixin, ResourceController ): supported_filters = {"output_type": "output_type"} exclude_fields = [] def get_one( self, id, output_type="all", output_format="raw", existing_only=False, requester_user=None, show_secrets=False, ): # Special case for id == "last" if id == "last": execution_db = ActionExecution.query().order_by("-id").limit(1).first() if not execution_db: raise ValueError("No executions found in the database") id = str(execution_db.id) if not requester_user: requester_user = UserDB(name=cfg.CONF.system_user.user) from_model_kwargs = { "mask_secrets": self._get_mask_secrets( requester_user, show_secrets=show_secrets ) } execution_db = self._get_one_by_id( id=id, requester_user=requester_user, from_model_kwargs=from_model_kwargs, permission_type=PermissionType.EXECUTION_VIEW, ) execution_id = str(execution_db.id) query_filters = {} if output_type and output_type != "all": query_filters["output_type"] = output_type def existing_output_iter(): # Consume and return all of the existing lines # pylint: disable=no-member output_dbs = ActionExecutionOutput.query( execution_id=execution_id, **query_filters ) output = "".join([output_db.data for output_db in output_dbs]) yield six.binary_type(output.encode("utf-8")) def make_response(): app_iter = existing_output_iter() res = Response(content_type="text/plain", app_iter=app_iter) return res res = make_response() return res class ActionExecutionReRunController( ActionExecutionsControllerMixin, ResourceController ): supported_filters = {} exclude_fields = ["result", "trigger_instance"] class ExecutionSpecificationAPI(object): def __init__(self, parameters=None, tasks=None, reset=None, user=None): self.parameters = parameters or {} self.tasks = tasks or [] self.reset = reset or [] self.user = user def validate(self): if (self.tasks or self.reset) and self.parameters: raise ValueError( "Parameters override is not supported when " "re-running task(s) for a workflow." ) if self.parameters: if not isinstance(self.parameters, dict): raise TypeError( f"The parameters needs to be a dictionary (was {type(self.parameters)})." ) if self.tasks: if not isinstance(self.tasks, list): raise TypeError( f"The tasks needs to be a list (was {type(self.tasks)})." ) if self.reset: if not isinstance(self.reset, list): raise TypeError( f"The reset needs to be a list (was {type(self.reset)})." ) if list(set(self.reset) - set(self.tasks)): raise ValueError( "List of tasks to reset does not match the tasks to rerun." ) return self def post(self, spec_api, id, requester_user, no_merge=False, show_secrets=False): """ Re-run the provided action execution optionally specifying override parameters. Handles requests: POST /executions/<id>/re_run """ if (spec_api.tasks or spec_api.reset) and spec_api.parameters: raise ValueError( "Parameters override is not supported when " "re-running task(s) for a workflow." ) if spec_api.parameters: if not isinstance(spec_api.parameters, dict): raise TypeError( f"The parameters needs to be a dictionary (was {type(spec_api.parameters)})." ) if spec_api.tasks: if not isinstance(spec_api.tasks, list): raise TypeError( f"The tasks needs to be a list (was {type(spec_api.tasks)})." ) if spec_api.reset: if not isinstance(spec_api.reset, list): raise TypeError( f"The reset needs to be a list (was {type(spec_api.reset)})." ) if list(set(spec_api.reset) - set(spec_api.tasks)): raise ValueError( "List of tasks to reset does not match the tasks to rerun." ) delay = None if hasattr(spec_api, "delay") and isinstance(spec_api.delay, int): delay = spec_api.delay no_merge = cast_argument_value(value_type=bool, value=no_merge) existing_execution = self._get_one_by_id( id=id, exclude_fields=self.exclude_fields, requester_user=requester_user, permission_type=PermissionType.EXECUTION_VIEW, ) if spec_api.tasks and existing_execution.runner["name"] != "orquesta": raise ValueError("Task option is only supported for Orquesta workflows.") # Merge in any parameters provided by the user new_parameters = {} if not no_merge: new_parameters.update(getattr(existing_execution, "parameters", {})) new_parameters.update(spec_api.parameters) # Create object for the new execution action_ref = existing_execution.action["ref"] # Include additional option(s) for the execution context = { "re-run": { "ref": id, } } if spec_api.tasks: context["re-run"]["tasks"] = spec_api.tasks if spec_api.reset: context["re-run"]["reset"] = spec_api.reset # Add trace to the new execution trace = trace_service.get_trace_db_by_action_execution( action_execution_id=existing_execution.id ) if trace: context["trace_context"] = {"id_": str(trace.id)} new_liveaction_api = LiveActionCreateAPI( action=action_ref, context=context, parameters=new_parameters, user=spec_api.user, delay=delay, ) return self._handle_schedule_execution( liveaction_api=new_liveaction_api, requester_user=requester_user, show_secrets=show_secrets, ) class ActionExecutionsController( BaseResourceIsolationControllerMixin, ActionExecutionsControllerMixin, ResourceController, ): """ Implements the RESTful web endpoint that handles the lifecycle of ActionExecutions in the system. """ # Nested controllers views = ExecutionViewsController() children = ActionExecutionChildrenController() attribute = ActionExecutionAttributeController() re_run = ActionExecutionReRunController() # ResourceController attributes query_options = {"sort": ["-start_timestamp", "action.ref"]} supported_filters = SUPPORTED_EXECUTIONS_FILTERS filter_transform_functions = { "timestamp_gt": lambda value: isotime.parse(value=value), "timestamp_lt": lambda value: isotime.parse(value=value), } def get_all( self, requester_user, exclude_attributes=None, sort=None, offset=0, limit=None, show_secrets=False, include_attributes=None, advanced_filters=None, **raw_filters, ): """ List all executions. Handles requests: GET /executions[?exclude_attributes=result,trigger_instance] :param exclude_attributes: List of attributes to exclude from the object. :type exclude_attributes: ``list`` """ # Use a custom sort order when filtering on a timestamp so we return a correct result as # expected by the user query_options = None if raw_filters.get("timestamp_lt", None) or raw_filters.get("sort_desc", None): query_options = {"sort": ["-start_timestamp", "action.ref"]} elif raw_filters.get("timestamp_gt", None) or raw_filters.get("sort_asc", None): query_options = {"sort": ["+start_timestamp", "action.ref"]} from_model_kwargs = { "mask_secrets": self._get_mask_secrets( requester_user, show_secrets=show_secrets ) } return self._get_action_executions( exclude_fields=exclude_attributes, include_fields=include_attributes, from_model_kwargs=from_model_kwargs, sort=sort, offset=offset, limit=limit, query_options=query_options, raw_filters=raw_filters, advanced_filters=advanced_filters, requester_user=requester_user, ) def get_one( self, id, requester_user, exclude_attributes=None, include_attributes=None, show_secrets=False, max_result_size=None, ): """ Retrieve a single execution. Handles requests: GET /executions/<id>[?exclude_attributes=result,trigger_instance] :param exclude_attributes: List of attributes to exclude from the object. :type exclude_attributes: ``list`` """ exclude_fields = self._validate_exclude_fields( exclude_fields=exclude_attributes ) include_fields = self._validate_include_fields( include_fields=include_attributes ) from_model_kwargs = { "mask_secrets": self._get_mask_secrets( requester_user, show_secrets=show_secrets ) } max_result_size = self._validate_max_result_size( max_result_size=max_result_size ) # Special case for id == "last" if id == "last": execution_db = ( ActionExecution.query().order_by("-id").limit(1).only("id").first() ) if not execution_db: raise ValueError("No executions found in the database") id = str(execution_db.id) return self._get_one_by_id( id=id, exclude_fields=exclude_fields, include_fields=include_fields, requester_user=requester_user, from_model_kwargs=from_model_kwargs, permission_type=PermissionType.EXECUTION_VIEW, get_by_id_kwargs={"max_result_size": max_result_size}, ) def post( self, liveaction_api, requester_user, context_string=None, show_secrets=False ): return self._handle_schedule_execution( liveaction_api=liveaction_api, requester_user=requester_user, context_string=context_string, show_secrets=show_secrets, ) def put(self, id, liveaction_api, requester_user, show_secrets=False): """ Updates a single execution. Handles requests: PUT /executions/<id> """ if not requester_user: requester_user = UserDB(name=cfg.CONF.system_user.user) from_model_kwargs = { "mask_secrets": self._get_mask_secrets( requester_user, show_secrets=show_secrets ) } execution_api = self._get_one_by_id( id=id, requester_user=requester_user, from_model_kwargs=from_model_kwargs, permission_type=PermissionType.EXECUTION_STOP, ) if not execution_api: abort(http_client.NOT_FOUND, "Execution with id %s not found." % id) liveaction_id = execution_api.liveaction["id"] if not liveaction_id: abort( http_client.INTERNAL_SERVER_ERROR, "Execution object missing link to liveaction %s." % liveaction_id, ) try: liveaction_db = LiveAction.get_by_id(liveaction_id) except: abort( http_client.INTERNAL_SERVER_ERROR, "Execution object missing link to liveaction %s." % liveaction_id, ) if liveaction_db.status in action_constants.LIVEACTION_COMPLETED_STATES: abort(http_client.BAD_REQUEST, "Execution is already in completed state.") def update_status(liveaction_api, liveaction_db): status = liveaction_api.status result = getattr(liveaction_api, "result", None) liveaction_db = action_service.update_status( liveaction_db, status, result, set_result_size=True ) actionexecution_db = ActionExecution.get( liveaction__id=str(liveaction_db.id) ) return (liveaction_db, actionexecution_db) try: if ( liveaction_db.status == action_constants.LIVEACTION_STATUS_CANCELING and liveaction_api.status == action_constants.LIVEACTION_STATUS_CANCELED ): if action_service.is_children_active(liveaction_id): liveaction_api.status = action_constants.LIVEACTION_STATUS_CANCELING liveaction_db, actionexecution_db = update_status( liveaction_api, liveaction_db ) elif ( liveaction_api.status == action_constants.LIVEACTION_STATUS_CANCELING or liveaction_api.status == action_constants.LIVEACTION_STATUS_CANCELED ): liveaction_db, actionexecution_db = action_service.request_cancellation( liveaction_db, requester_user.name or cfg.CONF.system_user.user ) elif ( liveaction_db.status == action_constants.LIVEACTION_STATUS_PAUSING and liveaction_api.status == action_constants.LIVEACTION_STATUS_PAUSED ): if action_service.is_children_active(liveaction_id): liveaction_api.status = action_constants.LIVEACTION_STATUS_PAUSING liveaction_db, actionexecution_db = update_status( liveaction_api, liveaction_db ) elif ( liveaction_api.status == action_constants.LIVEACTION_STATUS_PAUSING or liveaction_api.status == action_constants.LIVEACTION_STATUS_PAUSED ): liveaction_db, actionexecution_db = action_service.request_pause( liveaction_db, requester_user.name or cfg.CONF.system_user.user ) elif liveaction_api.status == action_constants.LIVEACTION_STATUS_RESUMING: liveaction_db, actionexecution_db = action_service.request_resume( liveaction_db, requester_user.name or cfg.CONF.system_user.user ) else: liveaction_db, actionexecution_db = update_status( liveaction_api, liveaction_db ) except runner_exc.InvalidActionRunnerOperationError as e: LOG.exception( "Failed updating liveaction %s. %s", liveaction_db.id, six.text_type(e) ) abort( http_client.BAD_REQUEST, "Failed updating execution. %s" % six.text_type(e), ) except runner_exc.UnexpectedActionExecutionStatusError as e: LOG.exception( "Failed updating liveaction %s. %s", liveaction_db.id, six.text_type(e) ) abort( http_client.BAD_REQUEST, "Failed updating execution. %s" % six.text_type(e), ) except Exception as e: LOG.exception( "Failed updating liveaction %s. %s", liveaction_db.id, six.text_type(e) ) abort( http_client.INTERNAL_SERVER_ERROR, "Failed updating execution due to unexpected error.", ) mask_secrets = self._get_mask_secrets(requester_user, show_secrets=show_secrets) execution_api = ActionExecutionAPI.from_model( actionexecution_db, mask_secrets=mask_secrets ) return execution_api def delete(self, id, requester_user, show_secrets=False): """ Stops a single execution. Handles requests: DELETE /executions/<id> """ if not requester_user: requester_user = UserDB(name=cfg.CONF.system_user.user) from_model_kwargs = { "mask_secrets": self._get_mask_secrets( requester_user, show_secrets=show_secrets ) } execution_api = self._get_one_by_id( id=id, requester_user=requester_user, from_model_kwargs=from_model_kwargs, permission_type=PermissionType.EXECUTION_STOP, ) if not execution_api: abort(http_client.NOT_FOUND, "Execution with id %s not found." % id) liveaction_id = execution_api.liveaction["id"] if not liveaction_id: abort( http_client.INTERNAL_SERVER_ERROR, "Execution object missing link to liveaction %s." % liveaction_id, ) try: liveaction_db = LiveAction.get_by_id(liveaction_id) except: abort( http_client.INTERNAL_SERVER_ERROR, "Execution object missing link to liveaction %s." % liveaction_id, ) if liveaction_db.status == action_constants.LIVEACTION_STATUS_CANCELED: LOG.info( 'Action %s already in "canceled" state; \ returning execution object.' % liveaction_db.id ) return execution_api if liveaction_db.status not in action_constants.LIVEACTION_CANCELABLE_STATES: abort( http_client.OK, "Action cannot be canceled. State = %s." % liveaction_db.status, ) try: (liveaction_db, execution_db) = action_service.request_cancellation( liveaction_db, requester_user.name or cfg.CONF.system_user.user ) except: LOG.exception( "Failed requesting cancellation for liveaction %s.", liveaction_db.id ) abort(http_client.INTERNAL_SERVER_ERROR, "Failed canceling execution.") return ActionExecutionAPI.from_model( execution_db, mask_secrets=from_model_kwargs["mask_secrets"] ) def _validate_max_result_size( self, max_result_size: Optional[int] ) -> Optional[int]: """ Validate value of the ?max_result_size query parameter (if provided). """ # Maximum limit for MongoDB collection document is 16 MB and the field itself can't be # larger than that obviously. And in reality due to the other fields, overhead, etc, # 14 is the upper limit. if not max_result_size: return max_result_size if max_result_size <= 0: raise ValueError("max_result_size must be a positive number") if max_result_size > 14 * 1024 * 1024: raise ValueError( "max_result_size query parameter must be smaller than 14 MB" ) return max_result_size def _get_by_id( self, resource_id, exclude_fields=None, include_fields=None, max_result_size=None, ): """ Custom version of _get_by_id() which supports ?max_result_size pre-filtering and not returning result field for executions which result size exceeds this threshold. This functionality allows us to implement fast and efficient retrievals in st2web. """ exclude_fields = exclude_fields or [] include_fields = include_fields or [] if not max_result_size: # If max_result_size is not provided we don't perform any prefiltering and directly # call parent method execution_db = super(ActionExecutionsController, self)._get_by_id( resource_id=resource_id, exclude_fields=exclude_fields, include_fields=include_fields, ) return execution_db # Special query where we check if result size is smaller than pre-defined or that field # doesn't not exist (old executions) and only return the result if the condition is met. # This allows us to implement fast and efficient retrievals of executions on the client # st2web side where we don't want to retrieve and display result directly for executions # with large results # Keep in mind that the query itself is very fast and adds almost no overhead for API # operations which pass this query parameter because we first filter on the ID (indexed # field) and perform projection query with two tiny fields (based on real life testing it # takes less than 3 ms in most scenarios). execution_db = self.access.get( Q(id=resource_id) & (Q(result_size__lte=max_result_size) | Q(result_size__not__exists=True)), only_fields=["id", "result_size"], ) # if result is empty, this means that execution either doesn't exist or the result is # larger than threshold which means we don't want to retrieve and return result to # the end user to we set exclude_fields accordingly if not execution_db: LOG.debug( "Execution with id %s and result_size < %s not found. This means " "execution with this ID doesn't exist or result_size exceeds the " "threshold. Result field will be excluded from the retrieval and " "the response." % (resource_id, max_result_size) ) if include_fields and "result" in include_fields: include_fields.remove("result") elif not include_fields: exclude_fields += ["result"] # Now call parent get by id with potentially modified include / exclude fields in case # result should not be included execution_db = super(ActionExecutionsController, self)._get_by_id( resource_id=resource_id, exclude_fields=exclude_fields, include_fields=include_fields, ) return execution_db def _get_action_executions( self, exclude_fields=None, include_fields=None, sort=None, offset=0, limit=None, advanced_filters=None, query_options=None, raw_filters=None, from_model_kwargs=None, requester_user=None, ): """ :param exclude_fields: A list of object fields to exclude. :type exclude_fields: ``list`` """ if limit is None: limit = self.default_limit limit = int(limit) LOG.debug( "Retrieving all action executions with filters=%s,exclude_fields=%s," "include_fields=%s", raw_filters, exclude_fields, include_fields, ) return super(ActionExecutionsController, self)._get_all( exclude_fields=exclude_fields, include_fields=include_fields, from_model_kwargs=from_model_kwargs, sort=sort, offset=offset, limit=limit, query_options=query_options, raw_filters=raw_filters, advanced_filters=advanced_filters, requester_user=requester_user, ) action_executions_controller = ActionExecutionsController() action_execution_output_controller = ActionExecutionOutputController() action_execution_rerun_controller = ActionExecutionReRunController() action_execution_attribute_controller = ActionExecutionAttributeController() action_execution_children_controller = ActionExecutionChildrenController() action_execution_raw_result_controller = ActionExecutionRawResultController()
apache-2.0
[ 3, 1898, 25455, 710, 13894, 933, 1025, 6642, 14, 199, 3, 1898, 20312, 7255, 17817, 17138, 12, 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, 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, 504, 14090, 492, 4879, 199, 199, 646, 1331, 199, 646, 295, 199, 646, 984, 199, 646, 11756, 199, 646, 5190, 199, 199, 646, 3816, 199, 646, 503, 1001, 199, 646, 2022, 3629, 199, 504, 11258, 63, 888, 492, 4810, 199, 504, 3816, 14, 4912, 492, 1455, 63, 1258, 199, 504, 18006, 3908, 14, 7924, 14, 19863, 492, 1413, 199, 199, 504, 410, 18, 1246, 14, 20531, 14, 1095, 492, 3523, 13726, 7506, 4256, 199, 504, 410, 18, 1246, 14, 20531, 14, 1927, 492, 7337, 7506, 199, 504, 410, 18, 1246, 14, 20531, 14, 1927, 492, 3523, 4031, 1831, 10410, 7506, 4256, 199, 504, 410, 18, 1246, 14, 20531, 14, 86, 17, 14, 9416, 63, 4196, 492, 28573, 21180, 7506, 199, 504, 410, 18, 1246, 14, 20531, 14, 86, 17, 14, 9416, 63, 4196, 492, 32501, 63, 9905, 51, 199, 504, 410, 18, 2330, 492, 943, 465, 2050, 199, 504, 410, 18, 2330, 14, 5559, 492, 1595, 465, 1595, 63, 5559, 199, 504, 410, 18, 2330, 14, 3924, 492, 1595, 5933, 465, 7876, 63, 2804, 199, 504, 410, 18, 2330, 14, 3924, 492, 2986, 6136, 465, 6411, 63, 2804, 199, 504, 410, 18, 2330, 14, 3924, 492, 1215, 465, 1215, 63, 2804, 199, 504, 410, 18, 2330, 14, 3924, 492, 3307, 465, 3307, 63, 2804, 199, 504, 410, 18, 2330, 14, 992, 14, 1246, 14, 1287, 492, 24683, 3310, 3735, 199, 504, 410, 18, 2330, 14, 992, 14, 1246, 14, 1287, 492, 24683, 3310, 2499, 3735, 199, 504, 410, 18, 2330, 14, 992, 14, 1246, 14, 1095, 492, 9106, 63, 2094, 63, 585, 199, 504, 410, 18, 2330, 14, 992, 14, 1246, 14, 9416, 492, 10033, 11310, 3735, 199, 504, 410, 18, 2330, 14, 992, 14, 697, 14, 1178, 492, 2876, 2846, 199, 504, 410, 18, 2330, 14, 24854, 14, 6442, 1287, 492, 24683, 3310, 199, 504, 410, 18, 2330, 14, 24854, 14, 9416, 492, 10033, 11310, 199, 504, 410, 18, 2330, 14, 24854, 14, 9416, 492, 10033, 11310, 2959, 199, 504, 410, 18, 2330, 14, 4995, 492, 12004, 199, 504, 410, 18, 2330, 14, 4995, 492, 7232, 199, 504, 410, 18, 2330, 14, 4995, 492, 21909, 1726, 199, 504, 410, 18, 2330, 14, 5950, 492, 1595, 465, 1595, 63, 1364, 199, 504, 410, 18, 2330, 14, 5950, 492, 2146, 8653, 465, 6451, 63, 1364, 199, 504, 410, 18, 2330, 14, 5950, 492, 3307, 465, 3307, 63, 1364, 199, 504, 410, 18, 2330, 14, 1974, 492, 11601, 521, 199, 504, 410, 18, 2330, 14, 1974, 492, 1595, 63, 697, 465, 1595, 63, 1208, 199, 504, 410, 18, 2330, 14, 1974, 492, 1215, 465, 1215, 63, 1208, 199, 504, 410, 18, 2330, 14, 1974, 14, 1001, 2021, 492, 862, 63, 3640, 199, 504, 410, 18, 2330, 14, 4848, 645, 14, 1313, 492, 8779, 804, 199, 504, 410, 18, 2330, 14, 4848, 645, 14, 7765, 492, 664, 63, 4848, 645, 63, 4620, 199, 199, 363, 452, 363, 275, 2097, 3310, 4858, 8653, 7506, 937, 199, 199, 4947, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 3, 3390, 26, 2136, 8265, 4766, 2348, 436, 440, 315, 314, 3787, 199, 15925, 63, 18074, 2823, 63, 9905, 51, 275, 1331, 14, 8293, 8, 15925, 63, 9905, 51, 9, 199, 15925, 63, 18074, 2823, 63, 9905, 51, 14, 873, 8, 272, 2420, 3954, 63, 3308, 582, 298, 928, 63, 3954, 14, 3308, 401, 298, 3954, 63, 4116, 582, 298, 928, 63, 3954, 14, 4116, 3570, 199, 9, 199, 199, 32387, 726, 63, 16103, 63, 13993, 63, 49, 63, 51, 906, 6102, 63, 4961, 275, 959, 199, 32387, 726, 63, 16103, 63, 2826, 63, 8406, 3960, 63, 51, 906, 6102, 63, 4961, 275, 413, 421, 199, 533, 10033, 4858, 8653, 7506, 4256, 8, 1563, 13726, 7506, 4256, 304, 272, 408, 272, 28438, 1021, 543, 5709, 3102, 14, 272, 408, 339, 1402, 275, 10033, 11310, 3735, 272, 2879, 275, 10033, 11310, 339, 327, 18049, 261, 2877, 3004, 787, 15230, 880, 781, 883, 6657, 6705, 436, 3656, 7565, 6451, 272, 327, 2633, 272, 15230, 63, 2613, 63, 955, 63, 14270, 275, 359, 267, 298, 1287, 14, 3214, 401, 267, 298, 1287, 14, 1199, 63, 3629, 401, 267, 298, 5933, 14, 5933, 63, 3214, 401, 267, 298, 5933, 14, 1199, 63, 498, 401, 267, 298, 3214, 401, 267, 327, 9382, 5084, 787, 15230, 367, 820, 34, 1348, 2727, 279, 6011, 267, 298, 1287, 14, 1389, 401, 267, 298, 1287, 14, 1535, 401, 267, 327, 11105, 1380, 11587, 645, 14, 5693, 63, 20808, 365, 5223, 267, 298, 1100, 401, 272, 1622, 339, 327, 437, 769, 402, 3004, 1314, 883, 506, 2013, 1808, 5805, 5473, 63, 2987, 2457, 272, 327, 6944, 26, 9812, 316, 922, 370, 5760, 2225, 4066, 465, 1595, 436, 7876, 3955, 2059, 25563, 272, 327, 3656, 316, 272, 1686, 63, 5473, 63, 2987, 275, 2097, 1099, 401, 298, 7631, 63, 842, 401, 298, 1205, 937, 339, 347, 485, 2479, 63, 7211, 63, 9416, 8, 267, 291, 12, 12166, 1287, 63, 1246, 12, 295, 18246, 63, 751, 12, 1067, 63, 875, 29, 403, 12, 2498, 63, 16153, 29, 797, 272, 3461, 267, 408, 267, 520, 635, 12166, 1287, 26, 24683, 3310, 3735, 909, 14, 267, 520, 466, 12166, 1287, 26, 520, 533, 1705, 17458, 3310, 3735, 64, 267, 408, 267, 340, 440 ]
[ 1898, 25455, 710, 13894, 933, 1025, 6642, 14, 199, 3, 1898, 20312, 7255, 17817, 17138, 12, 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, 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, 504, 14090, 492, 4879, 199, 199, 646, 1331, 199, 646, 295, 199, 646, 984, 199, 646, 11756, 199, 646, 5190, 199, 199, 646, 3816, 199, 646, 503, 1001, 199, 646, 2022, 3629, 199, 504, 11258, 63, 888, 492, 4810, 199, 504, 3816, 14, 4912, 492, 1455, 63, 1258, 199, 504, 18006, 3908, 14, 7924, 14, 19863, 492, 1413, 199, 199, 504, 410, 18, 1246, 14, 20531, 14, 1095, 492, 3523, 13726, 7506, 4256, 199, 504, 410, 18, 1246, 14, 20531, 14, 1927, 492, 7337, 7506, 199, 504, 410, 18, 1246, 14, 20531, 14, 1927, 492, 3523, 4031, 1831, 10410, 7506, 4256, 199, 504, 410, 18, 1246, 14, 20531, 14, 86, 17, 14, 9416, 63, 4196, 492, 28573, 21180, 7506, 199, 504, 410, 18, 1246, 14, 20531, 14, 86, 17, 14, 9416, 63, 4196, 492, 32501, 63, 9905, 51, 199, 504, 410, 18, 2330, 492, 943, 465, 2050, 199, 504, 410, 18, 2330, 14, 5559, 492, 1595, 465, 1595, 63, 5559, 199, 504, 410, 18, 2330, 14, 3924, 492, 1595, 5933, 465, 7876, 63, 2804, 199, 504, 410, 18, 2330, 14, 3924, 492, 2986, 6136, 465, 6411, 63, 2804, 199, 504, 410, 18, 2330, 14, 3924, 492, 1215, 465, 1215, 63, 2804, 199, 504, 410, 18, 2330, 14, 3924, 492, 3307, 465, 3307, 63, 2804, 199, 504, 410, 18, 2330, 14, 992, 14, 1246, 14, 1287, 492, 24683, 3310, 3735, 199, 504, 410, 18, 2330, 14, 992, 14, 1246, 14, 1287, 492, 24683, 3310, 2499, 3735, 199, 504, 410, 18, 2330, 14, 992, 14, 1246, 14, 1095, 492, 9106, 63, 2094, 63, 585, 199, 504, 410, 18, 2330, 14, 992, 14, 1246, 14, 9416, 492, 10033, 11310, 3735, 199, 504, 410, 18, 2330, 14, 992, 14, 697, 14, 1178, 492, 2876, 2846, 199, 504, 410, 18, 2330, 14, 24854, 14, 6442, 1287, 492, 24683, 3310, 199, 504, 410, 18, 2330, 14, 24854, 14, 9416, 492, 10033, 11310, 199, 504, 410, 18, 2330, 14, 24854, 14, 9416, 492, 10033, 11310, 2959, 199, 504, 410, 18, 2330, 14, 4995, 492, 12004, 199, 504, 410, 18, 2330, 14, 4995, 492, 7232, 199, 504, 410, 18, 2330, 14, 4995, 492, 21909, 1726, 199, 504, 410, 18, 2330, 14, 5950, 492, 1595, 465, 1595, 63, 1364, 199, 504, 410, 18, 2330, 14, 5950, 492, 2146, 8653, 465, 6451, 63, 1364, 199, 504, 410, 18, 2330, 14, 5950, 492, 3307, 465, 3307, 63, 1364, 199, 504, 410, 18, 2330, 14, 1974, 492, 11601, 521, 199, 504, 410, 18, 2330, 14, 1974, 492, 1595, 63, 697, 465, 1595, 63, 1208, 199, 504, 410, 18, 2330, 14, 1974, 492, 1215, 465, 1215, 63, 1208, 199, 504, 410, 18, 2330, 14, 1974, 14, 1001, 2021, 492, 862, 63, 3640, 199, 504, 410, 18, 2330, 14, 4848, 645, 14, 1313, 492, 8779, 804, 199, 504, 410, 18, 2330, 14, 4848, 645, 14, 7765, 492, 664, 63, 4848, 645, 63, 4620, 199, 199, 363, 452, 363, 275, 2097, 3310, 4858, 8653, 7506, 937, 199, 199, 4947, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 3, 3390, 26, 2136, 8265, 4766, 2348, 436, 440, 315, 314, 3787, 199, 15925, 63, 18074, 2823, 63, 9905, 51, 275, 1331, 14, 8293, 8, 15925, 63, 9905, 51, 9, 199, 15925, 63, 18074, 2823, 63, 9905, 51, 14, 873, 8, 272, 2420, 3954, 63, 3308, 582, 298, 928, 63, 3954, 14, 3308, 401, 298, 3954, 63, 4116, 582, 298, 928, 63, 3954, 14, 4116, 3570, 199, 9, 199, 199, 32387, 726, 63, 16103, 63, 13993, 63, 49, 63, 51, 906, 6102, 63, 4961, 275, 959, 199, 32387, 726, 63, 16103, 63, 2826, 63, 8406, 3960, 63, 51, 906, 6102, 63, 4961, 275, 413, 421, 199, 533, 10033, 4858, 8653, 7506, 4256, 8, 1563, 13726, 7506, 4256, 304, 272, 408, 272, 28438, 1021, 543, 5709, 3102, 14, 272, 408, 339, 1402, 275, 10033, 11310, 3735, 272, 2879, 275, 10033, 11310, 339, 327, 18049, 261, 2877, 3004, 787, 15230, 880, 781, 883, 6657, 6705, 436, 3656, 7565, 6451, 272, 327, 2633, 272, 15230, 63, 2613, 63, 955, 63, 14270, 275, 359, 267, 298, 1287, 14, 3214, 401, 267, 298, 1287, 14, 1199, 63, 3629, 401, 267, 298, 5933, 14, 5933, 63, 3214, 401, 267, 298, 5933, 14, 1199, 63, 498, 401, 267, 298, 3214, 401, 267, 327, 9382, 5084, 787, 15230, 367, 820, 34, 1348, 2727, 279, 6011, 267, 298, 1287, 14, 1389, 401, 267, 298, 1287, 14, 1535, 401, 267, 327, 11105, 1380, 11587, 645, 14, 5693, 63, 20808, 365, 5223, 267, 298, 1100, 401, 272, 1622, 339, 327, 437, 769, 402, 3004, 1314, 883, 506, 2013, 1808, 5805, 5473, 63, 2987, 2457, 272, 327, 6944, 26, 9812, 316, 922, 370, 5760, 2225, 4066, 465, 1595, 436, 7876, 3955, 2059, 25563, 272, 327, 3656, 316, 272, 1686, 63, 5473, 63, 2987, 275, 2097, 1099, 401, 298, 7631, 63, 842, 401, 298, 1205, 937, 339, 347, 485, 2479, 63, 7211, 63, 9416, 8, 267, 291, 12, 12166, 1287, 63, 1246, 12, 295, 18246, 63, 751, 12, 1067, 63, 875, 29, 403, 12, 2498, 63, 16153, 29, 797, 272, 3461, 267, 408, 267, 520, 635, 12166, 1287, 26, 24683, 3310, 3735, 909, 14, 267, 520, 466, 12166, 1287, 26, 520, 533, 1705, 17458, 3310, 3735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 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
jchome/LocalGuide-Mobile
database/localitydatareader.py
2
2287
#!/usr/bin/python # -*- coding: utf-8 -*- ### generated from template <objectdatareader.py> ### # AFTER CODE GENRATION : add this to the "__init__.py" file: # __all__ = ["datareader", ... , # "localitydatareader.LocalityDataReader", "localitydatareader.LocalityJsonRetriever" # ] ### from .datareader import DataReader, JsonRetriever from models.localityModel import Locality """Localité englobant les données de position """ class LocalityDataReader(DataReader): def __init__(self): DataReader.__init__(self, "locgui_localite", "locidloc", ["locidloc", "loclbnom", "locnulat", "locnulon"]) def getAllRecords(self): fullDict = DataReader.getAllRecords(self) return Locality.readAllFromDict(fullDict) def refreshData(self, message_writer = None): allObjects = LocalityJsonRetriever().retrieveAll() if allObjects is None: return None self.purgeTable(message_writer) for anObject in allObjects.itervalues(): json_data = { "locidloc" : anObject.locidloc, "loclbnom" : anObject.loclbnom, "locnulat" : anObject.locnulat, "locnulon" : anObject.locnulon } self.insertData(json_data, message_writer) def saveOrUpdate(self, anObject, message_writer = None): json_data = { "locidloc" : anObject.locidloc, "loclbnom" : anObject.loclbnom, "locnulat" : anObject.locnulat, "locnulon" : anObject.locnulon } if anObject.locidloc is None: anObject.locidloc = self.insertData(json_data, message_writer) else: self.updateData(json_data, message_writer) # get all <Localité> by <Identifiant>, using <locidloc> def getAllRecordsBy_locidloc(self, value): fullDict = DataReader.getAllRecordsEquals(self, "locidloc", value) return Locality.readAllFromDict(fullDict) class LocalityJsonRetriever(JsonRetriever): def __init__(self): JsonRetriever.__init__(self) def retrieveAll(self): URL_ALL = "locality/listlocalitysjson" fullDict = self.retrieveFromUrl(URL_ALL) if fullDict is not None: return Locality.readAllFromDict(fullDict) # get all <Localité> by <Identifiant>, using <locidloc> def retrieveAllBy_locidloc(self, value): URL_ALL = "locality/listlocalitysjson/findBy_locidloc/"+str(value) fullDict = self.retrieveFromUrl(URL_ALL) if fullDict is not None: return Locality.readAllFromDict(fullDict)
gpl-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 5680, 4046, 687, 1978, 665, 785, 576, 5503, 14, 647, 30, 199, 5680, 199, 3, 20089, 1157, 22547, 22813, 23743, 520, 1050, 642, 370, 314, 4396, 826, 4343, 647, 2, 570, 26, 199, 3, 221, 636, 452, 363, 275, 2097, 576, 5503, 401, 2263, 2360, 221, 199, 3, 198, 198, 2, 1832, 1209, 576, 5503, 14, 5339, 1209, 1451, 5929, 401, 298, 1832, 1209, 576, 5503, 14, 5339, 1209, 9653, 6816, 322, 5907, 2, 199, 3, 198, 61, 199, 5680, 199, 199, 504, 1275, 576, 5503, 492, 3918, 5929, 12, 14587, 6816, 322, 5907, 199, 504, 1709, 14, 1832, 1209, 1685, 492, 6263, 6712, 199, 199, 624, 5339, 390, 5741, 655, 6463, 867, 23487, 2793, 78, 5741, 397, 477, 3421, 199, 624, 199, 533, 6263, 6712, 1451, 5929, 8, 1451, 5929, 304, 8299, 198, 318, 636, 826, 721, 277, 304, 507, 198, 1451, 5929, 855, 826, 721, 277, 12, 298, 2102, 5885, 63, 1832, 1175, 401, 298, 2102, 344, 2102, 401, 2097, 2102, 344, 2102, 401, 298, 320, 429, 10472, 676, 401, 298, 2102, 78, 348, 292, 401, 298, 2102, 78, 348, 265, 3135, 18118, 198, 318, 664, 2422, 14941, 8, 277, 304, 507, 198, 2861, 2141, 275, 3918, 5929, 14, 31359, 14941, 8, 277, 9, 507, 198, 1107, 6263, 6712, 14, 739, 2422, 2532, 2141, 8, 2861, 2141, 9, 8299, 198, 318, 9236, 1451, 8, 277, 12, 1245, 63, 5491, 275, 488, 304, 507, 198, 452, 11188, 275, 6263, 6712, 9653, 6816, 322, 5907, 1252, 14270, 2422, 342, 507, 198, 692, 1006, 11188, 365, 488, 26, 686, 198, 1107, 488, 507, 198, 277, 14, 18254, 3186, 8, 1188, 63, 5491, 9, 507, 198, 509, 376, 1692, 315, 1006, 11188, 14, 13012, 837, 686, 198, 1001, 63, 576, 275, 469, 298, 2102, 344, 2102, 2, 520, 376, 1692, 14, 2102, 344, 2102, 12, 298, 320, 429, 10472, 676, 2, 520, 376, 1692, 14, 320, 429, 10472, 676, 12, 298, 2102, 78, 348, 292, 2, 520, 376, 1692, 14, 2102, 78, 348, 292, 12, 298, 2102, 78, 348, 265, 2, 520, 376, 1692, 14, 2102, 78, 348, 265, 789, 686, 198, 277, 14, 3176, 1451, 8, 1001, 63, 576, 12, 1245, 63, 5491, 9, 4388, 198, 318, 3354, 2844, 4152, 8, 277, 12, 376, 1692, 12, 1245, 63, 5491, 275, 488, 304, 507, 198, 1001, 63, 576, 275, 469, 298, 2102, 344, 2102, 2, 520, 376, 1692, 14, 2102, 344, 2102, 12, 298, 320, 429, 10472, 676, 2, 520, 376, 1692, 14, 320, 429, 10472, 676, 12, 298, 2102, 78, 348, 292, 2, 520, 376, 1692, 14, 2102, 78, 348, 292, 12, 298, 2102, 78, 348, 265, 2, 520, 376, 1692, 14, 2102, 78, 348, 265, 789, 507, 198, 692, 376, 1692, 14, 2102, 344, 2102, 365, 488, 26, 686, 198, 290, 1692, 14, 2102, 344, 2102, 275, 291, 14, 3176, 1451, 8, 1001, 63, 576, 12, 1245, 63, 5491, 9, 507, 198, 2836, 26, 686, 198, 277, 14, 873, 1451, 8, 1001, 63, 576, 12, 1245, 63, 5491, 9, 2742, 421, 198, 3, 664, 1006, 665, 5339, 390, 5741, 30, 701, 665, 41, 2433, 867, 6244, 1808, 665, 2102, 344, 2102, 30, 199, 198, 318, 664, 2422, 14941, 2175, 63, 2102, 344, 2102, 8, 277, 12, 574, 304, 507, 198, 2861, 2141, 275, 3918, 5929, 14, 31359, 14941, 13317, 8, 277, 12, 298, 2102, 344, 2102, 401, 574, 9, 507, 198, 1107, 6263, 6712, 14, 739, 2422, 2532, 2141, 8, 2861, 2141, 9, 686, 421, 199, 533, 6263, 6712, 9653, 6816, 322, 5907, 8, 9653, 6816, 322, 5907, 304, 8299, 198, 318, 636, 826, 721, 277, 304, 507, 198, 9653, 6816, 322, 5907, 855, 826, 721, 277, 9, 18118, 198, 318, 8044, 2422, 8, 277, 304, 507, 198, 2632, 63, 1761, 275, 298, 1832, 1209, 15, 513, 1832, 1209, 83, 1001, 2, 507, 198, 2861, 2141, 275, 291, 14, 14270, 2532, 6417, 8, 2632, 63, 1761, 9, 507, 198, 692, 2615, 2141, 365, 440, 488, 26, 686, 198, 1107, 6263, 6712, 14, 739, 2422, 2532, 2141, 8, 2861, 2141, 9, 4388, 198, 3, 664, 1006, 665, 5339, 390, 5741, 30, 701, 665, 41, 2433, 867, 6244, 1808, 665, 2102, 344, 2102, 30, 199, 198, 318, 8044, 2422, 2175, 63, 2102, 344, 2102, 8, 277, 12, 574, 304, 507, 198, 2632, 63, 1761, 275, 298, 1832, 1209, 15, 513, 1832, 1209, 83, 1001, 15, 1623, 2175, 63, 2102, 344, 2102, 25976, 495, 8, 585, 9, 507, 198, 2861, 2141, 275, 291, 14, 14270, 2532, 6417, 8, 2632, 63, 1761, 9, 507, 198, 692, 2615, 2141, 365, 440, 488, 26, 686, 198, 1107, 6263, 6712, 14, 739, 2422, 2532, 2141, 8, 2861, 2141, 9, 686, 421, 2742, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 5680, 4046, 687, 1978, 665, 785, 576, 5503, 14, 647, 30, 199, 5680, 199, 3, 20089, 1157, 22547, 22813, 23743, 520, 1050, 642, 370, 314, 4396, 826, 4343, 647, 2, 570, 26, 199, 3, 221, 636, 452, 363, 275, 2097, 576, 5503, 401, 2263, 2360, 221, 199, 3, 198, 198, 2, 1832, 1209, 576, 5503, 14, 5339, 1209, 1451, 5929, 401, 298, 1832, 1209, 576, 5503, 14, 5339, 1209, 9653, 6816, 322, 5907, 2, 199, 3, 198, 61, 199, 5680, 199, 199, 504, 1275, 576, 5503, 492, 3918, 5929, 12, 14587, 6816, 322, 5907, 199, 504, 1709, 14, 1832, 1209, 1685, 492, 6263, 6712, 199, 199, 624, 5339, 390, 5741, 655, 6463, 867, 23487, 2793, 78, 5741, 397, 477, 3421, 199, 624, 199, 533, 6263, 6712, 1451, 5929, 8, 1451, 5929, 304, 8299, 198, 318, 636, 826, 721, 277, 304, 507, 198, 1451, 5929, 855, 826, 721, 277, 12, 298, 2102, 5885, 63, 1832, 1175, 401, 298, 2102, 344, 2102, 401, 2097, 2102, 344, 2102, 401, 298, 320, 429, 10472, 676, 401, 298, 2102, 78, 348, 292, 401, 298, 2102, 78, 348, 265, 3135, 18118, 198, 318, 664, 2422, 14941, 8, 277, 304, 507, 198, 2861, 2141, 275, 3918, 5929, 14, 31359, 14941, 8, 277, 9, 507, 198, 1107, 6263, 6712, 14, 739, 2422, 2532, 2141, 8, 2861, 2141, 9, 8299, 198, 318, 9236, 1451, 8, 277, 12, 1245, 63, 5491, 275, 488, 304, 507, 198, 452, 11188, 275, 6263, 6712, 9653, 6816, 322, 5907, 1252, 14270, 2422, 342, 507, 198, 692, 1006, 11188, 365, 488, 26, 686, 198, 1107, 488, 507, 198, 277, 14, 18254, 3186, 8, 1188, 63, 5491, 9, 507, 198, 509, 376, 1692, 315, 1006, 11188, 14, 13012, 837, 686, 198, 1001, 63, 576, 275, 469, 298, 2102, 344, 2102, 2, 520, 376, 1692, 14, 2102, 344, 2102, 12, 298, 320, 429, 10472, 676, 2, 520, 376, 1692, 14, 320, 429, 10472, 676, 12, 298, 2102, 78, 348, 292, 2, 520, 376, 1692, 14, 2102, 78, 348, 292, 12, 298, 2102, 78, 348, 265, 2, 520, 376, 1692, 14, 2102, 78, 348, 265, 789, 686, 198, 277, 14, 3176, 1451, 8, 1001, 63, 576, 12, 1245, 63, 5491, 9, 4388, 198, 318, 3354, 2844, 4152, 8, 277, 12, 376, 1692, 12, 1245, 63, 5491, 275, 488, 304, 507, 198, 1001, 63, 576, 275, 469, 298, 2102, 344, 2102, 2, 520, 376, 1692, 14, 2102, 344, 2102, 12, 298, 320, 429, 10472, 676, 2, 520, 376, 1692, 14, 320, 429, 10472, 676, 12, 298, 2102, 78, 348, 292, 2, 520, 376, 1692, 14, 2102, 78, 348, 292, 12, 298, 2102, 78, 348, 265, 2, 520, 376, 1692, 14, 2102, 78, 348, 265, 789, 507, 198, 692, 376, 1692, 14, 2102, 344, 2102, 365, 488, 26, 686, 198, 290, 1692, 14, 2102, 344, 2102, 275, 291, 14, 3176, 1451, 8, 1001, 63, 576, 12, 1245, 63, 5491, 9, 507, 198, 2836, 26, 686, 198, 277, 14, 873, 1451, 8, 1001, 63, 576, 12, 1245, 63, 5491, 9, 2742, 421, 198, 3, 664, 1006, 665, 5339, 390, 5741, 30, 701, 665, 41, 2433, 867, 6244, 1808, 665, 2102, 344, 2102, 30, 199, 198, 318, 664, 2422, 14941, 2175, 63, 2102, 344, 2102, 8, 277, 12, 574, 304, 507, 198, 2861, 2141, 275, 3918, 5929, 14, 31359, 14941, 13317, 8, 277, 12, 298, 2102, 344, 2102, 401, 574, 9, 507, 198, 1107, 6263, 6712, 14, 739, 2422, 2532, 2141, 8, 2861, 2141, 9, 686, 421, 199, 533, 6263, 6712, 9653, 6816, 322, 5907, 8, 9653, 6816, 322, 5907, 304, 8299, 198, 318, 636, 826, 721, 277, 304, 507, 198, 9653, 6816, 322, 5907, 855, 826, 721, 277, 9, 18118, 198, 318, 8044, 2422, 8, 277, 304, 507, 198, 2632, 63, 1761, 275, 298, 1832, 1209, 15, 513, 1832, 1209, 83, 1001, 2, 507, 198, 2861, 2141, 275, 291, 14, 14270, 2532, 6417, 8, 2632, 63, 1761, 9, 507, 198, 692, 2615, 2141, 365, 440, 488, 26, 686, 198, 1107, 6263, 6712, 14, 739, 2422, 2532, 2141, 8, 2861, 2141, 9, 4388, 198, 3, 664, 1006, 665, 5339, 390, 5741, 30, 701, 665, 41, 2433, 867, 6244, 1808, 665, 2102, 344, 2102, 30, 199, 198, 318, 8044, 2422, 2175, 63, 2102, 344, 2102, 8, 277, 12, 574, 304, 507, 198, 2632, 63, 1761, 275, 298, 1832, 1209, 15, 513, 1832, 1209, 83, 1001, 15, 1623, 2175, 63, 2102, 344, 2102, 25976, 495, 8, 585, 9, 507, 198, 2861, 2141, 275, 291, 14, 14270, 2532, 6417, 8, 2632, 63, 1761, 9, 507, 198, 692, 2615, 2141, 365, 440, 488, 26, 686, 198, 1107, 6263, 6712, 14, 739, 2422, 2532, 2141, 8, 2861, 2141, 9, 686, 421, 2742, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 ]
whip112/Whip112
vendor/packages/translate/misc/progressbar.py
26
4765
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2004, 2005, 2010 Zuza Software Foundation # # This file is part of translate. # # translate 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. # # translate 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 this program; if not, see <http://www.gnu.org/licenses/>. """Progress bar utilities for reporting feedback on the progress of an application.""" class DotsProgressBar: """An ultra-simple progress indicator that just writes a dot for each action""" def __init__(self): import sys self.stderr = sys.stderr self.amount = 0 def show(self, verbosemessage): """show a dot for progress :-)""" # pylint: disable=W0613 self.stderr.write('.') self.stderr.flush() def close(self): self.stderr.write('\n') self.stderr.flush() def __del__(self): self.close() class NoProgressBar: """An invisible indicator that does nothing.""" def __init__(self): self.amount = 0 def show(self, verbosemessage): """show nothing for progress :-)""" pass def close(self): pass class ProgressBar: """A plain progress bar that doesn't know very much about output.""" def __init__(self, minValue=0, maxValue=100, totalWidth=50): self.progBar = "[]" # This holds the progress bar string self.min = minValue self.max = maxValue self.span = maxValue - minValue self.width = totalWidth self.amount = 0 # When amount == max, we are 100% done def __str__(self): """Produces the string representing the progress bar.""" if self.amount < self.min: self.amount = self.min if self.amount > self.max: self.amount = self.max # Figure out the new percent done, round to an integer diffFromMin = float(self.amount - self.min) percentDone = (diffFromMin / float(self.span)) * 100.0 percentDone = round(percentDone) percentDone = int(percentDone) # Figure out how many hash bars the percentage should be allFull = self.width - 7 numHashes = (percentDone / 100.0) * allFull numHashes = int(round(numHashes)) # build a progress bar with hashes and spaces self.progBar = "[%s%s] %3d%%" % ('#' * numHashes, ' ' * (allFull - numHashes), percentDone) return str(self.progBar) def show(self, verbosemessage): """displays the progress bar""" # pylint: disable=W0613 print(self) class MessageProgressBar(ProgressBar): """A ProgressBar that just writes out the messages without any progress display""" def __init__(self, *args, **kwargs): import sys self.sys = sys ProgressBar.__init__(self, *args, **kwargs) def show(self, verbosemessage): self.sys.stderr.write(verbosemessage + '\n') self.sys.stderr.flush() class HashProgressBar(ProgressBar): """A ProgressBar which knows how to go back to the beginning of the line.""" def __init__(self, *args, **kwargs): import sys self.sys = sys ProgressBar.__init__(self, *args, **kwargs) def show(self, verbosemessage): self.sys.stderr.write(str(self) + '\r') self.sys.stderr.flush() def close(self): self.sys.stderr.write('\n') self.sys.stderr.flush() def __del__(self): self.close() class VerboseProgressBar(HashProgressBar): def __init__(self, *args, **kwargs): self.lastwidth = 0 HashProgressBar.__init__(self, *args, **kwargs) def show(self, verbosemessage): output = str(self) self.sys.stderr.write('\r' + ' ' * self.lastwidth) self.sys.stderr.write('\r' + verbosemessage + '\n') self.lastwidth = len(output) self.sys.stderr.write('\r' + output) self.sys.stderr.flush() def test(progressbar): import time for n in range(progressbar.min, progressbar.max + 1, 5): progressbar.amount = n progressbar.show("Some message") time.sleep(0.2) if __name__ == '__main__': p = HashProgressBar(0, 100, 50) test(p)
mpl-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 8353, 12, 11811, 12, 7129, 3107, 85, 8076, 2290, 2752, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 9028, 14, 199, 3, 199, 3, 9028, 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, 9028, 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, 642, 2240, 27, 340, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 624, 11504, 4681, 15841, 367, 17290, 17145, 641, 314, 6696, 402, 376, 199, 3578, 1041, 421, 199, 533, 577, 16673, 11504, 5281, 26, 272, 408, 2493, 221, 427, 345, 13, 4129, 6696, 16385, 626, 2951, 14511, 282, 6308, 367, 1924, 272, 1595, 624, 339, 347, 636, 826, 721, 277, 304, 267, 492, 984, 267, 291, 14, 3083, 275, 984, 14, 3083, 267, 291, 14, 4606, 275, 378, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 408, 2384, 282, 6308, 367, 6696, 22901, 9471, 267, 327, 4287, 26, 3507, 29, 55, 1690, 969, 267, 291, 14, 3083, 14, 952, 7563, 267, 291, 14, 3083, 14, 4939, 342, 339, 347, 4002, 8, 277, 304, 267, 291, 14, 3083, 14, 952, 2258, 78, 358, 267, 291, 14, 3083, 14, 4939, 342, 339, 347, 636, 2264, 721, 277, 304, 267, 291, 14, 1600, 342, 421, 199, 533, 3091, 11504, 5281, 26, 272, 408, 2493, 315, 6604, 16385, 626, 1630, 6548, 1041, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 4606, 275, 378, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 408, 2384, 6548, 367, 6696, 22901, 9471, 267, 986, 339, 347, 4002, 8, 277, 304, 267, 986, 421, 199, 533, 21211, 5281, 26, 272, 408, 33, 8971, 6696, 4681, 626, 3181, 1133, 5715, 7437, 8298, 3595, 1072, 1041, 339, 347, 636, 826, 721, 277, 12, 1748, 1110, 29, 16, 12, 1390, 1110, 29, 1960, 12, 3141, 6216, 29, 1400, 304, 267, 291, 14, 6595, 5281, 275, 7369, 8480, 257, 327, 961, 15164, 314, 6696, 4681, 1059, 267, 291, 14, 827, 275, 1748, 1110, 267, 291, 14, 988, 275, 1390, 1110, 267, 291, 14, 3751, 275, 1390, 1110, 446, 1748, 1110, 267, 291, 14, 2063, 275, 3141, 6216, 267, 291, 14, 4606, 275, 378, 755, 327, 3979, 5982, 508, 1390, 12, 781, 787, 2948, 5, 4224, 339, 347, 636, 495, 721, 277, 304, 267, 408, 919, 10569, 314, 1059, 6144, 314, 6696, 4681, 1041, 267, 340, 291, 14, 4606, 665, 291, 14, 827, 26, 288, 291, 14, 4606, 275, 291, 14, 827, 267, 340, 291, 14, 4606, 690, 291, 14, 988, 26, 288, 291, 14, 4606, 275, 291, 14, 988, 398, 327, 16266, 734, 314, 892, 8878, 4224, 12, 6168, 370, 376, 3000, 267, 3915, 2532, 4649, 275, 2069, 8, 277, 14, 4606, 446, 291, 14, 827, 9, 267, 8878, 10759, 275, 334, 3028, 2532, 4649, 1182, 2069, 8, 277, 14, 3751, 430, 627, 2948, 14, 16, 267, 8878, 10759, 275, 6168, 8, 7045, 10759, 9, 267, 8878, 10759, 275, 1109, 8, 7045, 10759, 9, 398, 327, 16266, 734, 4212, 5002, 2631, 29130, 314, 16327, 1077, 506, 267, 1006, 9042, 275, 291, 14, 2063, 446, 1520, 267, 1967, 31660, 275, 334, 7045, 10759, 1182, 2948, 14, 16, 9, 627, 1006, 9042, 267, 1967, 31660, 275, 1109, 8, 2363, 8, 1507, 31660, 430, 398, 327, 1900, 282, 6696, 4681, 543, 14647, 436, 7883, 267, 291, 14, 6595, 5281, 275, 26503, 83, 5, 83, 61, 450, 19, 68, 8530, 2, 450, 661, 19367, 627, 1967, 31660, 12, 1460, 283, 283, 627, 334, 452, 9042, 446, 1967, 31660, 395, 1460, 8878, 10759, 9, 267, 372, 620, 8, 277, 14, 6595, 5281, 9, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 408, 13654, 9316, 314, 6696, 4681, 624, 267, 327, 4287, 26, 3507, 29, 55, 1690, 969, 267, 870, 8, 277, 9, 421, 199, 533, 6430, 11504, 5281, 8, 11504, 5281, 304, 272, 408, 33, 21211, 5281, 626, 2951, 14511, 734, 314, 3788, 1928, 1263, 6696, 272, 2929, 624, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 492, 984, 267, 291, 14, 1274, 275, 984, 267, 21211, 5281, 855, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 9, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 291, 14, 1274, 14, 3083, 14, 952, 8, 3832, 1188, 435, 1557, 78, 358, 267, 291, 14, 1274, 14, 3083, 14, 4939, 342, 421, 199, 533, 16101, 11504, 5281, 8, 11504, 5281, 304, 272, 408, 33, 21211, 5281, 1314, 19428, 4212, 370, 2621, 1771, 370, 314, 9608, 402, 314, 272, 1004, 1041, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 492, 984, 267, 291, 14, 1274, 275, 984, 267, 21211, 5281, 855, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 9, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 291, 14, 1274, 14, 3083, 14, 952, 8, 495, 8, 277, 9, 435, 1557, 82, 358, 267, 291, 14, 1274, 14, 3083, 14, 4939, 342, 339, 347, 4002, 8, 277, 304, 267, 291, 14, 1274, 14, 3083, 14, 952, 2258, 78, 358, 267, 291, 14, 1274, 14, 3083, 14, 4939, 342, 339, 347, 636, 2264, 721, 277, 304, 267, 291, 14, 1600, 342, 421, 199, 533, 5444, 2220, 11504, 5281, 8, 3476, 11504, 5281, 304, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 2019, 2063, 275, 378, 267, 16101, 11504, 5281, 855 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 8353, 12, 11811, 12, 7129, 3107, 85, 8076, 2290, 2752, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 9028, 14, 199, 3, 199, 3, 9028, 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, 9028, 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, 642, 2240, 27, 340, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 624, 11504, 4681, 15841, 367, 17290, 17145, 641, 314, 6696, 402, 376, 199, 3578, 1041, 421, 199, 533, 577, 16673, 11504, 5281, 26, 272, 408, 2493, 221, 427, 345, 13, 4129, 6696, 16385, 626, 2951, 14511, 282, 6308, 367, 1924, 272, 1595, 624, 339, 347, 636, 826, 721, 277, 304, 267, 492, 984, 267, 291, 14, 3083, 275, 984, 14, 3083, 267, 291, 14, 4606, 275, 378, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 408, 2384, 282, 6308, 367, 6696, 22901, 9471, 267, 327, 4287, 26, 3507, 29, 55, 1690, 969, 267, 291, 14, 3083, 14, 952, 7563, 267, 291, 14, 3083, 14, 4939, 342, 339, 347, 4002, 8, 277, 304, 267, 291, 14, 3083, 14, 952, 2258, 78, 358, 267, 291, 14, 3083, 14, 4939, 342, 339, 347, 636, 2264, 721, 277, 304, 267, 291, 14, 1600, 342, 421, 199, 533, 3091, 11504, 5281, 26, 272, 408, 2493, 315, 6604, 16385, 626, 1630, 6548, 1041, 339, 347, 636, 826, 721, 277, 304, 267, 291, 14, 4606, 275, 378, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 408, 2384, 6548, 367, 6696, 22901, 9471, 267, 986, 339, 347, 4002, 8, 277, 304, 267, 986, 421, 199, 533, 21211, 5281, 26, 272, 408, 33, 8971, 6696, 4681, 626, 3181, 1133, 5715, 7437, 8298, 3595, 1072, 1041, 339, 347, 636, 826, 721, 277, 12, 1748, 1110, 29, 16, 12, 1390, 1110, 29, 1960, 12, 3141, 6216, 29, 1400, 304, 267, 291, 14, 6595, 5281, 275, 7369, 8480, 257, 327, 961, 15164, 314, 6696, 4681, 1059, 267, 291, 14, 827, 275, 1748, 1110, 267, 291, 14, 988, 275, 1390, 1110, 267, 291, 14, 3751, 275, 1390, 1110, 446, 1748, 1110, 267, 291, 14, 2063, 275, 3141, 6216, 267, 291, 14, 4606, 275, 378, 755, 327, 3979, 5982, 508, 1390, 12, 781, 787, 2948, 5, 4224, 339, 347, 636, 495, 721, 277, 304, 267, 408, 919, 10569, 314, 1059, 6144, 314, 6696, 4681, 1041, 267, 340, 291, 14, 4606, 665, 291, 14, 827, 26, 288, 291, 14, 4606, 275, 291, 14, 827, 267, 340, 291, 14, 4606, 690, 291, 14, 988, 26, 288, 291, 14, 4606, 275, 291, 14, 988, 398, 327, 16266, 734, 314, 892, 8878, 4224, 12, 6168, 370, 376, 3000, 267, 3915, 2532, 4649, 275, 2069, 8, 277, 14, 4606, 446, 291, 14, 827, 9, 267, 8878, 10759, 275, 334, 3028, 2532, 4649, 1182, 2069, 8, 277, 14, 3751, 430, 627, 2948, 14, 16, 267, 8878, 10759, 275, 6168, 8, 7045, 10759, 9, 267, 8878, 10759, 275, 1109, 8, 7045, 10759, 9, 398, 327, 16266, 734, 4212, 5002, 2631, 29130, 314, 16327, 1077, 506, 267, 1006, 9042, 275, 291, 14, 2063, 446, 1520, 267, 1967, 31660, 275, 334, 7045, 10759, 1182, 2948, 14, 16, 9, 627, 1006, 9042, 267, 1967, 31660, 275, 1109, 8, 2363, 8, 1507, 31660, 430, 398, 327, 1900, 282, 6696, 4681, 543, 14647, 436, 7883, 267, 291, 14, 6595, 5281, 275, 26503, 83, 5, 83, 61, 450, 19, 68, 8530, 2, 450, 661, 19367, 627, 1967, 31660, 12, 1460, 283, 283, 627, 334, 452, 9042, 446, 1967, 31660, 395, 1460, 8878, 10759, 9, 267, 372, 620, 8, 277, 14, 6595, 5281, 9, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 408, 13654, 9316, 314, 6696, 4681, 624, 267, 327, 4287, 26, 3507, 29, 55, 1690, 969, 267, 870, 8, 277, 9, 421, 199, 533, 6430, 11504, 5281, 8, 11504, 5281, 304, 272, 408, 33, 21211, 5281, 626, 2951, 14511, 734, 314, 3788, 1928, 1263, 6696, 272, 2929, 624, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 492, 984, 267, 291, 14, 1274, 275, 984, 267, 21211, 5281, 855, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 9, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 291, 14, 1274, 14, 3083, 14, 952, 8, 3832, 1188, 435, 1557, 78, 358, 267, 291, 14, 1274, 14, 3083, 14, 4939, 342, 421, 199, 533, 16101, 11504, 5281, 8, 11504, 5281, 304, 272, 408, 33, 21211, 5281, 1314, 19428, 4212, 370, 2621, 1771, 370, 314, 9608, 402, 314, 272, 1004, 1041, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 492, 984, 267, 291, 14, 1274, 275, 984, 267, 21211, 5281, 855, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 9, 339, 347, 2498, 8, 277, 12, 3376, 1188, 304, 267, 291, 14, 1274, 14, 3083, 14, 952, 8, 495, 8, 277, 9, 435, 1557, 82, 358, 267, 291, 14, 1274, 14, 3083, 14, 4939, 342, 339, 347, 4002, 8, 277, 304, 267, 291, 14, 1274, 14, 3083, 14, 952, 2258, 78, 358, 267, 291, 14, 1274, 14, 3083, 14, 4939, 342, 339, 347, 636, 2264, 721, 277, 304, 267, 291, 14, 1600, 342, 421, 199, 533, 5444, 2220, 11504, 5281, 8, 3476, 11504, 5281, 304, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 2019, 2063, 275, 378, 267, 16101, 11504, 5281, 855, 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 ]
andrewhillcode/holo
src/reddit.py
2
1554
from logging import debug, info, error, exception import praw # Initialization _r = None _config = None def init_reddit(config): global _config _config = config def _connect_reddit(): if _config is None: error("Can't connect to reddit without a config") return None return praw.Reddit(client_id=_config.r_oauth_key, client_secret=_config.r_oauth_secret, username=_config.r_username, password=_config.r_password, user_agent=_config.useragent, check_for_updates=False) def _ensure_connection(): global _r if _r is None: _r = _connect_reddit() return _r is not None # Thing doing def submit_text_post(subreddit, title, body): _ensure_connection() try: info("Submitting post to {}".format(subreddit)) new_post = _r.subreddit(subreddit).submit(title, selftext=body, send_replies=False) return new_post except: exception("Failed to submit text post") return None #NOTE: PRAW3 stuff #def send_modmail(subreddit, title, body): # _ensure_connection() # _r.send_message("/r/"+subreddit, title, body) # #def send_pm(user, title, body, from_sr=None): # _ensure_connection() # _r.send_message(user, title, body, from_sr=from_sr) # #def reply_to(thing, body, distinguish=False): # _ensure_connection() # # reply = thing.reply(body) # # if distinguish and reply is not None: # response = reply.distinguish() # if len(response) > 0 and len(response["errors"]) > 0: # error("Failed to distinguish: {}".format(response["errors"])) # Utilities def get_shortlink_from_id(id): return "http://redd.it/{}".format(id)
mit
[ 504, 2050, 492, 3105, 12, 2256, 12, 1125, 12, 1919, 199, 646, 299, 1773, 199, 199, 3, 6026, 2072, 199, 199, 63, 82, 275, 488, 199, 63, 888, 275, 488, 199, 199, 318, 4205, 63, 18374, 8, 888, 304, 199, 198, 2966, 485, 888, 199, 198, 63, 888, 275, 1101, 199, 199, 318, 485, 2242, 63, 18374, 837, 199, 198, 692, 485, 888, 365, 488, 26, 507, 198, 705, 480, 6049, 1133, 4907, 370, 8992, 1741, 1928, 282, 1101, 531, 507, 198, 1107, 488, 8299, 198, 1107, 299, 1773, 14, 10858, 1741, 8, 1258, 63, 344, 3699, 888, 14, 82, 63, 6126, 63, 498, 12, 1890, 63, 4731, 3699, 888, 14, 82, 63, 6126, 63, 4731, 12, 1871, 198, 2473, 3699, 888, 14, 82, 63, 2473, 12, 2505, 3699, 888, 14, 82, 63, 2060, 12, 1871, 198, 751, 63, 4054, 3699, 888, 14, 751, 4054, 12, 1871, 198, 1074, 63, 509, 63, 7618, 29, 797, 9, 199, 199, 318, 485, 7505, 63, 2105, 837, 199, 198, 2966, 485, 82, 199, 198, 692, 485, 82, 365, 488, 26, 507, 198, 63, 82, 275, 485, 2242, 63, 18374, 342, 199, 198, 1107, 485, 82, 365, 440, 488, 199, 199, 3, 3868, 316, 9689, 199, 199, 318, 11482, 63, 505, 63, 1932, 8, 954, 18374, 12, 2538, 12, 2396, 304, 199, 198, 63, 7505, 63, 2105, 342, 199, 198, 893, 26, 507, 198, 815, 480, 17187, 1337, 2963, 370, 8352, 908, 8, 954, 18374, 430, 507, 198, 1222, 63, 1932, 275, 485, 82, 14, 954, 18374, 8, 954, 18374, 680, 7275, 8, 1213, 12, 291, 505, 29, 2030, 12, 3222, 63, 1155, 6528, 29, 797, 9, 507, 198, 1107, 892, 63, 1932, 199, 198, 2590, 26, 507, 198, 1971, 480, 4276, 370, 11482, 1318, 2963, 531, 507, 198, 1107, 488, 199, 199, 3, 19855, 26, 510, 4307, 19, 8292, 199, 3, 318, 3222, 63, 1494, 1198, 8, 954, 18374, 12, 2538, 12, 2396, 304, 199, 3, 198, 63, 7505, 63, 2105, 342, 199, 3, 198, 63, 82, 14, 2254, 63, 1188, 4769, 82, 25976, 954, 18374, 12, 2538, 12, 2396, 9, 199, 3, 199, 3, 318, 3222, 63, 7073, 8, 751, 12, 2538, 12, 2396, 12, 687, 63, 5474, 29, 403, 304, 199, 3, 198, 63, 7505, 63, 2105, 342, 199, 3, 198, 63, 82, 14, 2254, 63, 1188, 8, 751, 12, 2538, 12, 2396, 12, 687, 63, 5474, 29, 504, 63, 5474, 9, 199, 3, 199, 3, 318, 9351, 63, 475, 8, 2127, 12, 2396, 12, 22237, 29, 797, 304, 199, 3, 198, 63, 7505, 63, 2105, 342, 199, 3, 198, 199, 3, 198, 8102, 275, 8377, 14, 8102, 8, 2030, 9, 199, 3, 198, 199, 3, 198, 692, 22237, 436, 9351, 365, 440, 488, 26, 199, 3, 198, 198, 1310, 275, 9351, 14, 2686, 17603, 342, 199, 3, 198, 198, 692, 822, 8, 1310, 9, 690, 378, 436, 822, 8, 1310, 905, 2550, 3135, 690, 378, 26, 199, 3, 1057, 198, 705, 480, 4276, 370, 22237, 26, 8352, 908, 8, 1310, 905, 2550, 13045, 199, 199, 3, 738, 17933, 199, 199, 318, 664, 63, 3612, 1073, 63, 504, 63, 344, 8, 344, 304, 199, 198, 1107, 298, 1014, 921, 581, 68, 14, 390, 15, 13536, 908, 8, 344, 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 ]
[ 2050, 492, 3105, 12, 2256, 12, 1125, 12, 1919, 199, 646, 299, 1773, 199, 199, 3, 6026, 2072, 199, 199, 63, 82, 275, 488, 199, 63, 888, 275, 488, 199, 199, 318, 4205, 63, 18374, 8, 888, 304, 199, 198, 2966, 485, 888, 199, 198, 63, 888, 275, 1101, 199, 199, 318, 485, 2242, 63, 18374, 837, 199, 198, 692, 485, 888, 365, 488, 26, 507, 198, 705, 480, 6049, 1133, 4907, 370, 8992, 1741, 1928, 282, 1101, 531, 507, 198, 1107, 488, 8299, 198, 1107, 299, 1773, 14, 10858, 1741, 8, 1258, 63, 344, 3699, 888, 14, 82, 63, 6126, 63, 498, 12, 1890, 63, 4731, 3699, 888, 14, 82, 63, 6126, 63, 4731, 12, 1871, 198, 2473, 3699, 888, 14, 82, 63, 2473, 12, 2505, 3699, 888, 14, 82, 63, 2060, 12, 1871, 198, 751, 63, 4054, 3699, 888, 14, 751, 4054, 12, 1871, 198, 1074, 63, 509, 63, 7618, 29, 797, 9, 199, 199, 318, 485, 7505, 63, 2105, 837, 199, 198, 2966, 485, 82, 199, 198, 692, 485, 82, 365, 488, 26, 507, 198, 63, 82, 275, 485, 2242, 63, 18374, 342, 199, 198, 1107, 485, 82, 365, 440, 488, 199, 199, 3, 3868, 316, 9689, 199, 199, 318, 11482, 63, 505, 63, 1932, 8, 954, 18374, 12, 2538, 12, 2396, 304, 199, 198, 63, 7505, 63, 2105, 342, 199, 198, 893, 26, 507, 198, 815, 480, 17187, 1337, 2963, 370, 8352, 908, 8, 954, 18374, 430, 507, 198, 1222, 63, 1932, 275, 485, 82, 14, 954, 18374, 8, 954, 18374, 680, 7275, 8, 1213, 12, 291, 505, 29, 2030, 12, 3222, 63, 1155, 6528, 29, 797, 9, 507, 198, 1107, 892, 63, 1932, 199, 198, 2590, 26, 507, 198, 1971, 480, 4276, 370, 11482, 1318, 2963, 531, 507, 198, 1107, 488, 199, 199, 3, 19855, 26, 510, 4307, 19, 8292, 199, 3, 318, 3222, 63, 1494, 1198, 8, 954, 18374, 12, 2538, 12, 2396, 304, 199, 3, 198, 63, 7505, 63, 2105, 342, 199, 3, 198, 63, 82, 14, 2254, 63, 1188, 4769, 82, 25976, 954, 18374, 12, 2538, 12, 2396, 9, 199, 3, 199, 3, 318, 3222, 63, 7073, 8, 751, 12, 2538, 12, 2396, 12, 687, 63, 5474, 29, 403, 304, 199, 3, 198, 63, 7505, 63, 2105, 342, 199, 3, 198, 63, 82, 14, 2254, 63, 1188, 8, 751, 12, 2538, 12, 2396, 12, 687, 63, 5474, 29, 504, 63, 5474, 9, 199, 3, 199, 3, 318, 9351, 63, 475, 8, 2127, 12, 2396, 12, 22237, 29, 797, 304, 199, 3, 198, 63, 7505, 63, 2105, 342, 199, 3, 198, 199, 3, 198, 8102, 275, 8377, 14, 8102, 8, 2030, 9, 199, 3, 198, 199, 3, 198, 692, 22237, 436, 9351, 365, 440, 488, 26, 199, 3, 198, 198, 1310, 275, 9351, 14, 2686, 17603, 342, 199, 3, 198, 198, 692, 822, 8, 1310, 9, 690, 378, 436, 822, 8, 1310, 905, 2550, 3135, 690, 378, 26, 199, 3, 1057, 198, 705, 480, 4276, 370, 22237, 26, 8352, 908, 8, 1310, 905, 2550, 13045, 199, 199, 3, 738, 17933, 199, 199, 318, 664, 63, 3612, 1073, 63, 504, 63, 344, 8, 344, 304, 199, 198, 1107, 298, 1014, 921, 581, 68, 14, 390, 15, 13536, 908, 8, 344, 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, 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, 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 ]
securechain/securechain-wallet
contrib/testgen/gen_base58_test_vectors.py
1000
4343
#!/usr/bin/env python ''' Generate valid and invalid base58 address and private key test vectors. Usage: gen_base58_test_vectors.py valid 50 > ../../src/test/data/base58_keys_valid.json gen_base58_test_vectors.py invalid 50 > ../../src/test/data/base58_keys_invalid.json ''' # 2012 Wladimir J. van der Laan # Released under MIT License import os from itertools import islice from base58 import b58encode, b58decode, b58encode_chk, b58decode_chk, b58chars import random from binascii import b2a_hex # key types PUBKEY_ADDRESS = 0 SCRIPT_ADDRESS = 5 PUBKEY_ADDRESS_TEST = 111 SCRIPT_ADDRESS_TEST = 196 PRIVKEY = 128 PRIVKEY_TEST = 239 metadata_keys = ['isPrivkey', 'isTestnet', 'addrType', 'isCompressed'] # templates for valid sequences templates = [ # prefix, payload_size, suffix, metadata # None = N/A ((PUBKEY_ADDRESS,), 20, (), (False, False, 'pubkey', None)), ((SCRIPT_ADDRESS,), 20, (), (False, False, 'script', None)), ((PUBKEY_ADDRESS_TEST,), 20, (), (False, True, 'pubkey', None)), ((SCRIPT_ADDRESS_TEST,), 20, (), (False, True, 'script', None)), ((PRIVKEY,), 32, (), (True, False, None, False)), ((PRIVKEY,), 32, (1,), (True, False, None, True)), ((PRIVKEY_TEST,), 32, (), (True, True, None, False)), ((PRIVKEY_TEST,), 32, (1,), (True, True, None, True)) ] def is_valid(v): '''Check vector v for validity''' result = b58decode_chk(v) if result is None: return False valid = False for template in templates: prefix = str(bytearray(template[0])) suffix = str(bytearray(template[2])) if result.startswith(prefix) and result.endswith(suffix): if (len(result) - len(prefix) - len(suffix)) == template[1]: return True return False def gen_valid_vectors(): '''Generate valid test vectors''' while True: for template in templates: prefix = str(bytearray(template[0])) payload = os.urandom(template[1]) suffix = str(bytearray(template[2])) rv = b58encode_chk(prefix + payload + suffix) assert is_valid(rv) metadata = dict([(x,y) for (x,y) in zip(metadata_keys,template[3]) if y is not None]) yield (rv, b2a_hex(payload), metadata) def gen_invalid_vector(template, corrupt_prefix, randomize_payload_size, corrupt_suffix): '''Generate possibly invalid vector''' if corrupt_prefix: prefix = os.urandom(1) else: prefix = str(bytearray(template[0])) if randomize_payload_size: payload = os.urandom(max(int(random.expovariate(0.5)), 50)) else: payload = os.urandom(template[1]) if corrupt_suffix: suffix = os.urandom(len(template[2])) else: suffix = str(bytearray(template[2])) return b58encode_chk(prefix + payload + suffix) def randbool(p = 0.5): '''Return True with P(p)''' return random.random() < p def gen_invalid_vectors(): '''Generate invalid test vectors''' # start with some manual edge-cases yield "", yield "x", while True: # kinds of invalid vectors: # invalid prefix # invalid payload length # invalid (randomized) suffix (add random data) # corrupt checksum for template in templates: val = gen_invalid_vector(template, randbool(0.2), randbool(0.2), randbool(0.2)) if random.randint(0,10)<1: # line corruption if randbool(): # add random character to end val += random.choice(b58chars) else: # replace random character in the middle n = random.randint(0, len(val)) val = val[0:n] + random.choice(b58chars) + val[n+1:] if not is_valid(val): yield val, if __name__ == '__main__': import sys, json iters = {'valid':gen_valid_vectors, 'invalid':gen_invalid_vectors} try: uiter = iters[sys.argv[1]] except IndexError: uiter = gen_valid_vectors try: count = int(sys.argv[2]) except IndexError: count = 0 data = list(islice(uiter(), count)) json.dump(data, sys.stdout, sort_keys=True, indent=4) sys.stdout.write('\n')
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 2344, 199, 6864, 1686, 436, 3866, 1300, 2010, 2287, 436, 5726, 790, 511, 11102, 14, 199, 199, 7692, 26, 5591, 3805, 63, 1095, 2010, 63, 396, 63, 12280, 14, 647, 1686, 5238, 690, 24272, 5093, 2164, 15, 396, 15, 576, 15, 1095, 2010, 63, 1612, 63, 1078, 14, 1001, 272, 3805, 63, 1095, 2010, 63, 396, 63, 12280, 14, 647, 3866, 5238, 690, 24272, 5093, 2164, 15, 396, 15, 576, 15, 1095, 2010, 63, 1612, 63, 3197, 14, 1001, 199, 2344, 199, 3, 6029, 644, 416, 3572, 723, 1603, 14, 20744, 16921, 7964, 290, 199, 3, 17646, 68, 1334, 10697, 844, 199, 646, 747, 199, 504, 7975, 492, 365, 3037, 199, 504, 1300, 2010, 492, 330, 2010, 2143, 12, 330, 2010, 2708, 12, 330, 2010, 2143, 63, 14823, 12, 330, 2010, 2708, 63, 14823, 12, 330, 2010, 6574, 199, 646, 2196, 199, 504, 14755, 492, 330, 18, 65, 63, 4097, 199, 199, 3, 790, 2943, 199, 13047, 3078, 63, 12368, 275, 378, 199, 10484, 63, 12368, 275, 959, 199, 13047, 3078, 63, 12368, 63, 2864, 275, 20128, 199, 10484, 63, 12368, 63, 2864, 275, 32132, 199, 13420, 3078, 275, 7960, 199, 13420, 3078, 63, 2864, 275, 499, 1355, 199, 199, 2343, 63, 1612, 275, 788, 374, 4562, 86, 498, 297, 283, 374, 774, 846, 297, 283, 2697, 804, 297, 283, 374, 25428, 418, 199, 3, 7009, 367, 1686, 8013, 199, 5876, 275, 359, 523, 327, 2403, 12, 4886, 63, 890, 12, 4739, 12, 3341, 523, 327, 22456, 488, 275, 653, 15, 33, 523, 3666, 13047, 3078, 63, 12368, 4706, 420, 3388, 12, 11969, 257, 334, 797, 12, 756, 12, 283, 17178, 297, 488, 1826, 523, 3666, 10484, 63, 12368, 4706, 420, 3388, 12, 11969, 257, 334, 797, 12, 756, 12, 283, 1579, 297, 221, 488, 1826, 523, 3666, 13047, 3078, 63, 12368, 63, 2864, 4706, 3388, 12, 11969, 257, 334, 797, 12, 715, 12, 221, 283, 17178, 297, 488, 1826, 523, 3666, 10484, 63, 12368, 63, 2864, 4706, 3388, 12, 11969, 257, 334, 797, 12, 715, 12, 221, 283, 1579, 297, 221, 488, 1826, 523, 3666, 13420, 3078, 4706, 3777, 4337, 12, 11969, 257, 334, 549, 12, 221, 756, 12, 488, 12, 221, 756, 1826, 523, 3666, 13420, 3078, 4706, 3777, 4337, 12, 334, 17, 4706, 334, 549, 12, 221, 756, 12, 488, 12, 221, 715, 1826, 523, 3666, 13420, 3078, 63, 2864, 4706, 263, 4337, 12, 11969, 257, 334, 549, 12, 221, 715, 12, 221, 488, 12, 221, 756, 1826, 523, 3666, 13420, 3078, 63, 2864, 4706, 263, 4337, 12, 334, 17, 4706, 334, 549, 12, 221, 715, 12, 221, 488, 12, 221, 715, 430, 199, 61, 199, 199, 318, 365, 63, 1078, 8, 86, 304, 272, 1449, 1799, 5477, 373, 367, 25667, 2344, 272, 754, 275, 330, 2010, 2708, 63, 14823, 8, 86, 9, 272, 340, 754, 365, 488, 26, 267, 372, 756, 272, 1686, 275, 756, 272, 367, 1978, 315, 7009, 26, 267, 2403, 275, 620, 8, 20108, 8, 1160, 59, 16, 2459, 267, 4739, 275, 620, 8, 20108, 8, 1160, 59, 18, 2459, 267, 340, 754, 14, 2460, 8, 1861, 9, 436, 754, 14, 4130, 8, 4511, 304, 288, 340, 334, 552, 8, 1099, 9, 446, 822, 8, 1861, 9, 446, 822, 8, 4511, 430, 508, 1978, 59, 17, 2189, 355, 372, 715, 272, 372, 756, 199, 199, 318, 3805, 63, 1078, 63, 12280, 837, 272, 1449, 6864, 1686, 511, 11102, 2344, 272, 1830, 715, 26, 267, 367, 1978, 315, 7009, 26, 288, 2403, 275, 620, 8, 20108, 8, 1160, 59, 16, 2459, 288, 4886, 275, 747, 14, 22776, 8, 1160, 59, 17, 566, 7205, 4739, 275, 620, 8, 20108, 8, 1160, 59, 18, 2459, 288, 4336, 275, 330, 2010, 2143, 63, 14823, 8, 1861, 435, 4886, 435, 4739, 9, 288, 702, 365, 63, 1078, 8, 6310, 9, 288, 3341, 275, 1211, 7694, 88, 12, 89, 9, 367, 334, 88, 12, 89, 9, 315, 3482, 8, 2343, 63, 1612, 12, 1160, 59, 19, 566, 340, 612, 365, 440, 488, 566, 288, 1995, 334, 6310, 12, 330, 18, 65, 63, 4097, 8, 4749, 395, 3341, 9, 199, 199, 318, 3805, 63, 3197, 63, 4106, 8, 1160, 12, 29221, 63, 1861, 12, 2196, 794, 63, 4749, 63, 890, 12, 29221, 63, 4511, 304, 272, 1449, 6864, 12570, 3866, 5477, 2344, 272, 340, 29221, 63, 1861, 26, 267, 2403, 275, 747, 14, 22776, 8, 17, 9, 272, 587, 26, 267, 2403, 275, 620, 8, 20108, 8, 1160, 59, 16, 2459, 2286, 340, 2196, 794, 63, 4749, 63, 890, 26, 267, 4886, 275, 747, 14, 22776, 8, 988, 8, 442, 8, 2355, 14, 476, 555, 13805, 8, 16, 14, 21, 1826, 5238, 430, 272, 587, 26, 267, 4886, 275, 747, 14, 22776, 8, 1160, 59, 17, 566, 2286, 340, 29221, 63, 4511, 26, 267, 4739, 275, 747, 14, 22776, 8, 552, 8, 1160, 59, 18, 2459, 272, 587, 26, 267, 4739, 275, 620, 8, 20108, 8, 1160, 59, 18, 2459, 339, 372, 330, 2010, 2143, 63, 14823, 8, 1861, 435, 4886, 435, 4739, 9, 199, 199, 318, 10261, 2245, 8, 80, 275, 378, 14, 21, 304, 272, 1449, 1767, 715, 543, 510, 8, 80, 9, 2344, 272, 372, 2196, 14, 2355, 342, 665, 299, 199, 199, 318, 3805, 63, 3197, 63, 12280, 837, 272, 1449, 6864, 3866, 511, 11102, 2344, 272, 327, 1343, 543, 2005, 8722, 6275, 13, 9403, 272, 1995, 4873, 272, 1995, 298, 88, 401, 272, 1830, 715, 26, 267, 327, 24241, 402, 3866, 11102, 26, 267, 327, 257, 3866, 2403, 267, 327, 257, 3866, 4886, 2582, 267, 327, 257, 3866, 334, 2355, 1759, 9, 4739, 334, 525, 2196, 666, 9, 267, 327, 257, 29221, 9040, 267, 367, 1978, 315, 7009, 26, 288, 1139, 275, 3805, 63, 3197, 63, 4106, 8, 1160, 12, 10261, 2245, 8, 16, 14, 18, 395, 10261, 2245, 8, 16, 14, 18, 395, 10261, 2245, 8, 16, 14, 18, 430, 288, 340, 2196, 14, 8393, 8, 16, 12, 709, 21528, 17, 26, 327, 1004, 1970, 5505, 296, 355, 340, 10261, 2245, 837, 327, 1050, 2196, 4528, 370, 1284, 490, 1139, 847, 2196, 14, 5095, 8, 66, 2010, 6574, 9, 355 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 2344, 199, 6864, 1686, 436, 3866, 1300, 2010, 2287, 436, 5726, 790, 511, 11102, 14, 199, 199, 7692, 26, 5591, 3805, 63, 1095, 2010, 63, 396, 63, 12280, 14, 647, 1686, 5238, 690, 24272, 5093, 2164, 15, 396, 15, 576, 15, 1095, 2010, 63, 1612, 63, 1078, 14, 1001, 272, 3805, 63, 1095, 2010, 63, 396, 63, 12280, 14, 647, 3866, 5238, 690, 24272, 5093, 2164, 15, 396, 15, 576, 15, 1095, 2010, 63, 1612, 63, 3197, 14, 1001, 199, 2344, 199, 3, 6029, 644, 416, 3572, 723, 1603, 14, 20744, 16921, 7964, 290, 199, 3, 17646, 68, 1334, 10697, 844, 199, 646, 747, 199, 504, 7975, 492, 365, 3037, 199, 504, 1300, 2010, 492, 330, 2010, 2143, 12, 330, 2010, 2708, 12, 330, 2010, 2143, 63, 14823, 12, 330, 2010, 2708, 63, 14823, 12, 330, 2010, 6574, 199, 646, 2196, 199, 504, 14755, 492, 330, 18, 65, 63, 4097, 199, 199, 3, 790, 2943, 199, 13047, 3078, 63, 12368, 275, 378, 199, 10484, 63, 12368, 275, 959, 199, 13047, 3078, 63, 12368, 63, 2864, 275, 20128, 199, 10484, 63, 12368, 63, 2864, 275, 32132, 199, 13420, 3078, 275, 7960, 199, 13420, 3078, 63, 2864, 275, 499, 1355, 199, 199, 2343, 63, 1612, 275, 788, 374, 4562, 86, 498, 297, 283, 374, 774, 846, 297, 283, 2697, 804, 297, 283, 374, 25428, 418, 199, 3, 7009, 367, 1686, 8013, 199, 5876, 275, 359, 523, 327, 2403, 12, 4886, 63, 890, 12, 4739, 12, 3341, 523, 327, 22456, 488, 275, 653, 15, 33, 523, 3666, 13047, 3078, 63, 12368, 4706, 420, 3388, 12, 11969, 257, 334, 797, 12, 756, 12, 283, 17178, 297, 488, 1826, 523, 3666, 10484, 63, 12368, 4706, 420, 3388, 12, 11969, 257, 334, 797, 12, 756, 12, 283, 1579, 297, 221, 488, 1826, 523, 3666, 13047, 3078, 63, 12368, 63, 2864, 4706, 3388, 12, 11969, 257, 334, 797, 12, 715, 12, 221, 283, 17178, 297, 488, 1826, 523, 3666, 10484, 63, 12368, 63, 2864, 4706, 3388, 12, 11969, 257, 334, 797, 12, 715, 12, 221, 283, 1579, 297, 221, 488, 1826, 523, 3666, 13420, 3078, 4706, 3777, 4337, 12, 11969, 257, 334, 549, 12, 221, 756, 12, 488, 12, 221, 756, 1826, 523, 3666, 13420, 3078, 4706, 3777, 4337, 12, 334, 17, 4706, 334, 549, 12, 221, 756, 12, 488, 12, 221, 715, 1826, 523, 3666, 13420, 3078, 63, 2864, 4706, 263, 4337, 12, 11969, 257, 334, 549, 12, 221, 715, 12, 221, 488, 12, 221, 756, 1826, 523, 3666, 13420, 3078, 63, 2864, 4706, 263, 4337, 12, 334, 17, 4706, 334, 549, 12, 221, 715, 12, 221, 488, 12, 221, 715, 430, 199, 61, 199, 199, 318, 365, 63, 1078, 8, 86, 304, 272, 1449, 1799, 5477, 373, 367, 25667, 2344, 272, 754, 275, 330, 2010, 2708, 63, 14823, 8, 86, 9, 272, 340, 754, 365, 488, 26, 267, 372, 756, 272, 1686, 275, 756, 272, 367, 1978, 315, 7009, 26, 267, 2403, 275, 620, 8, 20108, 8, 1160, 59, 16, 2459, 267, 4739, 275, 620, 8, 20108, 8, 1160, 59, 18, 2459, 267, 340, 754, 14, 2460, 8, 1861, 9, 436, 754, 14, 4130, 8, 4511, 304, 288, 340, 334, 552, 8, 1099, 9, 446, 822, 8, 1861, 9, 446, 822, 8, 4511, 430, 508, 1978, 59, 17, 2189, 355, 372, 715, 272, 372, 756, 199, 199, 318, 3805, 63, 1078, 63, 12280, 837, 272, 1449, 6864, 1686, 511, 11102, 2344, 272, 1830, 715, 26, 267, 367, 1978, 315, 7009, 26, 288, 2403, 275, 620, 8, 20108, 8, 1160, 59, 16, 2459, 288, 4886, 275, 747, 14, 22776, 8, 1160, 59, 17, 566, 7205, 4739, 275, 620, 8, 20108, 8, 1160, 59, 18, 2459, 288, 4336, 275, 330, 2010, 2143, 63, 14823, 8, 1861, 435, 4886, 435, 4739, 9, 288, 702, 365, 63, 1078, 8, 6310, 9, 288, 3341, 275, 1211, 7694, 88, 12, 89, 9, 367, 334, 88, 12, 89, 9, 315, 3482, 8, 2343, 63, 1612, 12, 1160, 59, 19, 566, 340, 612, 365, 440, 488, 566, 288, 1995, 334, 6310, 12, 330, 18, 65, 63, 4097, 8, 4749, 395, 3341, 9, 199, 199, 318, 3805, 63, 3197, 63, 4106, 8, 1160, 12, 29221, 63, 1861, 12, 2196, 794, 63, 4749, 63, 890, 12, 29221, 63, 4511, 304, 272, 1449, 6864, 12570, 3866, 5477, 2344, 272, 340, 29221, 63, 1861, 26, 267, 2403, 275, 747, 14, 22776, 8, 17, 9, 272, 587, 26, 267, 2403, 275, 620, 8, 20108, 8, 1160, 59, 16, 2459, 2286, 340, 2196, 794, 63, 4749, 63, 890, 26, 267, 4886, 275, 747, 14, 22776, 8, 988, 8, 442, 8, 2355, 14, 476, 555, 13805, 8, 16, 14, 21, 1826, 5238, 430, 272, 587, 26, 267, 4886, 275, 747, 14, 22776, 8, 1160, 59, 17, 566, 2286, 340, 29221, 63, 4511, 26, 267, 4739, 275, 747, 14, 22776, 8, 552, 8, 1160, 59, 18, 2459, 272, 587, 26, 267, 4739, 275, 620, 8, 20108, 8, 1160, 59, 18, 2459, 339, 372, 330, 2010, 2143, 63, 14823, 8, 1861, 435, 4886, 435, 4739, 9, 199, 199, 318, 10261, 2245, 8, 80, 275, 378, 14, 21, 304, 272, 1449, 1767, 715, 543, 510, 8, 80, 9, 2344, 272, 372, 2196, 14, 2355, 342, 665, 299, 199, 199, 318, 3805, 63, 3197, 63, 12280, 837, 272, 1449, 6864, 3866, 511, 11102, 2344, 272, 327, 1343, 543, 2005, 8722, 6275, 13, 9403, 272, 1995, 4873, 272, 1995, 298, 88, 401, 272, 1830, 715, 26, 267, 327, 24241, 402, 3866, 11102, 26, 267, 327, 257, 3866, 2403, 267, 327, 257, 3866, 4886, 2582, 267, 327, 257, 3866, 334, 2355, 1759, 9, 4739, 334, 525, 2196, 666, 9, 267, 327, 257, 29221, 9040, 267, 367, 1978, 315, 7009, 26, 288, 1139, 275, 3805, 63, 3197, 63, 4106, 8, 1160, 12, 10261, 2245, 8, 16, 14, 18, 395, 10261, 2245, 8, 16, 14, 18, 395, 10261, 2245, 8, 16, 14, 18, 430, 288, 340, 2196, 14, 8393, 8, 16, 12, 709, 21528, 17, 26, 327, 1004, 1970, 5505, 296, 355, 340, 10261, 2245, 837, 327, 1050, 2196, 4528, 370, 1284, 490, 1139, 847, 2196, 14, 5095, 8, 66, 2010, 6574, 9, 355, 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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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 ]
isandlaTech/cohorte-demos
led/dump/led-demo-raspberry/cohorte/dist/cohorte-1.0.0-1.0.0-20141201.234602-19-python-distribution/repo/bundles/herald/__init__.py
4
3210
#!/usr/bin/env python # -- Content-Encoding: UTF-8 -- """ Herald core package :author: Thomas Calmant :copyright: Copyright 2014, isandlaTech :license: Apache License 2.0 :version: 0.0.2.dev :status: Alpha .. Copyright 2014 isandlaTech 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. """ # Documentation strings format __docformat__ = "restructuredtext en" # ------------------------------------------------------------------------------ # Service specifications SERVICE_HERALD = "herald.core" """ Specification of the Herald core service. This service is provided only if at least one transport implementation is available. """ SERVICE_HERALD_INTERNAL = "herald.core.internal" """ Synonym for the Herald core server, but with a different life cycle: this service has the same life cycle as the Herald core component """ SERVICE_DIRECTORY = "herald.directory" """ Specification of the Herald directory service """ SERVICE_LISTENER = "herald.message.listener" """ Specification of a message listener """ SERVICE_DIRECTORY_LISTENER = "herald.directory.listener" """ Specification of a directory listener """ SERVICE_DIRECTORY_GROUP_LISTENER = "herald.directory.group_listener" """ Specification of a directory group listener """ SERVICE_TRANSPORT = "herald.transport" """ Specification of a transport implementation for Herald """ SERVICE_TRANSPORT_DIRECTORY = "herald.transport.directory" """ Specification of the directory associated to a transport implementation """ # ------------------------------------------------------------------------------ # Service properties PROP_ACCESS_ID = "herald.access.id" """ Unique name of the kind of access a transport implementation handles """ PROP_FILTERS = "herald.filters" """ A set of filename patterns to filter messages """ # ------------------------------------------------------------------------------ # Framework properties FWPROP_APPLICATION_ID = "herald.application.id" """ ID of the application the local peer is part of. Peers of other applications will be ignored. """ DEFAULT_APPLICATION_ID = "<herald-legacy>" """ Default application ID """ FWPROP_PEER_UID = "herald.peer.uid" """ UID of the peer. Default to the Pelix framework UID. """ FWPROP_PEER_NAME = "herald.peer.name" """ Human-readable name of the peer. Default to the peer UID. """ FWPROP_PEER_GROUPS = "herald.peer.groups" """ The list of groups the peer belongs to. Can be either a list or a comma-separated list string. """ FWPROP_NODE_UID = "herald.node.uid" """ UID of the node hosting the peer. Defaults to the peer UID. """ FWPROP_NODE_NAME = "herald.node.name" """ Human-readable name of the node hosting the peer. Defaults to the node UID. """
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1553, 6646, 13, 7630, 26, 9094, 13, 24, 1553, 199, 624, 199, 40, 281, 27075, 6170, 2559, 199, 199, 26, 2502, 26, 27864, 8256, 77, 867, 199, 26, 7307, 26, 1898, 6927, 12, 365, 460, 416, 6301, 335, 199, 26, 1682, 26, 3668, 844, 499, 14, 16, 199, 26, 1023, 26, 378, 14, 16, 14, 18, 14, 2374, 199, 26, 1205, 26, 32657, 199, 199, 703, 339, 1898, 6927, 365, 460, 416, 6301, 335, 339, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 272, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 272, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 398, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 339, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 272, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 272, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 272, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 272, 4204, 1334, 314, 844, 14, 199, 624, 199, 199, 3, 15249, 3326, 1475, 199, 363, 21841, 363, 275, 298, 26854, 655, 2, 199, 199, 3, 5620, 10965, 199, 3, 7591, 28754, 199, 199, 10486, 63, 3452, 748, 36, 275, 298, 2523, 27075, 14, 1018, 2, 199, 624, 199, 26235, 402, 314, 18769, 27075, 6170, 2435, 14, 961, 2435, 365, 2741, 1454, 340, 199, 292, 5210, 1373, 7773, 4514, 365, 2808, 14, 199, 624, 199, 199, 10486, 63, 3452, 748, 36, 63, 17681, 275, 298, 2523, 27075, 14, 1018, 14, 4672, 2, 199, 624, 199, 17746, 15224, 367, 314, 18769, 27075, 6170, 1654, 12, 1325, 543, 282, 3365, 15451, 8643, 26, 199, 3749, 2435, 965, 314, 2011, 15451, 8643, 465, 314, 18769, 27075, 6170, 3931, 199, 624, 199, 199, 10486, 63, 16436, 275, 298, 2523, 27075, 14, 3619, 2, 199, 624, 199, 26235, 402, 314, 18769, 27075, 2082, 2435, 199, 624, 199, 199, 10486, 63, 4924, 742, 540, 275, 298, 2523, 27075, 14, 1188, 14, 9799, 2, 199, 624, 199, 26235, 402, 282, 1245, 11647, 199, 624, 199, 199, 10486, 63, 16436, 63, 4924, 742, 540, 275, 298, 2523, 27075, 14, 3619, 14, 9799, 2, 199, 624, 199, 26235, 402, 282, 2082, 11647, 199, 624, 199, 199, 10486, 63, 16436, 63, 7823, 63, 4924, 742, 540, 275, 298, 2523, 27075, 14, 3619, 14, 923, 63, 9799, 2, 199, 624, 199, 26235, 402, 282, 2082, 1572, 11647, 199, 624, 199, 199, 10486, 63, 12191, 3657, 275, 298, 2523, 27075, 14, 5545, 2, 199, 624, 199, 26235, 402, 282, 7773, 4514, 367, 18769, 27075, 199, 624, 199, 199, 10486, 63, 12191, 3657, 63, 16436, 275, 298, 2523, 27075, 14, 5545, 14, 3619, 2, 199, 624, 199, 26235, 402, 314, 2082, 4568, 370, 282, 7773, 4514, 199, 624, 199, 199, 3, 5620, 10965, 199, 3, 7591, 4382, 199, 199, 19926, 63, 11074, 63, 998, 275, 298, 2523, 27075, 14, 2732, 14, 344, 2, 199, 624, 199, 11427, 536, 402, 314, 4928, 402, 2879, 282, 7773, 4514, 10022, 199, 624, 199, 199, 19926, 63, 9905, 51, 275, 298, 2523, 27075, 14, 4273, 2, 199, 624, 199, 33, 663, 402, 1788, 7970, 370, 2457, 3788, 199, 624, 199, 199, 3, 5620, 10965, 199, 3, 22545, 4382, 199, 199, 19445, 19926, 63, 24051, 63, 998, 275, 298, 2523, 27075, 14, 3578, 14, 344, 2, 199, 624, 199, 998, 402, 314, 4223, 314, 2257, 9104, 365, 1777, 402, 14, 11379, 1192, 402, 1163, 13103, 199, 14117, 506, 5525, 14, 199, 624, 199, 199, 3472, 63, 24051, 63, 998, 275, 3886, 2523, 27075, 13, 10000, 4335, 199, 624, 3758, 4223, 2870, 408, 199, 199, 19445, 19926, 63, 31560, 63, 6685, 275, 298, 2523, 27075, 14, 7866, 14, 1535, 2, 199, 624, 199, 6685, 402, 314, 9104, 14, 3758, 370, 314, 11379, 20528, 10059, 20746, 14, 199, 624, 199, 199, 19445, 19926, 63, 31560, 63, 2339, 275, 298, 2523, 27075, 14, 7866, 14, 354, 2, 199, 624, 199, 31355, 13, 11875, 536, 402, 314, 9104, 14, 3758, 370, 314, 9104, 20746, 14, 199, 624, 199, 199, 19445, 19926, 63, 31560, 63, 27544, 275, 298, 2523, 27075, 14, 7866, 14, 2634, 2, 199, 624, 199, 1918, 769, 402, 4652, 314, 9104, 15006, 370, 14, 6855, 506, 1902, 282, 769, 503, 199, 65, 10029, 13, 12794, 769, 1059, 14, 199, 624, 199, 199, 19445, 19926, 63, 8063, 63, 6685, 275, 298, 2523, 27075, 14, 932, 14, 1535, 2, 199, 624, 199, 6685, 402, 314, 1031, 1591, 316, 314, 9104, 14, 7827, 370, 314, 9104, 20746, 14, 199, 624, 199, 199, 19445, 19926, 63, 8063, 63, 2339, 275, 298, 2523, 27075, 14, 932, 14, 354, 2, 199, 624, 199, 31355, 13, 11875, 536, 402, 314, 1031, 1591, 316, 314, 9104, 14, 7827, 370, 314, 1031, 20746, 14, 199, 624, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1553, 6646, 13, 7630, 26, 9094, 13, 24, 1553, 199, 624, 199, 40, 281, 27075, 6170, 2559, 199, 199, 26, 2502, 26, 27864, 8256, 77, 867, 199, 26, 7307, 26, 1898, 6927, 12, 365, 460, 416, 6301, 335, 199, 26, 1682, 26, 3668, 844, 499, 14, 16, 199, 26, 1023, 26, 378, 14, 16, 14, 18, 14, 2374, 199, 26, 1205, 26, 32657, 199, 199, 703, 339, 1898, 6927, 365, 460, 416, 6301, 335, 339, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 272, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 272, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 398, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 339, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 272, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 272, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 272, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 272, 4204, 1334, 314, 844, 14, 199, 624, 199, 199, 3, 15249, 3326, 1475, 199, 363, 21841, 363, 275, 298, 26854, 655, 2, 199, 199, 3, 5620, 10965, 199, 3, 7591, 28754, 199, 199, 10486, 63, 3452, 748, 36, 275, 298, 2523, 27075, 14, 1018, 2, 199, 624, 199, 26235, 402, 314, 18769, 27075, 6170, 2435, 14, 961, 2435, 365, 2741, 1454, 340, 199, 292, 5210, 1373, 7773, 4514, 365, 2808, 14, 199, 624, 199, 199, 10486, 63, 3452, 748, 36, 63, 17681, 275, 298, 2523, 27075, 14, 1018, 14, 4672, 2, 199, 624, 199, 17746, 15224, 367, 314, 18769, 27075, 6170, 1654, 12, 1325, 543, 282, 3365, 15451, 8643, 26, 199, 3749, 2435, 965, 314, 2011, 15451, 8643, 465, 314, 18769, 27075, 6170, 3931, 199, 624, 199, 199, 10486, 63, 16436, 275, 298, 2523, 27075, 14, 3619, 2, 199, 624, 199, 26235, 402, 314, 18769, 27075, 2082, 2435, 199, 624, 199, 199, 10486, 63, 4924, 742, 540, 275, 298, 2523, 27075, 14, 1188, 14, 9799, 2, 199, 624, 199, 26235, 402, 282, 1245, 11647, 199, 624, 199, 199, 10486, 63, 16436, 63, 4924, 742, 540, 275, 298, 2523, 27075, 14, 3619, 14, 9799, 2, 199, 624, 199, 26235, 402, 282, 2082, 11647, 199, 624, 199, 199, 10486, 63, 16436, 63, 7823, 63, 4924, 742, 540, 275, 298, 2523, 27075, 14, 3619, 14, 923, 63, 9799, 2, 199, 624, 199, 26235, 402, 282, 2082, 1572, 11647, 199, 624, 199, 199, 10486, 63, 12191, 3657, 275, 298, 2523, 27075, 14, 5545, 2, 199, 624, 199, 26235, 402, 282, 7773, 4514, 367, 18769, 27075, 199, 624, 199, 199, 10486, 63, 12191, 3657, 63, 16436, 275, 298, 2523, 27075, 14, 5545, 14, 3619, 2, 199, 624, 199, 26235, 402, 314, 2082, 4568, 370, 282, 7773, 4514, 199, 624, 199, 199, 3, 5620, 10965, 199, 3, 7591, 4382, 199, 199, 19926, 63, 11074, 63, 998, 275, 298, 2523, 27075, 14, 2732, 14, 344, 2, 199, 624, 199, 11427, 536, 402, 314, 4928, 402, 2879, 282, 7773, 4514, 10022, 199, 624, 199, 199, 19926, 63, 9905, 51, 275, 298, 2523, 27075, 14, 4273, 2, 199, 624, 199, 33, 663, 402, 1788, 7970, 370, 2457, 3788, 199, 624, 199, 199, 3, 5620, 10965, 199, 3, 22545, 4382, 199, 199, 19445, 19926, 63, 24051, 63, 998, 275, 298, 2523, 27075, 14, 3578, 14, 344, 2, 199, 624, 199, 998, 402, 314, 4223, 314, 2257, 9104, 365, 1777, 402, 14, 11379, 1192, 402, 1163, 13103, 199, 14117, 506, 5525, 14, 199, 624, 199, 199, 3472, 63, 24051, 63, 998, 275, 3886, 2523, 27075, 13, 10000, 4335, 199, 624, 3758, 4223, 2870, 408, 199, 199, 19445, 19926, 63, 31560, 63, 6685, 275, 298, 2523, 27075, 14, 7866, 14, 1535, 2, 199, 624, 199, 6685, 402, 314, 9104, 14, 3758, 370, 314, 11379, 20528, 10059, 20746, 14, 199, 624, 199, 199, 19445, 19926, 63, 31560, 63, 2339, 275, 298, 2523, 27075, 14, 7866, 14, 354, 2, 199, 624, 199, 31355, 13, 11875, 536, 402, 314, 9104, 14, 3758, 370, 314, 9104, 20746, 14, 199, 624, 199, 199, 19445, 19926, 63, 31560, 63, 27544, 275, 298, 2523, 27075, 14, 7866, 14, 2634, 2, 199, 624, 199, 1918, 769, 402, 4652, 314, 9104, 15006, 370, 14, 6855, 506, 1902, 282, 769, 503, 199, 65, 10029, 13, 12794, 769, 1059, 14, 199, 624, 199, 199, 19445, 19926, 63, 8063, 63, 6685, 275, 298, 2523, 27075, 14, 932, 14, 1535, 2, 199, 624, 199, 6685, 402, 314, 1031, 1591, 316, 314, 9104, 14, 7827, 370, 314, 9104, 20746, 14, 199, 624, 199, 199, 19445, 19926, 63, 8063, 63, 2339, 275, 298, 2523, 27075, 14, 932, 14, 354, 2, 199, 624, 199, 31355, 13, 11875, 536, 402, 314, 1031, 1591, 316, 314, 9104, 14, 7827, 370, 314, 1031, 20746, 14, 199, 624, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
travisdoor/ArgosRts
engine/thirdparty/pybind11/tests/test_builtin_casters.py
2
9913
# Python < 3 needs this: coding=utf-8 import pytest from pybind11_tests import builtin_casters as m from pybind11_tests import UserType, IncType def test_simple_string(): assert m.string_roundtrip("const char *") == "const char *" def test_unicode_conversion(): """Tests unicode conversion and error reporting.""" assert m.good_utf8_string() == u"Say utf8‽ 🎂 𝐀" assert m.good_utf16_string() == u"b‽🎂𝐀z" assert m.good_utf32_string() == u"a𝐀🎂‽z" assert m.good_wchar_string() == u"a⸘𝐀z" with pytest.raises(UnicodeDecodeError): m.bad_utf8_string() with pytest.raises(UnicodeDecodeError): m.bad_utf16_string() # These are provided only if they actually fail (they don't when 32-bit and under Python 2.7) if hasattr(m, "bad_utf32_string"): with pytest.raises(UnicodeDecodeError): m.bad_utf32_string() if hasattr(m, "bad_wchar_string"): with pytest.raises(UnicodeDecodeError): m.bad_wchar_string() assert m.u8_Z() == 'Z' assert m.u8_eacute() == u'é' assert m.u16_ibang() == u'‽' assert m.u32_mathbfA() == u'𝐀' assert m.wchar_heart() == u'♥' def test_single_char_arguments(): """Tests failures for passing invalid inputs to char-accepting functions""" def toobig_message(r): return "Character code point not in range({0:#x})".format(r) toolong_message = "Expected a character, but multi-character string found" assert m.ord_char(u'a') == 0x61 # simple ASCII assert m.ord_char(u'é') == 0xE9 # requires 2 bytes in utf-8, but can be stuffed in a char with pytest.raises(ValueError) as excinfo: assert m.ord_char(u'Ā') == 0x100 # requires 2 bytes, doesn't fit in a char assert str(excinfo.value) == toobig_message(0x100) with pytest.raises(ValueError) as excinfo: assert m.ord_char(u'ab') assert str(excinfo.value) == toolong_message assert m.ord_char16(u'a') == 0x61 assert m.ord_char16(u'é') == 0xE9 assert m.ord_char16(u'Ā') == 0x100 assert m.ord_char16(u'‽') == 0x203d assert m.ord_char16(u'♥') == 0x2665 with pytest.raises(ValueError) as excinfo: assert m.ord_char16(u'🎂') == 0x1F382 # requires surrogate pair assert str(excinfo.value) == toobig_message(0x10000) with pytest.raises(ValueError) as excinfo: assert m.ord_char16(u'aa') assert str(excinfo.value) == toolong_message assert m.ord_char32(u'a') == 0x61 assert m.ord_char32(u'é') == 0xE9 assert m.ord_char32(u'Ā') == 0x100 assert m.ord_char32(u'‽') == 0x203d assert m.ord_char32(u'♥') == 0x2665 assert m.ord_char32(u'🎂') == 0x1F382 with pytest.raises(ValueError) as excinfo: assert m.ord_char32(u'aa') assert str(excinfo.value) == toolong_message assert m.ord_wchar(u'a') == 0x61 assert m.ord_wchar(u'é') == 0xE9 assert m.ord_wchar(u'Ā') == 0x100 assert m.ord_wchar(u'‽') == 0x203d assert m.ord_wchar(u'♥') == 0x2665 if m.wchar_size == 2: with pytest.raises(ValueError) as excinfo: assert m.ord_wchar(u'🎂') == 0x1F382 # requires surrogate pair assert str(excinfo.value) == toobig_message(0x10000) else: assert m.ord_wchar(u'🎂') == 0x1F382 with pytest.raises(ValueError) as excinfo: assert m.ord_wchar(u'aa') assert str(excinfo.value) == toolong_message def test_bytes_to_string(): """Tests the ability to pass bytes to C++ string-accepting functions. Note that this is one-way: the only way to return bytes to Python is via the pybind11::bytes class.""" # Issue #816 import sys byte = bytes if sys.version_info[0] < 3 else str assert m.strlen(byte("hi")) == 2 assert m.string_length(byte("world")) == 5 assert m.string_length(byte("a\x00b")) == 3 assert m.strlen(byte("a\x00b")) == 1 # C-string limitation # passing in a utf8 encoded string should work assert m.string_length(u'💩'.encode("utf8")) == 4 @pytest.mark.skipif(not hasattr(m, "has_string_view"), reason="no <string_view>") def test_string_view(capture): """Tests support for C++17 string_view arguments and return values""" assert m.string_view_chars("Hi") == [72, 105] assert m.string_view_chars("Hi 🎂") == [72, 105, 32, 0xf0, 0x9f, 0x8e, 0x82] assert m.string_view16_chars("Hi 🎂") == [72, 105, 32, 0xd83c, 0xdf82] assert m.string_view32_chars("Hi 🎂") == [72, 105, 32, 127874] assert m.string_view_return() == "utf8 secret 🎂" assert m.string_view16_return() == "utf16 secret 🎂" assert m.string_view32_return() == "utf32 secret 🎂" with capture: m.string_view_print("Hi") m.string_view_print("utf8 🎂") m.string_view16_print("utf16 🎂") m.string_view32_print("utf32 🎂") assert capture == """ Hi 2 utf8 🎂 9 utf16 🎂 8 utf32 🎂 7 """ with capture: m.string_view_print("Hi, ascii") m.string_view_print("Hi, utf8 🎂") m.string_view16_print("Hi, utf16 🎂") m.string_view32_print("Hi, utf32 🎂") assert capture == """ Hi, ascii 9 Hi, utf8 🎂 13 Hi, utf16 🎂 12 Hi, utf32 🎂 11 """ def test_integer_casting(): """Issue #929 - out-of-range integer values shouldn't be accepted""" import sys assert m.i32_str(-1) == "-1" assert m.i64_str(-1) == "-1" assert m.i32_str(2000000000) == "2000000000" assert m.u32_str(2000000000) == "2000000000" if sys.version_info < (3,): assert m.i32_str(long(-1)) == "-1" assert m.i64_str(long(-1)) == "-1" assert m.i64_str(long(-999999999999)) == "-999999999999" assert m.u64_str(long(999999999999)) == "999999999999" else: assert m.i64_str(-999999999999) == "-999999999999" assert m.u64_str(999999999999) == "999999999999" with pytest.raises(TypeError) as excinfo: m.u32_str(-1) assert "incompatible function arguments" in str(excinfo.value) with pytest.raises(TypeError) as excinfo: m.u64_str(-1) assert "incompatible function arguments" in str(excinfo.value) with pytest.raises(TypeError) as excinfo: m.i32_str(-3000000000) assert "incompatible function arguments" in str(excinfo.value) with pytest.raises(TypeError) as excinfo: m.i32_str(3000000000) assert "incompatible function arguments" in str(excinfo.value) if sys.version_info < (3,): with pytest.raises(TypeError) as excinfo: m.u32_str(long(-1)) assert "incompatible function arguments" in str(excinfo.value) with pytest.raises(TypeError) as excinfo: m.u64_str(long(-1)) assert "incompatible function arguments" in str(excinfo.value) def test_tuple(doc): """std::pair <-> tuple & std::tuple <-> tuple""" assert m.pair_passthrough((True, "test")) == ("test", True) assert m.tuple_passthrough((True, "test", 5)) == (5, "test", True) # Any sequence can be cast to a std::pair or std::tuple assert m.pair_passthrough([True, "test"]) == ("test", True) assert m.tuple_passthrough([True, "test", 5]) == (5, "test", True) assert m.empty_tuple() == () assert doc(m.pair_passthrough) == """ pair_passthrough(arg0: Tuple[bool, str]) -> Tuple[str, bool] Return a pair in reversed order """ assert doc(m.tuple_passthrough) == """ tuple_passthrough(arg0: Tuple[bool, str, int]) -> Tuple[int, str, bool] Return a triple in reversed order """ assert m.rvalue_pair() == ("rvalue", "rvalue") assert m.lvalue_pair() == ("lvalue", "lvalue") assert m.rvalue_tuple() == ("rvalue", "rvalue", "rvalue") assert m.lvalue_tuple() == ("lvalue", "lvalue", "lvalue") assert m.rvalue_nested() == ("rvalue", ("rvalue", ("rvalue", "rvalue"))) assert m.lvalue_nested() == ("lvalue", ("lvalue", ("lvalue", "lvalue"))) def test_builtins_cast_return_none(): """Casters produced with PYBIND11_TYPE_CASTER() should convert nullptr to None""" assert m.return_none_string() is None assert m.return_none_char() is None assert m.return_none_bool() is None assert m.return_none_int() is None assert m.return_none_float() is None def test_none_deferred(): """None passed as various argument types should defer to other overloads""" assert not m.defer_none_cstring("abc") assert m.defer_none_cstring(None) assert not m.defer_none_custom(UserType()) assert m.defer_none_custom(None) assert m.nodefer_none_void(None) def test_void_caster(): assert m.load_nullptr_t(None) is None assert m.cast_nullptr_t() is None def test_reference_wrapper(): """std::reference_wrapper for builtin and user types""" assert m.refwrap_builtin(42) == 420 assert m.refwrap_usertype(UserType(42)) == 42 with pytest.raises(TypeError) as excinfo: m.refwrap_builtin(None) assert "incompatible function arguments" in str(excinfo.value) with pytest.raises(TypeError) as excinfo: m.refwrap_usertype(None) assert "incompatible function arguments" in str(excinfo.value) a1 = m.refwrap_list(copy=True) a2 = m.refwrap_list(copy=True) assert [x.value for x in a1] == [2, 3] assert [x.value for x in a2] == [2, 3] assert not a1[0] is a2[0] and not a1[1] is a2[1] b1 = m.refwrap_list(copy=False) b2 = m.refwrap_list(copy=False) assert [x.value for x in b1] == [1, 2] assert [x.value for x in b2] == [1, 2] assert b1[0] is b2[0] and b1[1] is b2[1] assert m.refwrap_iiw(IncType(5)) == 5 assert m.refwrap_call_iiw(IncType(10), m.refwrap_iiw) == [10, 10, 10, 10] def test_complex_cast(): """std::complex casts""" assert m.complex_cast(1) == "1.0" assert m.complex_cast(2j) == "(0.0, 2.0)"
mit
[ 3, 2018, 665, 650, 4839, 642, 26, 2803, 29, 1624, 13, 24, 199, 646, 4613, 199, 199, 504, 1134, 3409, 845, 63, 2219, 492, 6762, 63, 9765, 878, 465, 333, 199, 504, 1134, 3409, 845, 63, 2219, 492, 2876, 804, 12, 3277, 804, 421, 199, 318, 511, 63, 4129, 63, 875, 837, 272, 702, 333, 14, 875, 63, 25920, 480, 1297, 1495, 627, 531, 508, 298, 1297, 1495, 14390, 421, 199, 318, 511, 63, 2975, 63, 15083, 837, 272, 408, 2925, 2649, 8603, 436, 1125, 17290, 1041, 272, 702, 333, 14, 8302, 63, 1624, 24, 63, 875, 342, 508, 399, 2, 51, 1187, 2774, 24, 8477, 122, 221, 173, 254, 237, 225, 221, 173, 252, 239, 223, 2, 272, 702, 333, 14, 8302, 63, 1624, 975, 63, 875, 342, 508, 399, 2, 66, 8477, 122, 173, 254, 237, 225, 173, 252, 239, 223, 90, 2, 272, 702, 333, 14, 8302, 63, 1624, 708, 63, 875, 342, 508, 399, 2, 65, 173, 252, 239, 223, 173, 254, 237, 225, 8477, 122, 90, 2, 272, 702, 333, 14, 8302, 63, 23118, 63, 875, 342, 508, 399, 2, 65, 159, 117, 247, 173, 252, 239, 223, 90, 2, 339, 543, 4613, 14, 3536, 8, 7087, 12620, 304, 267, 333, 14, 4087, 63, 1624, 24, 63, 875, 342, 339, 543, 4613, 14, 3536, 8, 7087, 12620, 304, 267, 333, 14, 4087, 63, 1624, 975, 63, 875, 342, 339, 327, 5723, 787, 2741, 1454, 340, 2985, 5965, 2449, 334, 29002, 2793, 1133, 1380, 4337, 13, 2075, 436, 1334, 2018, 499, 14, 23, 9, 272, 340, 2688, 8, 77, 12, 298, 4087, 63, 1624, 708, 63, 875, 2349, 267, 543, 4613, 14, 3536, 8, 7087, 12620, 304, 288, 333, 14, 4087, 63, 1624, 708, 63, 875, 342, 272, 340, 2688, 8, 77, 12, 298, 4087, 63, 23118, 63, 875, 2349, 267, 543, 4613, 14, 3536, 8, 7087, 12620, 304, 288, 333, 14, 4087, 63, 23118, 63, 875, 342, 339, 702, 333, 14, 85, 24, 63, 58, 342, 508, 283, 58, 7, 272, 702, 333, 14, 85, 24, 63, 69, 14696, 342, 508, 399, 7, 5741, 7, 272, 702, 333, 14, 85, 975, 63, 1892, 621, 342, 508, 399, 7, 8477, 122, 7, 272, 702, 333, 14, 85, 708, 63, 30286, 33, 342, 508, 399, 7, 173, 252, 239, 223, 7, 272, 702, 333, 14, 23118, 63, 426, 580, 342, 508, 399, 22095, 248, 99, 7, 421, 199, 318, 511, 63, 4780, 63, 1560, 63, 4958, 837, 272, 408, 2925, 9081, 367, 9476, 3866, 4153, 370, 1495, 13, 5694, 316, 3423, 624, 272, 347, 370, 2873, 528, 63, 1188, 8, 82, 304, 267, 372, 298, 14852, 1233, 2376, 440, 315, 1425, 2561, 16, 15596, 88, 25974, 908, 8, 82, 9, 272, 4744, 951, 63, 1188, 275, 298, 6964, 282, 4528, 12, 1325, 3510, 13, 10856, 1059, 1911, 2, 339, 702, 333, 14, 2181, 63, 1560, 8, 85, 7, 65, 358, 508, 378, 88, 2976, 221, 327, 3486, 10485, 272, 702, 333, 14, 2181, 63, 1560, 8, 85, 7, 5741, 358, 508, 378, 6991, 25, 221, 327, 5074, 499, 2783, 315, 2774, 13, 24, 12, 1325, 883, 506, 8292, 379, 315, 282, 1495, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 8, 85, 7, 129, 223, 358, 508, 378, 88, 1960, 221, 327, 5074, 499, 2783, 12, 3181, 1133, 5542, 315, 282, 1495, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 370, 2873, 528, 63, 1188, 8, 16, 88, 1960, 9, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 8, 85, 7, 371, 358, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 4744, 951, 63, 1188, 339, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 65, 358, 508, 378, 88, 2976, 272, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 5741, 358, 508, 378, 6991, 25, 272, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 129, 223, 358, 508, 378, 88, 1960, 272, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 8477, 122, 358, 508, 378, 88, 11341, 68, 272, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 22095, 248, 99, 358, 508, 378, 88, 9969, 21, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 173, 254, 237, 225, 358, 508, 378, 88, 17, 38, 16244, 221, 327, 5074, 6296, 13095, 4092, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 370, 2873, 528, 63, 1188, 8, 16, 88, 9943, 9, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 2158, 358, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 4744, 951, 63, 1188, 339, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 65, 358, 508, 378, 88, 2976, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 5741, 358, 508, 378, 6991, 25, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 129, 223, 358, 508, 378, 88, 1960, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 8477, 122, 358, 508, 378, 88, 11341, 68, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 22095, 248, 99, 358, 508, 378, 88, 9969, 21, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 173, 254, 237, 225, 358, 508, 378, 88, 17, 38, 16244, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 2158, 358, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 4744, 951, 63, 1188, 339, 702, 333, 14, 2181, 63, 23118, 8, 85, 7, 65, 358, 508, 378, 88, 2976, 272, 702, 333, 14, 2181, 63, 23118, 8, 85, 7, 5741, 358, 508, 378, 6991, 25, 272, 702, 333, 14, 2181, 63, 23118, 8, 85, 7, 129, 223, 358, 508, 378, 88, 1960, 272, 702, 333, 14, 2181, 63, 23118, 8, 85, 7, 8477, 122, 358, 508, 378, 88, 11341, 68, 272, 702, 333 ]
[ 2018, 665, 650, 4839, 642, 26, 2803, 29, 1624, 13, 24, 199, 646, 4613, 199, 199, 504, 1134, 3409, 845, 63, 2219, 492, 6762, 63, 9765, 878, 465, 333, 199, 504, 1134, 3409, 845, 63, 2219, 492, 2876, 804, 12, 3277, 804, 421, 199, 318, 511, 63, 4129, 63, 875, 837, 272, 702, 333, 14, 875, 63, 25920, 480, 1297, 1495, 627, 531, 508, 298, 1297, 1495, 14390, 421, 199, 318, 511, 63, 2975, 63, 15083, 837, 272, 408, 2925, 2649, 8603, 436, 1125, 17290, 1041, 272, 702, 333, 14, 8302, 63, 1624, 24, 63, 875, 342, 508, 399, 2, 51, 1187, 2774, 24, 8477, 122, 221, 173, 254, 237, 225, 221, 173, 252, 239, 223, 2, 272, 702, 333, 14, 8302, 63, 1624, 975, 63, 875, 342, 508, 399, 2, 66, 8477, 122, 173, 254, 237, 225, 173, 252, 239, 223, 90, 2, 272, 702, 333, 14, 8302, 63, 1624, 708, 63, 875, 342, 508, 399, 2, 65, 173, 252, 239, 223, 173, 254, 237, 225, 8477, 122, 90, 2, 272, 702, 333, 14, 8302, 63, 23118, 63, 875, 342, 508, 399, 2, 65, 159, 117, 247, 173, 252, 239, 223, 90, 2, 339, 543, 4613, 14, 3536, 8, 7087, 12620, 304, 267, 333, 14, 4087, 63, 1624, 24, 63, 875, 342, 339, 543, 4613, 14, 3536, 8, 7087, 12620, 304, 267, 333, 14, 4087, 63, 1624, 975, 63, 875, 342, 339, 327, 5723, 787, 2741, 1454, 340, 2985, 5965, 2449, 334, 29002, 2793, 1133, 1380, 4337, 13, 2075, 436, 1334, 2018, 499, 14, 23, 9, 272, 340, 2688, 8, 77, 12, 298, 4087, 63, 1624, 708, 63, 875, 2349, 267, 543, 4613, 14, 3536, 8, 7087, 12620, 304, 288, 333, 14, 4087, 63, 1624, 708, 63, 875, 342, 272, 340, 2688, 8, 77, 12, 298, 4087, 63, 23118, 63, 875, 2349, 267, 543, 4613, 14, 3536, 8, 7087, 12620, 304, 288, 333, 14, 4087, 63, 23118, 63, 875, 342, 339, 702, 333, 14, 85, 24, 63, 58, 342, 508, 283, 58, 7, 272, 702, 333, 14, 85, 24, 63, 69, 14696, 342, 508, 399, 7, 5741, 7, 272, 702, 333, 14, 85, 975, 63, 1892, 621, 342, 508, 399, 7, 8477, 122, 7, 272, 702, 333, 14, 85, 708, 63, 30286, 33, 342, 508, 399, 7, 173, 252, 239, 223, 7, 272, 702, 333, 14, 23118, 63, 426, 580, 342, 508, 399, 22095, 248, 99, 7, 421, 199, 318, 511, 63, 4780, 63, 1560, 63, 4958, 837, 272, 408, 2925, 9081, 367, 9476, 3866, 4153, 370, 1495, 13, 5694, 316, 3423, 624, 272, 347, 370, 2873, 528, 63, 1188, 8, 82, 304, 267, 372, 298, 14852, 1233, 2376, 440, 315, 1425, 2561, 16, 15596, 88, 25974, 908, 8, 82, 9, 272, 4744, 951, 63, 1188, 275, 298, 6964, 282, 4528, 12, 1325, 3510, 13, 10856, 1059, 1911, 2, 339, 702, 333, 14, 2181, 63, 1560, 8, 85, 7, 65, 358, 508, 378, 88, 2976, 221, 327, 3486, 10485, 272, 702, 333, 14, 2181, 63, 1560, 8, 85, 7, 5741, 358, 508, 378, 6991, 25, 221, 327, 5074, 499, 2783, 315, 2774, 13, 24, 12, 1325, 883, 506, 8292, 379, 315, 282, 1495, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 8, 85, 7, 129, 223, 358, 508, 378, 88, 1960, 221, 327, 5074, 499, 2783, 12, 3181, 1133, 5542, 315, 282, 1495, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 370, 2873, 528, 63, 1188, 8, 16, 88, 1960, 9, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 8, 85, 7, 371, 358, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 4744, 951, 63, 1188, 339, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 65, 358, 508, 378, 88, 2976, 272, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 5741, 358, 508, 378, 6991, 25, 272, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 129, 223, 358, 508, 378, 88, 1960, 272, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 8477, 122, 358, 508, 378, 88, 11341, 68, 272, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 22095, 248, 99, 358, 508, 378, 88, 9969, 21, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 173, 254, 237, 225, 358, 508, 378, 88, 17, 38, 16244, 221, 327, 5074, 6296, 13095, 4092, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 370, 2873, 528, 63, 1188, 8, 16, 88, 9943, 9, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 975, 8, 85, 7, 2158, 358, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 4744, 951, 63, 1188, 339, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 65, 358, 508, 378, 88, 2976, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 5741, 358, 508, 378, 6991, 25, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 129, 223, 358, 508, 378, 88, 1960, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 8477, 122, 358, 508, 378, 88, 11341, 68, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 22095, 248, 99, 358, 508, 378, 88, 9969, 21, 272, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 173, 254, 237, 225, 358, 508, 378, 88, 17, 38, 16244, 272, 543, 4613, 14, 3536, 8, 3393, 9, 465, 21596, 26, 267, 702, 333, 14, 2181, 63, 1560, 708, 8, 85, 7, 2158, 358, 272, 702, 620, 8, 27447, 14, 585, 9, 508, 4744, 951, 63, 1188, 339, 702, 333, 14, 2181, 63, 23118, 8, 85, 7, 65, 358, 508, 378, 88, 2976, 272, 702, 333, 14, 2181, 63, 23118, 8, 85, 7, 5741, 358, 508, 378, 6991, 25, 272, 702, 333, 14, 2181, 63, 23118, 8, 85, 7, 129, 223, 358, 508, 378, 88, 1960, 272, 702, 333, 14, 2181, 63, 23118, 8, 85, 7, 8477, 122, 358, 508, 378, 88, 11341, 68, 272, 702, 333, 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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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 ]
zofuthan/edx-platform
lms/djangoapps/lms_xblock/migrations/0001_initial.py
110
4883
# -*- 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 model 'XBlockAsidesConfig' db.create_table('lms_xblock_xblockasidesconfig', ( ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), ('change_date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), ('changed_by', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'], null=True, on_delete=models.PROTECT)), ('enabled', self.gf('django.db.models.fields.BooleanField')(default=False)), ('disabled_blocks', self.gf('django.db.models.fields.TextField')(default='about course_info static_tab')), )) db.send_create_signal('lms_xblock', ['XBlockAsidesConfig']) def backwards(self, orm): # Deleting model 'XBlockAsidesConfig' db.delete_table('lms_xblock_xblockasidesconfig') models = { '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'}) }, 'lms_xblock.xblockasidesconfig': { 'Meta': {'object_name': 'XBlockAsidesConfig'}, 'change_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'changed_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'on_delete': 'models.PROTECT'}), 'disabled_blocks': ('django.db.models.fields.TextField', [], {'default': "'about course_info static_tab'"}), 'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) } } complete_apps = ['lms_xblock']
agpl-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, 1402, 283, 24784, 33, 19564, 2028, 7, 267, 1592, 14, 981, 63, 1224, 360, 15807, 63, 11283, 63, 11283, 28135, 83, 888, 297, 334, 288, 661, 344, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 7533, 3327, 63, 498, 29, 549, 1826, 288, 661, 1461, 63, 602, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 2495, 63, 2131, 63, 525, 29, 549, 12, 4596, 29, 549, 1826, 288, 661, 2489, 63, 991, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 7533, 475, 29, 1025, 459, 1178, 14, 1899, 995, 2973, 29, 549, 12, 641, 63, 1807, 29, 992, 14, 29148, 1826, 288, 661, 3827, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 7533, 885, 29, 797, 1826, 288, 661, 7011, 63, 4166, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 7533, 885, 534, 10254, 2518, 63, 815, 2955, 63, 2902, 3855, 267, 5082, 267, 1592, 14, 2254, 63, 981, 63, 4653, 360, 15807, 63, 11283, 297, 788, 24784, 33, 19564, 2028, 1105, 2378, 347, 8552, 8, 277, 12, 9813, 304, 267, 327, 15920, 1402, 283, 24784, 33, 19564, 2028, 7, 267, 1592, 14, 1807, 63, 1224, 360, 15807, 63, 11283, 63, 11283, 28135, 83, 888, 358, 2378, 1709, 275, 469, 267, 283, 1178, 14, 923, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 2448, 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, 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, 1257, 1604, 288, 283, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 3071, 267, 1660, 267, 283, 1178, 14, 5693, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 1317, 63, 466, 363, 571, 63, 1302, 297, 283, 1317, 63, 466, 363, 1238, 297, 283, 11879, 18106, 283, 3235, 63, 6314, 356, 9510, 1317, 63, 466, 297, 283, 11879, 9878, 283, 785, 63, 354, 356, 283, 7980, 2267, 288, 283, 11879, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 1317, 63, 466, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 297, 990, 791, 475, 356, 298, 1025, 459, 10778, 14, 11282, 6097, 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, 988, 63, 1267, 356, 283, 1400, 3071, 267, 1660, 267, 283, 1178, 14, 751, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 1899, 2267, 288, 283, 602, 63, 11806, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2123, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 297, 990, 791, 988, 63, 1267, 356, 283, 2194, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2246, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2634, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 2448, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 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, 374, 63, 2682, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 549, 1604, 288, 283, 374, 63, 7018, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 374, 63, 11434, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 2019, 63, 2886, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2019, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 3933, 1604, 288, 283, 751, 63, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2473, 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, 1216, 3071, 267, 1660, 267, 283, 10778, 14, 20735, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 354, 21099, 283, 3235, 63, 6314, 356, 9510, 571, 63, 1302, 297, 283, 1238, 9878, 283, 785, 63, 354, 356, 283, 11282, 297, 283, 697, 63, 1224, 356, 3546, 1176, 63, 1317, 63, 466, 15208, 288, 283, 571, 63, 1302, 356, 661, 1176, 14, 697, 14, 992, 14, 955 ]
[ 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, 1402, 283, 24784, 33, 19564, 2028, 7, 267, 1592, 14, 981, 63, 1224, 360, 15807, 63, 11283, 63, 11283, 28135, 83, 888, 297, 334, 288, 661, 344, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 7533, 3327, 63, 498, 29, 549, 1826, 288, 661, 1461, 63, 602, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 7533, 2495, 63, 2131, 63, 525, 29, 549, 12, 4596, 29, 549, 1826, 288, 661, 2489, 63, 991, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 7533, 475, 29, 1025, 459, 1178, 14, 1899, 995, 2973, 29, 549, 12, 641, 63, 1807, 29, 992, 14, 29148, 1826, 288, 661, 3827, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 7533, 885, 29, 797, 1826, 288, 661, 7011, 63, 4166, 297, 291, 14, 7102, 360, 1176, 14, 697, 14, 992, 14, 955, 14, 6254, 7533, 885, 534, 10254, 2518, 63, 815, 2955, 63, 2902, 3855, 267, 5082, 267, 1592, 14, 2254, 63, 981, 63, 4653, 360, 15807, 63, 11283, 297, 788, 24784, 33, 19564, 2028, 1105, 2378, 347, 8552, 8, 277, 12, 9813, 304, 267, 327, 15920, 1402, 283, 24784, 33, 19564, 2028, 7, 267, 1592, 14, 1807, 63, 1224, 360, 15807, 63, 11283, 63, 11283, 28135, 83, 888, 358, 2378, 1709, 275, 469, 267, 283, 1178, 14, 923, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 2448, 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, 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, 1257, 1604, 288, 283, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 3071, 267, 1660, 267, 283, 1178, 14, 5693, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 1317, 63, 466, 363, 571, 63, 1302, 297, 283, 1317, 63, 466, 363, 1238, 297, 283, 11879, 18106, 283, 3235, 63, 6314, 356, 9510, 1317, 63, 466, 297, 283, 11879, 9878, 283, 785, 63, 354, 356, 283, 7980, 2267, 288, 283, 11879, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 1317, 63, 466, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 297, 990, 791, 475, 356, 298, 1025, 459, 10778, 14, 11282, 6097, 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, 988, 63, 1267, 356, 283, 1400, 3071, 267, 1660, 267, 283, 1178, 14, 751, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 1899, 2267, 288, 283, 602, 63, 11806, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2123, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 297, 990, 791, 988, 63, 1267, 356, 283, 2194, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2246, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2634, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 2448, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 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, 374, 63, 2682, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 549, 1604, 288, 283, 374, 63, 7018, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 374, 63, 11434, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 2019, 63, 2886, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2019, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 3933, 1604, 288, 283, 751, 63, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 298, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2473, 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, 1216, 3071, 267, 1660, 267, 283, 10778, 14, 20735, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 16111, 354, 21099, 283, 3235, 63, 6314, 356, 9510, 571, 63, 1302, 297, 283, 1238, 9878, 283, 785, 63, 354, 356, 283, 11282, 297, 283, 697, 63, 1224, 356, 3546, 1176, 63, 1317, 63, 466, 15208, 288, 283, 571, 63, 1302, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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teinSequence from varcode import Variant from testing_helpers import data_path from nose.tools import eq_ def test_isovar_result_property_types(): for result in run_isovar( variants=data_path("data/b16.f10/b16.vcf"), alignment_file=data_path("data/b16.f10/b16.combined.sorted.bam")): # variant assert type(result.variant) is Variant # counts of genes and transcripts from variant assert type(result.num_overlapping_genes) is int assert type(result.num_overlapping_coding_genes) is int assert type(result.num_overlapping_transcripts) is int assert type(result.num_overlapping_coding_transcripts) is int # protein sequence assert type(result.top_protein_sequence) in (type(None), ProteinSequence) # counts of genes and transcripts from protein sequences assert type(result.num_genes_from_protein_sequences) is int assert type(result.num_genes_from_top_protein_sequence) is int assert type(result.num_transcripts_from_protein_sequences) is int assert type(result.num_transcripts_from_top_protein_sequence) is int # read and fragment counts assert type(result.num_ref_reads) is int assert type(result.num_alt_reads) is int assert type(result.num_other_reads) is int assert type(result.num_ref_fragments) is int assert type(result.num_alt_fragments) is int assert type(result.num_other_fragments) is int # read and fragment fractions assert type(result.fraction_ref_reads) is float assert type(result.fraction_alt_reads) is float assert type(result.fraction_other_reads) is float assert type(result.fraction_ref_fragments) is float assert type(result.fraction_alt_fragments) is float assert type(result.fraction_other_fragments) is float # read and fragment count ratios assert type(result.ratio_alt_to_other_reads) is float assert type(result.ratio_alt_to_other_fragments) is float assert type(result.ratio_other_to_alt_fragments) is float assert type(result.ratio_other_to_alt_reads) is float assert type(result.ratio_ref_to_other_fragments) is float assert type(result.ratio_other_to_ref_fragments) is float assert type(result.ratio_other_to_ref_reads) is float # this property aggregates all filters assert result.passes_all_filters in {True, False} assert type(result.protein_sequence_mutation_start_idx) in (int, type(None)) assert type(result.protein_sequence_mutation_end_idx) in (int, type(None)) def test_isovar_result_nonsyn_variants(): for result in run_isovar( variants=data_path("data/b16.f10/b16.vcf"), alignment_file=data_path("data/b16.f10/b16.combined.sorted.bam")): print(result.variant) print(result.predicted_effect) if result.has_mutant_protein_sequence_from_rna: assert result.num_amino_acid_mismatches_from_predicted_effect is not None assert result.num_amino_acid_mismatches_from_reference is not None assert result.num_amino_acid_mismatches_from_reference > 0 eq_(result.protein_sequence_matches_reference, False) eq_(result.protein_sequence_contains_mutation, True) else: assert result.num_amino_acid_mismatches_from_predicted_effect is None assert result.num_amino_acid_mismatches_from_reference is None assert result.protein_sequence_matches_predicted_mutation_effect is None assert result.protein_sequence_matches_reference is None assert result.protein_sequence_contains_mutation is None def test_isovar_result_clone(): for result in run_isovar( variants=data_path("data/b16.f10/b16.vcf"), alignment_file=data_path("data/b16.f10/b16.combined.sorted.bam")): result2 = result.clone() eq_(result, result2) def test_isovar_result_clone_with_updates(): for result in run_isovar( variants=data_path("data/b16.f10/b16.vcf"), alignment_file=data_path("data/b16.f10/b16.combined.sorted.bam")): result2 = result.clone_with_updates(variant=None) assert result != result2 def test_isovar_result_str(): for result in run_isovar( variants=data_path("data/b16.f10/b16.vcf"), alignment_file=data_path("data/b16.f10/b16.combined.sorted.bam")): s = str(result) assert len(s) > 0 assert s.startswith("IsovarResult(") assert s.endswith(")")
apache-2.0
[ 504, 11601, 1391, 492, 1255, 63, 4595, 1391, 199, 504, 11601, 1391, 492, 2165, 15859, 5826, 199, 504, 2729, 600, 492, 21107, 867, 199, 504, 5343, 63, 7546, 492, 666, 63, 515, 199, 199, 504, 11354, 14, 2537, 492, 3850, 63, 421, 199, 318, 511, 63, 4595, 1391, 63, 1099, 63, 1829, 63, 1313, 837, 272, 367, 754, 315, 1255, 63, 4595, 1391, 8, 288, 21169, 29, 576, 63, 515, 480, 576, 15, 66, 975, 14, 70, 709, 15, 66, 975, 14, 27288, 1288, 288, 13177, 63, 493, 29, 576, 63, 515, 480, 576, 15, 66, 975, 14, 70, 709, 15, 66, 975, 14, 17583, 14, 5917, 14, 21112, 14150, 267, 327, 9854, 267, 702, 730, 8, 1099, 14, 8759, 9, 365, 21107, 867, 398, 327, 8242, 402, 3805, 397, 436, 7115, 6429, 687, 9854, 267, 702, 730, 8, 1099, 14, 1507, 63, 31034, 63, 26965, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 31034, 63, 1523, 63, 26965, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 31034, 63, 27800, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 31034, 63, 1523, 63, 27800, 9, 365, 1109, 398, 327, 557, 15859, 3414, 267, 702, 730, 8, 1099, 14, 2119, 63, 496, 15859, 63, 4041, 9, 315, 334, 466, 8, 403, 395, 2165, 15859, 5826, 9, 398, 327, 8242, 402, 3805, 397, 436, 7115, 6429, 687, 557, 15859, 8013, 267, 702, 730, 8, 1099, 14, 1507, 63, 26965, 63, 504, 63, 496, 15859, 63, 13436, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 26965, 63, 504, 63, 2119, 63, 496, 15859, 63, 4041, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 27800, 63, 504, 63, 496, 15859, 63, 13436, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 27800, 63, 504, 63, 2119, 63, 496, 15859, 63, 4041, 9, 365, 1109, 398, 327, 1586, 436, 7956, 8242, 267, 702, 730, 8, 1099, 14, 1507, 63, 1121, 63, 15656, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 4478, 63, 15656, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 1848, 63, 15656, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 1121, 63, 18047, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 4478, 63, 18047, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 1848, 63, 18047, 9, 365, 1109, 398, 327, 1586, 436, 7956, 28213, 2452, 267, 702, 730, 8, 1099, 14, 13054, 63, 1121, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 4478, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 1848, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 1121, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 4478, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 1848, 63, 18047, 9, 365, 2069, 398, 327, 1586, 436, 7956, 2338, 660, 9636, 267, 702, 730, 8, 1099, 14, 6884, 63, 4478, 63, 475, 63, 1848, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 4478, 63, 475, 63, 1848, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1848, 63, 475, 63, 4478, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1848, 63, 475, 63, 4478, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1121, 63, 475, 63, 1848, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1848, 63, 475, 63, 1121, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1848, 63, 475, 63, 1121, 63, 15656, 9, 365, 2069, 398, 327, 642, 3324, 27535, 1006, 4766, 267, 702, 754, 14, 16027, 63, 452, 63, 4273, 315, 469, 549, 12, 756, 93, 398, 702, 730, 8, 1099, 14, 496, 15859, 63, 4041, 63, 11627, 63, 928, 63, 2996, 9, 315, 334, 442, 12, 730, 8, 403, 430, 267, 702, 730, 8, 1099, 14, 496, 15859, 63, 4041, 63, 11627, 63, 500, 63, 2996, 9, 315, 334, 442, 12, 730, 8, 403, 430, 421, 199, 318, 511, 63, 4595, 1391, 63, 1099, 63, 2865, 9466, 63, 15680, 837, 272, 367, 754, 315, 1255, 63, 4595, 1391, 8, 288, 21169, 29, 576, 63, 515, 480, 576, 15, 66, 975, 14, 70, 709, 15, 66, 975, 14, 27288, 1288, 288, 13177, 63, 493, 29, 576, 63, 515, 480, 576, 15, 66, 975, 14, 70, 709, 15, 66, 975, 14, 17583, 14, 5917, 14, 21112, 14150, 267, 870, 8, 1099, 14, 8759, 9, 267, 870, 8, 1099, 14, 21118, 63, 5881, 9, 267, 340, 754, 14, 1989, 63, 6552, 867, 63, 496, 15859, 63, 4041, 63, 504, 63, 82, 3540, 26, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 21118, 63, 5881, 365, 440, 488, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 4443, 365, 440, 488, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 4443, 690, 378, 288, 3850, 2531, 1099, 14, 496, 15859, 63, 4041, 63, 6742, 63, 4443, 12, 756, 9, 288, 3850, 2531, 1099, 14, 496, 15859, 63, 4041, 63, 6134, 63, 11627, 12, 715, 9, 267, 587, 26, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 21118, 63, 5881, 365, 488, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 4443, 365, 488, 288, 702, 754, 14, 496, 15859, 63, 4041, 63, 6742, 63, 21118, 63, 11627, 63, 5881, 365, 488, 288, 702, 754, 14, 496, 15859, 63, 4041, 63, 6742, 63, 4443, 365, 488, 288, 702, 754, 14, 496, 15859, 63, 4041, 63, 6134, 63, 11627, 365, 488, 421, 199, 318, 511, 63, 4595, 1391, 63, 1099, 63, 6311, 837, 272, 367, 754, 315, 1255, 63, 4595, 1391, 8, 288, 21169, 29, 576, 63, 515, 480, 576 ]
[ 11601, 1391, 492, 1255, 63, 4595, 1391, 199, 504, 11601, 1391, 492, 2165, 15859, 5826, 199, 504, 2729, 600, 492, 21107, 867, 199, 504, 5343, 63, 7546, 492, 666, 63, 515, 199, 199, 504, 11354, 14, 2537, 492, 3850, 63, 421, 199, 318, 511, 63, 4595, 1391, 63, 1099, 63, 1829, 63, 1313, 837, 272, 367, 754, 315, 1255, 63, 4595, 1391, 8, 288, 21169, 29, 576, 63, 515, 480, 576, 15, 66, 975, 14, 70, 709, 15, 66, 975, 14, 27288, 1288, 288, 13177, 63, 493, 29, 576, 63, 515, 480, 576, 15, 66, 975, 14, 70, 709, 15, 66, 975, 14, 17583, 14, 5917, 14, 21112, 14150, 267, 327, 9854, 267, 702, 730, 8, 1099, 14, 8759, 9, 365, 21107, 867, 398, 327, 8242, 402, 3805, 397, 436, 7115, 6429, 687, 9854, 267, 702, 730, 8, 1099, 14, 1507, 63, 31034, 63, 26965, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 31034, 63, 1523, 63, 26965, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 31034, 63, 27800, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 31034, 63, 1523, 63, 27800, 9, 365, 1109, 398, 327, 557, 15859, 3414, 267, 702, 730, 8, 1099, 14, 2119, 63, 496, 15859, 63, 4041, 9, 315, 334, 466, 8, 403, 395, 2165, 15859, 5826, 9, 398, 327, 8242, 402, 3805, 397, 436, 7115, 6429, 687, 557, 15859, 8013, 267, 702, 730, 8, 1099, 14, 1507, 63, 26965, 63, 504, 63, 496, 15859, 63, 13436, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 26965, 63, 504, 63, 2119, 63, 496, 15859, 63, 4041, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 27800, 63, 504, 63, 496, 15859, 63, 13436, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 27800, 63, 504, 63, 2119, 63, 496, 15859, 63, 4041, 9, 365, 1109, 398, 327, 1586, 436, 7956, 8242, 267, 702, 730, 8, 1099, 14, 1507, 63, 1121, 63, 15656, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 4478, 63, 15656, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 1848, 63, 15656, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 1121, 63, 18047, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 4478, 63, 18047, 9, 365, 1109, 267, 702, 730, 8, 1099, 14, 1507, 63, 1848, 63, 18047, 9, 365, 1109, 398, 327, 1586, 436, 7956, 28213, 2452, 267, 702, 730, 8, 1099, 14, 13054, 63, 1121, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 4478, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 1848, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 1121, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 4478, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 13054, 63, 1848, 63, 18047, 9, 365, 2069, 398, 327, 1586, 436, 7956, 2338, 660, 9636, 267, 702, 730, 8, 1099, 14, 6884, 63, 4478, 63, 475, 63, 1848, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 4478, 63, 475, 63, 1848, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1848, 63, 475, 63, 4478, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1848, 63, 475, 63, 4478, 63, 15656, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1121, 63, 475, 63, 1848, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1848, 63, 475, 63, 1121, 63, 18047, 9, 365, 2069, 267, 702, 730, 8, 1099, 14, 6884, 63, 1848, 63, 475, 63, 1121, 63, 15656, 9, 365, 2069, 398, 327, 642, 3324, 27535, 1006, 4766, 267, 702, 754, 14, 16027, 63, 452, 63, 4273, 315, 469, 549, 12, 756, 93, 398, 702, 730, 8, 1099, 14, 496, 15859, 63, 4041, 63, 11627, 63, 928, 63, 2996, 9, 315, 334, 442, 12, 730, 8, 403, 430, 267, 702, 730, 8, 1099, 14, 496, 15859, 63, 4041, 63, 11627, 63, 500, 63, 2996, 9, 315, 334, 442, 12, 730, 8, 403, 430, 421, 199, 318, 511, 63, 4595, 1391, 63, 1099, 63, 2865, 9466, 63, 15680, 837, 272, 367, 754, 315, 1255, 63, 4595, 1391, 8, 288, 21169, 29, 576, 63, 515, 480, 576, 15, 66, 975, 14, 70, 709, 15, 66, 975, 14, 27288, 1288, 288, 13177, 63, 493, 29, 576, 63, 515, 480, 576, 15, 66, 975, 14, 70, 709, 15, 66, 975, 14, 17583, 14, 5917, 14, 21112, 14150, 267, 870, 8, 1099, 14, 8759, 9, 267, 870, 8, 1099, 14, 21118, 63, 5881, 9, 267, 340, 754, 14, 1989, 63, 6552, 867, 63, 496, 15859, 63, 4041, 63, 504, 63, 82, 3540, 26, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 21118, 63, 5881, 365, 440, 488, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 4443, 365, 440, 488, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 4443, 690, 378, 288, 3850, 2531, 1099, 14, 496, 15859, 63, 4041, 63, 6742, 63, 4443, 12, 756, 9, 288, 3850, 2531, 1099, 14, 496, 15859, 63, 4041, 63, 6134, 63, 11627, 12, 715, 9, 267, 587, 26, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 21118, 63, 5881, 365, 488, 288, 702, 754, 14, 1507, 63, 455, 10175, 63, 645, 344, 63, 1292, 6742, 63, 504, 63, 4443, 365, 488, 288, 702, 754, 14, 496, 15859, 63, 4041, 63, 6742, 63, 21118, 63, 11627, 63, 5881, 365, 488, 288, 702, 754, 14, 496, 15859, 63, 4041, 63, 6742, 63, 4443, 365, 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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 ]
ubuntunux/GuineaPig
PyEngine3D/OpenGLContext/UniformBuffer.py
2
11521
import traceback import numpy as np from OpenGL.GL import * from PyEngine3D.Common import logger from PyEngine3D.App import CoreManager ignore_uniform_types = ["atomic_bool", "atomic_uint", "atomic_int", "atomic_float"] def CreateUniformDataFromString(data_type, strValue=None): """ return converted data from string or default data """ if data_type == 'bool': return np.bool(strValue) if strValue else np.bool(False) elif data_type == 'float': # return float(strValue) if strValue else 0.0 return np.float32(strValue) if strValue else np.float32(0) elif data_type == 'int': # return int(strValue) if strValue else 0 return np.int32(strValue) if strValue else np.int32(0) elif data_type == 'uint': # return int(strValue) if strValue else 0 return np.uint32(strValue) if strValue else np.uint32(0) elif data_type in ('vec2', 'vec3', 'vec4', 'bvec2', 'bvec3', 'bvec4', 'ivec2', 'ivec3', 'ivec4', 'uvec2', 'uvec3', 'uvec4'): if data_type in ('bvec2', 'bvec3', 'bvec4', 'ivec2', 'ivec3', 'ivec4'): dtype = np.int32 elif data_type in ('uvec2', 'uvec3', 'uvec4'): dtype = np.uint32 else: dtype = np.float32 componentCount = int(data_type[-1]) if strValue is not None: vecValue = eval(strValue) if type(strValue) is str else strValue if len(vecValue) == componentCount: return np.array(vecValue, dtype=dtype) else: logger.error(ValueError("%s need %d float members." % (data_type, componentCount))) raise ValueError else: return np.array([1, ] * componentCount, dtype=dtype) elif data_type in ('mat2', 'mat3', 'mat4', 'dmat2', 'dmat3', 'dmat4'): if data_type in ('dmat2', 'dmat3', 'dmat4'): dtype = np.float32 else: dtype = np.double componentCount = int(data_type[-1]) if strValue is not None: vecValue = eval(strValue) if type(strValue) is str else strValue if len(vecValue) == componentCount: return np.array(vecValue, dtype=dtype) else: logger.error(ValueError("%s need %d float members." % (data_type, componentCount))) raise ValueError else: return np.eye(componentCount, dtype=dtype) elif data_type in ('sampler2D', 'image2D'): texture = CoreManager.instance().resource_manager.get_texture(strValue or 'common.flat_white') return texture elif data_type == 'sampler2DMS': logger.warn('sampler2DMS need multisample texture.') return CoreManager.instance().resource_manager.get_texture(strValue or 'common.flat_white') elif data_type == 'sampler2DArray': return CoreManager.instance().resource_manager.get_texture(strValue or 'common.default_2d_array') elif data_type in ('sampler3D', 'image3D'): return CoreManager.instance().resource_manager.get_texture(strValue or 'common.default_3d') elif data_type == 'samplerCube': texture = CoreManager.instance().resource_manager.get_texture(strValue or 'common.default_cube') return texture error_message = 'Cannot find uniform data of %s.' % data_type logger.error(error_message) raise ValueError(error_message) return None def CreateUniformBuffer(program, uniform_type, uniform_name, default_data=None): """ create uniform buffer from .mat(shader) file """ uniform_classes = [ UniformBool, UniformInt, UniformUint, UniformFloat, UniformVector2, UniformVector3, UniformVector4, UniformBoolVector2, UniformBoolVector3, UniformBoolVector4, UniformIntVector2, UniformIntVector3, UniformIntVector4, UniformUintVector2, UniformUintVector3, UniformUintVector4, UniformMatrix2, UniformMatrix3, UniformMatrix4, UniformDoubleMatrix2, UniformDoubleMatrix3, UniformDoubleMatrix4, UniformTexture2D, UniformTexture2DMultiSample, UniformTexture2DArray, UniformTexture3D, UniformTextureCube, UniformImage2D, UniformImage3D ] for uniform_class in uniform_classes: if uniform_type == uniform_class.uniform_type: if default_data is not None: uniform_data = default_data else: uniform_data = CreateUniformDataFromString(uniform_type) uniform_buffer = uniform_class(program, uniform_name) uniform_buffer.set_default_value(uniform_data) return uniform_buffer if uniform_buffer.valid else None else: if uniform_type not in ignore_uniform_types: error_message = 'Cannot matched to %s type of %s.' % (uniform_type, uniform_name) logger.error(error_message) raise BaseException(error_message) return None class UniformVariable: data_type = "" uniform_type = "" def __init__(self, program, variable_name): self.name = variable_name self.location = glGetUniformLocation(program, variable_name) self.show_message = True self.default_value = None self.valid = True if self.location == -1: self.valid = False # logger.warn("%s location is -1" % variable_name) def set_default_value(self, value): self.default_value = value def get_default_value(self): return self.default_value def bind_uniform(self, value): raise BaseException("You must implement bind function.") class UniformArray(UniformVariable): """future work : http://pyopengl.sourceforge.net/context/tutorials/shader_7.html""" uniform_type = "" class UniformBool(UniformVariable): uniform_type = "bool" def bind_uniform(self, value): glUniform1i(self.location, value) class UniformInt(UniformVariable): uniform_type = "int" def bind_uniform(self, value): glUniform1i(self.location, value) class UniformUint(UniformVariable): uniform_type = "uint" def bind_uniform(self, value): glUniform1ui(self.location, value) class UniformFloat(UniformVariable): uniform_type = "float" def bind_uniform(self, value): glUniform1f(self.location, value) class UniformVector2(UniformVariable): uniform_type = "vec2" def bind_uniform(self, value, num=1): glUniform2fv(self.location, num, value) class UniformVector3(UniformVariable): uniform_type = "vec3" def bind_uniform(self, value, num=1): glUniform3fv(self.location, num, value) class UniformVector4(UniformVariable): uniform_type = "vec4" def bind_uniform(self, value, num=1): glUniform4fv(self.location, num, value) class UniformBoolVector2(UniformVariable): uniform_type = "bvec2" def bind_uniform(self, value, num=1): glUniform2iv(self.location, num, value) class UniformBoolVector3(UniformVariable): uniform_type = "bvec3" def bind_uniform(self, value, num=1): glUniform3iv(self.location, num, value) class UniformBoolVector4(UniformVariable): uniform_type = "bvec4" def bind_uniform(self, value, num=1): glUniform4iv(self.location, num, value) class UniformIntVector2(UniformVariable): uniform_type = "ivec2" def bind_uniform(self, value, num=1): glUniform2iv(self.location, num, value) class UniformIntVector3(UniformVariable): uniform_type = "ivec3" def bind_uniform(self, value, num=1): glUniform3iv(self.location, num, value) class UniformIntVector4(UniformVariable): uniform_type = "ivec4" def bind_uniform(self, value, num=1): glUniform4iv(self.location, num, value) class UniformUintVector2(UniformVariable): uniform_type = "uvec2" def bind_uniform(self, value, num=1): glUniform2uiv(self.location, num, value) class UniformUintVector3(UniformVariable): uniform_type = "uvec3" def bind_uniform(self, value, num=1): glUniform3uiv(self.location, num, value) class UniformUintVector4(UniformVariable): uniform_type = "uvec4" def bind_uniform(self, value, num=1): glUniform4uiv(self.location, num, value) class UniformMatrix2(UniformVariable): uniform_type = "mat2" def bind_uniform(self, value, num=1, transpose=False): glUniformMatrix2fv(self.location, num, GL_TRUE if transpose else GL_FALSE, value) class UniformMatrix3(UniformVariable): uniform_type = "mat3" def bind_uniform(self, value, num=1, transpose=False): glUniformMatrix3fv(self.location, num, GL_TRUE if transpose else GL_FALSE, value) class UniformMatrix4(UniformVariable): uniform_type = "mat4" def bind_uniform(self, value, num=1, transpose=False): glUniformMatrix4fv(self.location, num, GL_TRUE if transpose else GL_FALSE, value) class UniformDoubleMatrix2(UniformVariable): uniform_type = "dmat2" def bind_uniform(self, value, num=1, transpose=False): glUniformMatrix2dv(self.location, num, GL_TRUE if transpose else GL_FALSE, value) class UniformDoubleMatrix3(UniformVariable): uniform_type = "dmat3" def bind_uniform(self, value, num=1, transpose=False): glUniformMatrix3dv(self.location, num, GL_TRUE if transpose else GL_FALSE, value) class UniformDoubleMatrix4(UniformVariable): uniform_type = "dmat4" def bind_uniform(self, value, num=1, transpose=False): glUniformMatrix4dv(self.location, num, GL_TRUE if transpose else GL_FALSE, value) class UniformTextureBase(UniformVariable): uniform_type = "UniformTextureBase" texture_offset = 0 def __init__(self, program, variable_name): UniformVariable.__init__(self, program, variable_name) self.textureIndex = 0 def set_texture_index(self, textureIndex): self.textureIndex = textureIndex + self.texture_offset def bind_uniform(self, texture, wrap=None): if texture is not None: glActiveTexture(GL_TEXTURE0 + self.textureIndex) texture.bind_texture(wrap) glUniform1i(self.location, self.textureIndex) elif self.show_message: self.show_message = False logger.error("%s %s is None" % (self.name, self.__class__.__name__)) class UniformTexture2D(UniformTextureBase): uniform_type = "sampler2D" texture_offset = 0 class UniformTexture2DArray(UniformTextureBase): uniform_type = "sampler2DArray" texture_offset = 16 class UniformTexture2DMultiSample(UniformTextureBase): uniform_type = "sampler2DMS" texture_offset = 32 class UniformTexture3D(UniformTextureBase): uniform_type = "sampler3D" texture_offset = 48 class UniformTextureCube(UniformTextureBase): uniform_type = "samplerCube" texture_offset = 64 class UniformImageBase(UniformTextureBase): uniform_type = "UniformImageBase" def set_texture_index(self, textureIndex): self.textureIndex = textureIndex def bind_uniform(self, texture, level=0, access=GL_READ_WRITE): if texture is not None: texture.bind_image(self.textureIndex, level, access) elif self.show_message: self.show_message = False logger.error("%s %s is None" % (self.name, self.__class__.__name__)) class UniformImage2D(UniformImageBase): uniform_type = "image2D" texture_offset = 0 class UniformImage3D(UniformImageBase): uniform_type = "image3D" texture_offset = 48
bsd-2-clause
[ 646, 5190, 199, 199, 646, 2680, 465, 980, 199, 504, 24374, 14, 2226, 492, 627, 199, 199, 504, 1611, 8524, 19, 36, 14, 7844, 492, 2512, 199, 504, 1611, 8524, 19, 36, 14, 2640, 492, 11672, 2988, 421, 199, 4247, 63, 8830, 63, 1313, 275, 2097, 10910, 63, 2245, 401, 298, 10910, 63, 1635, 401, 298, 10910, 63, 442, 401, 298, 10910, 63, 1609, 937, 421, 199, 318, 2790, 12421, 1451, 7671, 8, 576, 63, 466, 12, 620, 1110, 29, 403, 304, 272, 408, 372, 6702, 666, 687, 1059, 503, 849, 666, 408, 272, 340, 666, 63, 466, 508, 283, 2245, 356, 267, 372, 980, 14, 2245, 8, 495, 1110, 9, 340, 620, 1110, 587, 980, 14, 2245, 8, 797, 9, 272, 916, 666, 63, 466, 508, 283, 1609, 356, 267, 327, 372, 2069, 8, 495, 1110, 9, 340, 620, 1110, 587, 378, 14, 16, 267, 372, 980, 14, 1609, 708, 8, 495, 1110, 9, 340, 620, 1110, 587, 980, 14, 1609, 708, 8, 16, 9, 272, 916, 666, 63, 466, 508, 283, 442, 356, 267, 327, 372, 1109, 8, 495, 1110, 9, 340, 620, 1110, 587, 378, 267, 372, 980, 14, 442, 708, 8, 495, 1110, 9, 340, 620, 1110, 587, 980, 14, 442, 708, 8, 16, 9, 272, 916, 666, 63, 466, 508, 283, 1635, 356, 267, 327, 372, 1109, 8, 495, 1110, 9, 340, 620, 1110, 587, 378, 267, 372, 980, 14, 1635, 708, 8, 495, 1110, 9, 340, 620, 1110, 587, 980, 14, 1635, 708, 8, 16, 9, 272, 916, 666, 63, 466, 315, 661, 6046, 18, 297, 283, 6046, 19, 297, 283, 6046, 20, 297, 283, 66, 6046, 18, 297, 283, 66, 6046, 19, 297, 283, 66, 6046, 20, 297, 283, 1912, 67, 18, 297, 283, 1912, 67, 19, 297, 283, 1912, 67, 20, 297, 283, 85, 6046, 18, 297, 283, 85, 6046, 19, 297, 283, 85, 6046, 20, 735, 267, 340, 666, 63, 466, 315, 661, 66, 6046, 18, 297, 283, 66, 6046, 19, 297, 283, 66, 6046, 20, 297, 283, 1912, 67, 18, 297, 283, 1912, 67, 19, 297, 283, 1912, 67, 20, 735, 288, 2152, 275, 980, 14, 442, 708, 267, 916, 666, 63, 466, 315, 661, 85, 6046, 18, 297, 283, 85, 6046, 19, 297, 283, 85, 6046, 20, 735, 288, 2152, 275, 980, 14, 1635, 708, 267, 587, 26, 288, 2152, 275, 980, 14, 1609, 708, 398, 3931, 2353, 275, 1109, 8, 576, 63, 466, 1988, 17, 566, 267, 340, 620, 1110, 365, 440, 488, 26, 288, 10782, 1110, 275, 3468, 8, 495, 1110, 9, 340, 730, 8, 495, 1110, 9, 365, 620, 587, 620, 1110, 288, 340, 822, 8, 6046, 1110, 9, 508, 3931, 2353, 26, 355, 372, 980, 14, 1144, 8, 6046, 1110, 12, 2152, 29, 2271, 9, 288, 587, 26, 355, 2512, 14, 705, 8, 3393, 3647, 83, 1929, 450, 68, 2069, 7556, 2122, 450, 334, 576, 63, 466, 12, 3931, 2353, 1724, 355, 746, 1722, 267, 587, 26, 288, 372, 980, 14, 1144, 779, 17, 12, 1622, 627, 3931, 2353, 12, 2152, 29, 2271, 9, 272, 916, 666, 63, 466, 315, 661, 569, 18, 297, 283, 569, 19, 297, 283, 569, 20, 297, 283, 68, 569, 18, 297, 283, 68, 569, 19, 297, 283, 68, 569, 20, 735, 267, 340, 666, 63, 466, 315, 661, 68, 569, 18, 297, 283, 68, 569, 19, 297, 283, 68, 569, 20, 735, 288, 2152, 275, 980, 14, 1609, 708, 267, 587, 26, 288, 2152, 275, 980, 14, 3157, 267, 3931, 2353, 275, 1109, 8, 576, 63, 466, 1988, 17, 566, 267, 340, 620, 1110, 365, 440, 488, 26, 288, 10782, 1110, 275, 3468, 8, 495, 1110, 9, 340, 730, 8, 495, 1110, 9, 365, 620, 587, 620, 1110, 288, 340, 822, 8, 6046, 1110, 9, 508, 3931, 2353, 26, 355, 372, 980, 14, 1144, 8, 6046, 1110, 12, 2152, 29, 2271, 9, 288, 587, 26, 355, 2512, 14, 705, 8, 3393, 3647, 83, 1929, 450, 68, 2069, 7556, 2122, 450, 334, 576, 63, 466, 12, 3931, 2353, 1724, 355, 746, 1722, 267, 587, 26, 288, 372, 980, 14, 15240, 8, 3173, 2353, 12, 2152, 29, 2271, 9, 272, 916, 666, 63, 466, 315, 661, 22934, 18, 36, 297, 283, 1569, 18, 36, 735, 267, 14855, 275, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 7088, 63, 7510, 358, 267, 372, 14855, 272, 916, 666, 63, 466, 508, 283, 22934, 18, 36, 3053, 356, 267, 2512, 14, 4050, 360, 22934, 18, 36, 3053, 1929, 3510, 3271, 14855, 2659, 267, 372, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 7088, 63, 7510, 358, 272, 916, 666, 63, 466, 508, 283, 22934, 18, 36, 3836, 356, 267, 372, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 885, 63, 18, 68, 63, 1144, 358, 272, 916, 666, 63, 466, 315, 661, 22934, 19, 36, 297, 283, 1569, 19, 36, 735, 267, 372, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 885, 63, 19, 68, 358, 272, 916, 666, 63, 466, 508, 283, 22934, 25043, 356, 267, 14855, 275, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 885, 63, 11477, 358, 267, 372, 14855, 339, 1125, 63, 1188, 275, 283, 6612, 2342, 14818, 666, 402, 450, 83, 3530, 450, 666, 63, 466, 272, 2512, 14, 705, 8, 705, 63, 1188, 9, 272, 746, 1722, 8, 705, 63, 1188, 9, 272, 372, 488, 421, 199, 318, 2790, 12421, 3299, 8, 6815, 12, 14818, 63, 466, 12, 14818, 63, 354, 12, 849, 63, 576, 29, 403, 304, 272, 408, 1218, 14818, 3335, 687, 1275, 569, 8, 18116, 9, 570, 408, 272, 14818, 63, 2888, 275, 359, 267, 1910, 8241, 10349, 12, 1910, 8241, 3241, 12, 1910, 8241, 23448, 12, 1910, 8241, 5136, 12, 267, 1910, 8241, 3646, 18, 12, 1910, 8241, 3646, 19, 12, 1910, 8241, 3646, 20, 12, 267, 1910, 8241, 10349, 3646, 18 ]
[ 5190, 199, 199, 646, 2680, 465, 980, 199, 504, 24374, 14, 2226, 492, 627, 199, 199, 504, 1611, 8524, 19, 36, 14, 7844, 492, 2512, 199, 504, 1611, 8524, 19, 36, 14, 2640, 492, 11672, 2988, 421, 199, 4247, 63, 8830, 63, 1313, 275, 2097, 10910, 63, 2245, 401, 298, 10910, 63, 1635, 401, 298, 10910, 63, 442, 401, 298, 10910, 63, 1609, 937, 421, 199, 318, 2790, 12421, 1451, 7671, 8, 576, 63, 466, 12, 620, 1110, 29, 403, 304, 272, 408, 372, 6702, 666, 687, 1059, 503, 849, 666, 408, 272, 340, 666, 63, 466, 508, 283, 2245, 356, 267, 372, 980, 14, 2245, 8, 495, 1110, 9, 340, 620, 1110, 587, 980, 14, 2245, 8, 797, 9, 272, 916, 666, 63, 466, 508, 283, 1609, 356, 267, 327, 372, 2069, 8, 495, 1110, 9, 340, 620, 1110, 587, 378, 14, 16, 267, 372, 980, 14, 1609, 708, 8, 495, 1110, 9, 340, 620, 1110, 587, 980, 14, 1609, 708, 8, 16, 9, 272, 916, 666, 63, 466, 508, 283, 442, 356, 267, 327, 372, 1109, 8, 495, 1110, 9, 340, 620, 1110, 587, 378, 267, 372, 980, 14, 442, 708, 8, 495, 1110, 9, 340, 620, 1110, 587, 980, 14, 442, 708, 8, 16, 9, 272, 916, 666, 63, 466, 508, 283, 1635, 356, 267, 327, 372, 1109, 8, 495, 1110, 9, 340, 620, 1110, 587, 378, 267, 372, 980, 14, 1635, 708, 8, 495, 1110, 9, 340, 620, 1110, 587, 980, 14, 1635, 708, 8, 16, 9, 272, 916, 666, 63, 466, 315, 661, 6046, 18, 297, 283, 6046, 19, 297, 283, 6046, 20, 297, 283, 66, 6046, 18, 297, 283, 66, 6046, 19, 297, 283, 66, 6046, 20, 297, 283, 1912, 67, 18, 297, 283, 1912, 67, 19, 297, 283, 1912, 67, 20, 297, 283, 85, 6046, 18, 297, 283, 85, 6046, 19, 297, 283, 85, 6046, 20, 735, 267, 340, 666, 63, 466, 315, 661, 66, 6046, 18, 297, 283, 66, 6046, 19, 297, 283, 66, 6046, 20, 297, 283, 1912, 67, 18, 297, 283, 1912, 67, 19, 297, 283, 1912, 67, 20, 735, 288, 2152, 275, 980, 14, 442, 708, 267, 916, 666, 63, 466, 315, 661, 85, 6046, 18, 297, 283, 85, 6046, 19, 297, 283, 85, 6046, 20, 735, 288, 2152, 275, 980, 14, 1635, 708, 267, 587, 26, 288, 2152, 275, 980, 14, 1609, 708, 398, 3931, 2353, 275, 1109, 8, 576, 63, 466, 1988, 17, 566, 267, 340, 620, 1110, 365, 440, 488, 26, 288, 10782, 1110, 275, 3468, 8, 495, 1110, 9, 340, 730, 8, 495, 1110, 9, 365, 620, 587, 620, 1110, 288, 340, 822, 8, 6046, 1110, 9, 508, 3931, 2353, 26, 355, 372, 980, 14, 1144, 8, 6046, 1110, 12, 2152, 29, 2271, 9, 288, 587, 26, 355, 2512, 14, 705, 8, 3393, 3647, 83, 1929, 450, 68, 2069, 7556, 2122, 450, 334, 576, 63, 466, 12, 3931, 2353, 1724, 355, 746, 1722, 267, 587, 26, 288, 372, 980, 14, 1144, 779, 17, 12, 1622, 627, 3931, 2353, 12, 2152, 29, 2271, 9, 272, 916, 666, 63, 466, 315, 661, 569, 18, 297, 283, 569, 19, 297, 283, 569, 20, 297, 283, 68, 569, 18, 297, 283, 68, 569, 19, 297, 283, 68, 569, 20, 735, 267, 340, 666, 63, 466, 315, 661, 68, 569, 18, 297, 283, 68, 569, 19, 297, 283, 68, 569, 20, 735, 288, 2152, 275, 980, 14, 1609, 708, 267, 587, 26, 288, 2152, 275, 980, 14, 3157, 267, 3931, 2353, 275, 1109, 8, 576, 63, 466, 1988, 17, 566, 267, 340, 620, 1110, 365, 440, 488, 26, 288, 10782, 1110, 275, 3468, 8, 495, 1110, 9, 340, 730, 8, 495, 1110, 9, 365, 620, 587, 620, 1110, 288, 340, 822, 8, 6046, 1110, 9, 508, 3931, 2353, 26, 355, 372, 980, 14, 1144, 8, 6046, 1110, 12, 2152, 29, 2271, 9, 288, 587, 26, 355, 2512, 14, 705, 8, 3393, 3647, 83, 1929, 450, 68, 2069, 7556, 2122, 450, 334, 576, 63, 466, 12, 3931, 2353, 1724, 355, 746, 1722, 267, 587, 26, 288, 372, 980, 14, 15240, 8, 3173, 2353, 12, 2152, 29, 2271, 9, 272, 916, 666, 63, 466, 315, 661, 22934, 18, 36, 297, 283, 1569, 18, 36, 735, 267, 14855, 275, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 7088, 63, 7510, 358, 267, 372, 14855, 272, 916, 666, 63, 466, 508, 283, 22934, 18, 36, 3053, 356, 267, 2512, 14, 4050, 360, 22934, 18, 36, 3053, 1929, 3510, 3271, 14855, 2659, 267, 372, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 7088, 63, 7510, 358, 272, 916, 666, 63, 466, 508, 283, 22934, 18, 36, 3836, 356, 267, 372, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 885, 63, 18, 68, 63, 1144, 358, 272, 916, 666, 63, 466, 315, 661, 22934, 19, 36, 297, 283, 1569, 19, 36, 735, 267, 372, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 885, 63, 19, 68, 358, 272, 916, 666, 63, 466, 508, 283, 22934, 25043, 356, 267, 14855, 275, 11672, 2988, 14, 842, 1252, 1927, 63, 2609, 14, 362, 63, 12611, 8, 495, 1110, 503, 283, 2330, 14, 885, 63, 11477, 358, 267, 372, 14855, 339, 1125, 63, 1188, 275, 283, 6612, 2342, 14818, 666, 402, 450, 83, 3530, 450, 666, 63, 466, 272, 2512, 14, 705, 8, 705, 63, 1188, 9, 272, 746, 1722, 8, 705, 63, 1188, 9, 272, 372, 488, 421, 199, 318, 2790, 12421, 3299, 8, 6815, 12, 14818, 63, 466, 12, 14818, 63, 354, 12, 849, 63, 576, 29, 403, 304, 272, 408, 1218, 14818, 3335, 687, 1275, 569, 8, 18116, 9, 570, 408, 272, 14818, 63, 2888, 275, 359, 267, 1910, 8241, 10349, 12, 1910, 8241, 3241, 12, 1910, 8241, 23448, 12, 1910, 8241, 5136, 12, 267, 1910, 8241, 3646, 18, 12, 1910, 8241, 3646, 19, 12, 1910, 8241, 3646, 20, 12, 267, 1910, 8241, 10349, 3646, 18, 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, 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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 ]
xiangel/hue
desktop/core/ext-py/Django-1.6.10/django/contrib/admin/views/main.py
47
17811
import sys import warnings from django.core.exceptions import SuspiciousOperation, ImproperlyConfigured from django.core.paginator import InvalidPage from django.core.urlresolvers import reverse from django.db import models from django.db.models.fields import FieldDoesNotExist from django.utils import six from django.utils.datastructures import SortedDict from django.utils.deprecation import RenameMethodsBase from django.utils.encoding import force_str, force_text from django.utils.translation import ugettext, ugettext_lazy from django.utils.http import urlencode from django.contrib.admin import FieldListFilter from django.contrib.admin.exceptions import DisallowedModelAdminLookup, DisallowedModelAdminToField from django.contrib.admin.options import IncorrectLookupParameters, IS_POPUP_VAR from django.contrib.admin.util import (quote, get_fields_from_path, lookup_needs_distinct, prepare_lookup_value) # Changelist settings ALL_VAR = 'all' ORDER_VAR = 'o' ORDER_TYPE_VAR = 'ot' PAGE_VAR = 'p' SEARCH_VAR = 'q' TO_FIELD_VAR = 't' ERROR_FLAG = 'e' IGNORED_PARAMS = ( ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR, TO_FIELD_VAR) # Text to display within change-list table cells if the value is blank. EMPTY_CHANGELIST_VALUE = ugettext_lazy('(None)') def _is_changelist_popup(request): """ Returns True if the popup GET parameter is set. This function is introduced to facilitate deprecating the legacy value for IS_POPUP_VAR and should be removed at the end of the deprecation cycle. """ if IS_POPUP_VAR in request.GET: return True IS_LEGACY_POPUP_VAR = 'pop' if IS_LEGACY_POPUP_VAR in request.GET: warnings.warn( "The `%s` GET parameter has been renamed to `%s`." % (IS_LEGACY_POPUP_VAR, IS_POPUP_VAR), PendingDeprecationWarning, 2) return True return False class RenameChangeListMethods(RenameMethodsBase): renamed_methods = ( ('get_query_set', 'get_queryset', PendingDeprecationWarning), ) class ChangeList(six.with_metaclass(RenameChangeListMethods)): def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, list_max_show_all, list_editable, model_admin): self.model = model self.opts = model._meta self.lookup_opts = self.opts self.root_queryset = model_admin.get_queryset(request) self.list_display = list_display self.list_display_links = list_display_links self.list_filter = list_filter self.date_hierarchy = date_hierarchy self.search_fields = search_fields self.list_select_related = list_select_related self.list_per_page = list_per_page self.list_max_show_all = list_max_show_all self.model_admin = model_admin self.preserved_filters = model_admin.get_preserved_filters(request) # Get search parameters from the query string. try: self.page_num = int(request.GET.get(PAGE_VAR, 0)) except ValueError: self.page_num = 0 self.show_all = ALL_VAR in request.GET self.is_popup = _is_changelist_popup(request) to_field = request.GET.get(TO_FIELD_VAR) if to_field and not model_admin.to_field_allowed(request, to_field): raise DisallowedModelAdminToField("The field %s cannot be referenced." % to_field) self.to_field = to_field self.params = dict(request.GET.items()) if PAGE_VAR in self.params: del self.params[PAGE_VAR] if ERROR_FLAG in self.params: del self.params[ERROR_FLAG] if self.is_popup: self.list_editable = () else: self.list_editable = list_editable self.query = request.GET.get(SEARCH_VAR, '') self.queryset = self.get_queryset(request) self.get_results(request) if self.is_popup: title = ugettext('Select %s') else: title = ugettext('Select %s to change') self.title = title % force_text(self.opts.verbose_name) self.pk_attname = self.lookup_opts.pk.attname @property def root_query_set(self): warnings.warn("`ChangeList.root_query_set` is deprecated, " "use `root_queryset` instead.", PendingDeprecationWarning, 2) return self.root_queryset @property def query_set(self): warnings.warn("`ChangeList.query_set` is deprecated, " "use `queryset` instead.", PendingDeprecationWarning, 2) return self.queryset def get_filters_params(self, params=None): """ Returns all params except IGNORED_PARAMS """ if not params: params = self.params lookup_params = params.copy() # a dictionary of the query string # Remove all the parameters that are globally and systematically # ignored. for ignored in IGNORED_PARAMS: if ignored in lookup_params: del lookup_params[ignored] return lookup_params def get_filters(self, request): lookup_params = self.get_filters_params() use_distinct = False # Normalize the types of keys for key, value in lookup_params.items(): if not isinstance(key, str): # 'key' will be used as a keyword argument later, so Python # requires it to be a string. del lookup_params[key] lookup_params[force_str(key)] = value if not self.model_admin.lookup_allowed(key, value): raise DisallowedModelAdminLookup("Filtering by %s not allowed" % key) filter_specs = [] if self.list_filter: for list_filter in self.list_filter: if callable(list_filter): # This is simply a custom list filter class. spec = list_filter(request, lookup_params, self.model, self.model_admin) else: field_path = None if isinstance(list_filter, (tuple, list)): # This is a custom FieldListFilter class for a given field. field, field_list_filter_class = list_filter else: # This is simply a field name, so use the default # FieldListFilter class that has been registered for # the type of the given field. field, field_list_filter_class = list_filter, FieldListFilter.create if not isinstance(field, models.Field): field_path = field field = get_fields_from_path(self.model, field_path)[-1] spec = field_list_filter_class(field, request, lookup_params, self.model, self.model_admin, field_path=field_path) # Check if we need to use distinct() use_distinct = (use_distinct or lookup_needs_distinct(self.lookup_opts, field_path)) if spec and spec.has_output(): filter_specs.append(spec) # At this point, all the parameters used by the various ListFilters # have been removed from lookup_params, which now only contains other # parameters passed via the query string. We now loop through the # remaining parameters both to ensure that all the parameters are valid # fields and to determine if at least one of them needs distinct(). If # the lookup parameters aren't real fields, then bail out. try: for key, value in lookup_params.items(): lookup_params[key] = prepare_lookup_value(key, value) use_distinct = (use_distinct or lookup_needs_distinct(self.lookup_opts, key)) return filter_specs, bool(filter_specs), lookup_params, use_distinct except FieldDoesNotExist as e: six.reraise(IncorrectLookupParameters, IncorrectLookupParameters(e), sys.exc_info()[2]) def get_query_string(self, new_params=None, remove=None): if new_params is None: new_params = {} if remove is None: remove = [] p = self.params.copy() for r in remove: for k in list(p): if k.startswith(r): del p[k] for k, v in new_params.items(): if v is None: if k in p: del p[k] else: p[k] = v return '?%s' % urlencode(sorted(p.items())) def get_results(self, request): paginator = self.model_admin.get_paginator(request, self.queryset, self.list_per_page) # Get the number of objects, with admin filters applied. result_count = paginator.count # Get the total number of objects, with no admin filters applied. # Perform a slight optimization: # full_result_count is equal to paginator.count if no filters # were applied if self.get_filters_params() or self.params.get(SEARCH_VAR): full_result_count = self.root_queryset.count() else: full_result_count = result_count can_show_all = result_count <= self.list_max_show_all multi_page = result_count > self.list_per_page # Get the list of objects to display on this page. if (self.show_all and can_show_all) or not multi_page: result_list = self.queryset._clone() else: try: result_list = paginator.page(self.page_num+1).object_list except InvalidPage: raise IncorrectLookupParameters self.result_count = result_count self.full_result_count = full_result_count self.result_list = result_list self.can_show_all = can_show_all self.multi_page = multi_page self.paginator = paginator def _get_default_ordering(self): ordering = [] if self.model_admin.ordering: ordering = self.model_admin.ordering elif self.lookup_opts.ordering: ordering = self.lookup_opts.ordering return ordering def get_ordering_field(self, field_name): """ Returns the proper model field name corresponding to the given field_name to use for ordering. field_name may either be the name of a proper model field or the name of a method (on the admin or model) or a callable with the 'admin_order_field' attribute. Returns None if no proper model field name can be matched. """ try: field = self.lookup_opts.get_field(field_name) return field.name except models.FieldDoesNotExist: # See whether field_name is a name of a non-field # that allows sorting. if callable(field_name): attr = field_name elif hasattr(self.model_admin, field_name): attr = getattr(self.model_admin, field_name) else: attr = getattr(self.model, field_name) return getattr(attr, 'admin_order_field', None) def get_ordering(self, request, queryset): """ Returns the list of ordering fields for the change list. First we check the get_ordering() method in model admin, then we check the object's default ordering. Then, any manually-specified ordering from the query string overrides anything. Finally, a deterministic order is guaranteed by ensuring the primary key is used as the last ordering field. """ params = self.params ordering = list(self.model_admin.get_ordering(request) or self._get_default_ordering()) if ORDER_VAR in params: # Clear ordering and used params ordering = [] order_params = params[ORDER_VAR].split('.') for p in order_params: try: none, pfx, idx = p.rpartition('-') field_name = self.list_display[int(idx)] order_field = self.get_ordering_field(field_name) if not order_field: continue # No 'admin_order_field', skip it ordering.append(pfx + order_field) except (IndexError, ValueError): continue # Invalid ordering specified, skip it. # Add the given query's ordering fields, if any. ordering.extend(queryset.query.order_by) # Ensure that the primary key is systematically present in the list of # ordering fields so we can guarantee a deterministic order across all # database backends. pk_name = self.lookup_opts.pk.name if not (set(ordering) & set(['pk', '-pk', pk_name, '-' + pk_name])): # The two sets do not intersect, meaning the pk isn't present. So # we add it. ordering.append('-pk') return ordering def get_ordering_field_columns(self): """ Returns a SortedDict of ordering field column numbers and asc/desc """ # We must cope with more than one column having the same underlying sort # field, so we base things on column numbers. ordering = self._get_default_ordering() ordering_fields = SortedDict() if ORDER_VAR not in self.params: # for ordering specified on ModelAdmin or model Meta, we don't know # the right column numbers absolutely, because there might be more # than one column associated with that ordering, so we guess. for field in ordering: if field.startswith('-'): field = field[1:] order_type = 'desc' else: order_type = 'asc' for index, attr in enumerate(self.list_display): if self.get_ordering_field(attr) == field: ordering_fields[index] = order_type break else: for p in self.params[ORDER_VAR].split('.'): none, pfx, idx = p.rpartition('-') try: idx = int(idx) except ValueError: continue # skip it ordering_fields[idx] = 'desc' if pfx == '-' else 'asc' return ordering_fields def get_queryset(self, request): # First, we collect all the declared list filters. (self.filter_specs, self.has_filters, remaining_lookup_params, filters_use_distinct) = self.get_filters(request) # Then, we let every list filter modify the queryset to its liking. qs = self.root_queryset for filter_spec in self.filter_specs: new_qs = filter_spec.queryset(request, qs) if new_qs is not None: qs = new_qs try: # Finally, we apply the remaining lookup parameters from the query # string (i.e. those that haven't already been processed by the # filters). qs = qs.filter(**remaining_lookup_params) except (SuspiciousOperation, ImproperlyConfigured): # Allow certain types of errors to be re-raised as-is so that the # caller can treat them in a special way. raise except Exception as e: # Every other error is caught with a naked except, because we don't # have any other way of validating lookup parameters. They might be # invalid if the keyword arguments are incorrect, or if the values # are not in the correct type, so we might get FieldError, # ValueError, ValidationError, or ?. raise IncorrectLookupParameters(e) if not qs.query.select_related: qs = self.apply_select_related(qs) # Set ordering. ordering = self.get_ordering(request, qs) qs = qs.order_by(*ordering) # Apply search results qs, search_use_distinct = self.model_admin.get_search_results( request, qs, self.query) # Remove duplicates from results, if necessary if filters_use_distinct | search_use_distinct: return qs.distinct() else: return qs def apply_select_related(self, qs): if self.list_select_related is True: return qs.select_related() if self.list_select_related is False: if self.has_related_field_in_list_display(): return qs.select_related() if self.list_select_related: return qs.select_related(*self.list_select_related) return qs def has_related_field_in_list_display(self): for field_name in self.list_display: try: field = self.lookup_opts.get_field(field_name) except models.FieldDoesNotExist: pass else: if isinstance(field.rel, models.ManyToOneRel): return True return False def url_for_result(self, result): pk = getattr(result, self.pk_attname) return reverse('admin:%s_%s_change' % (self.opts.app_label, self.opts.model_name), args=(quote(pk),), current_app=self.model_admin.admin_site.name)
apache-2.0
[ 646, 984, 199, 646, 3598, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 428, 28651, 6044, 12, 11897, 199, 504, 1639, 14, 1018, 14, 22073, 492, 6378, 3276, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 492, 29994, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 23004, 492, 27432, 2141, 199, 504, 1639, 14, 1208, 14, 15383, 492, 22756, 10385, 1563, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 495, 12, 3542, 63, 505, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 12, 10366, 63, 6395, 199, 504, 1639, 14, 1208, 14, 1014, 492, 16511, 199, 199, 504, 1639, 14, 2828, 14, 2113, 492, 5024, 24703, 199, 504, 1639, 14, 2828, 14, 2113, 14, 3924, 492, 5289, 6541, 12976, 7521, 12, 5289, 6541, 12976, 1378, 792, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1419, 492, 1010, 4525, 7521, 5976, 12, 2281, 63, 13531, 2160, 63, 5568, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1974, 492, 334, 3513, 12, 664, 63, 955, 63, 504, 63, 515, 12, 272, 4237, 63, 10065, 63, 12926, 12, 9275, 63, 3892, 63, 585, 9, 199, 199, 3, 7743, 513, 2202, 199, 1761, 63, 5568, 275, 283, 452, 7, 199, 12125, 63, 5568, 275, 283, 79, 7, 199, 12125, 63, 2711, 63, 5568, 275, 283, 357, 7, 199, 12898, 63, 5568, 275, 283, 80, 7, 199, 15962, 63, 5568, 275, 283, 81, 7, 199, 2566, 63, 8609, 63, 5568, 275, 283, 84, 7, 199, 3170, 63, 3719, 275, 283, 69, 7, 199, 199, 3203, 25517, 63, 17978, 275, 334, 272, 11727, 63, 5568, 12, 16044, 63, 5568, 12, 16044, 63, 2711, 63, 5568, 12, 5795, 7762, 63, 5568, 12, 2281, 63, 13531, 2160, 63, 5568, 12, 2296, 63, 8609, 63, 5568, 9, 199, 199, 3, 4516, 370, 2929, 4453, 1570, 13, 513, 1817, 10106, 340, 314, 574, 365, 4596, 14, 199, 13993, 63, 16062, 4924, 63, 7041, 275, 10366, 63, 6395, 14097, 403, 5942, 421, 199, 318, 485, 374, 63, 19043, 63, 16020, 8, 1069, 304, 272, 408, 272, 1803, 715, 340, 314, 22365, 9576, 2725, 365, 663, 14, 339, 961, 805, 365, 21399, 370, 30242, 1051, 323, 477, 9218, 1958, 314, 12139, 272, 574, 367, 2281, 63, 13531, 2160, 63, 5568, 436, 1077, 506, 4829, 737, 314, 1284, 402, 314, 272, 17831, 8643, 14, 272, 408, 339, 340, 2281, 63, 13531, 2160, 63, 5568, 315, 1056, 14, 2970, 26, 267, 372, 715, 339, 2281, 63, 25086, 22114, 63, 13531, 2160, 63, 5568, 275, 283, 1935, 7, 272, 340, 2281, 63, 25086, 22114, 63, 13531, 2160, 63, 5568, 315, 1056, 14, 2970, 26, 267, 3598, 14, 4050, 8, 267, 298, 1918, 18633, 83, 64, 9576, 2725, 965, 2757, 17864, 370, 18633, 83, 64, 2122, 450, 267, 334, 1311, 63, 25086, 22114, 63, 13531, 2160, 63, 5568, 12, 2281, 63, 13531, 2160, 63, 5568, 395, 267, 29216, 15561, 12, 499, 9, 267, 372, 715, 339, 372, 756, 421, 199, 533, 22756, 4001, 1296, 10385, 8, 16843, 10385, 1563, 304, 272, 17864, 63, 2474, 275, 334, 267, 661, 362, 63, 1131, 63, 409, 297, 283, 362, 63, 7924, 297, 29216, 15561, 395, 272, 776, 421, 199, 533, 7743, 1296, 8, 4174, 14, 1045, 63, 6577, 8, 16843, 4001, 1296, 10385, 2298, 272, 347, 636, 826, 721, 277, 12, 1056, 12, 1402, 12, 769, 63, 2918, 12, 769, 63, 2918, 63, 4614, 12, 288, 769, 63, 1541, 12, 1434, 63, 14861, 12, 2754, 63, 955, 12, 769, 63, 2416, 63, 2407, 12, 288, 769, 63, 529, 63, 1606, 12, 769, 63, 988, 63, 2384, 63, 452, 12, 769, 63, 10820, 12, 1402, 63, 2113, 304, 267, 291, 14, 1238, 275, 1402, 267, 291, 14, 3291, 275, 1402, 423, 2024, 267, 291, 14, 3892, 63, 3291, 275, 291, 14, 3291, 267, 291, 14, 1231, 63, 7924, 275, 1402, 63, 2113, 14, 362, 63, 7924, 8, 1069, 9, 267, 291, 14, 513, 63, 2918, 275, 769, 63, 2918, 267, 291, 14, 513, 63, 2918, 63, 4614, 275, 769, 63, 2918, 63, 4614, 267, 291, 14, 513, 63, 1541, 275, 769, 63, 1541, 267, 291, 14, 602, 63, 14861, 275, 1434, 63, 14861, 267, 291, 14, 1733, 63, 955, 275, 2754, 63, 955, 267, 291, 14, 513, 63, 2416, 63, 2407, 275, 769, 63, 2416, 63, 2407, 267, 291, 14, 513, 63, 529, 63, 1606, 275, 769, 63, 529, 63, 1606, 267, 291, 14, 513, 63, 988, 63, 2384, 63, 452, 275, 769, 63, 988, 63, 2384, 63, 452, 267, 291, 14, 1238, 63, 2113, 275, 1402, 63, 2113, 267, 291, 14, 32104, 63, 4273, 275, 1402, 63, 2113, 14, 362, 63, 32104, 63, 4273, 8, 1069, 9, 398, 327, 2372, 2754, 2633, 687, 314, 1827, 1059, 14, 267, 862, 26, 288, 291, 14, 1606, 63, 1507, 275, 1109, 8, 1069, 14, 2970, 14, 362, 8, 12898, 63, 5568, 12, 378, 430, 267, 871, 1722, 26, 288, 291, 14, 1606, 63, 1507, 275, 378, 267, 291, 14, 2384, 63, 452, 275, 11727, 63, 5568, 315, 1056, 14, 2970, 267, 291, 14, 374, 63, 16020, 275, 485, 374, 63, 19043, 63, 16020, 8, 1069, 9, 267, 370, 63, 698, 275, 1056, 14, 2970, 14, 362, 8, 2566, 63, 8609, 63, 5568, 9, 267, 340, 370, 63, 698, 436, 440, 1402, 63, 2113, 14, 475, 63, 698, 63, 6541, 8, 1069, 12, 370, 63, 698, 304, 288, 746, 5289, 6541, 12976, 1378, 792, 480, 1918, 901, 450, 83, 3913, 506, 11812, 2122, 450, 370, 63, 698, 9, 267, 291, 14, 475, 63, 698, 275, 370, 63, 698, 267, 291, 14, 1162, 275, 1211, 8, 1069, 14, 2970, 14, 1744, 1012, 267, 340, 510, 2962, 63, 5568, 315, 291, 14, 1162, 26, 288, 2150, 291, 14, 1162, 59, 12898, 63, 5568, 61, 267, 340, 12539, 63, 3719, 315, 291, 14, 1162, 26, 288, 2150, 291, 14, 1162, 59, 3170, 63, 3719, 61, 398, 340, 291, 14, 374, 63, 16020, 26, 288, 291, 14, 513, 63, 10820, 275, 6248, 267, 587, 26, 288, 291, 14, 513, 63, 10820, 275, 769, 63, 10820 ]
[ 984, 199, 646, 3598, 199, 199, 504, 1639, 14, 1018, 14, 3924, 492, 428, 28651, 6044, 12, 11897, 199, 504, 1639, 14, 1018, 14, 22073, 492, 6378, 3276, 199, 504, 1639, 14, 1018, 14, 16522, 492, 3837, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 697, 14, 992, 14, 955, 492, 29994, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 23004, 492, 27432, 2141, 199, 504, 1639, 14, 1208, 14, 15383, 492, 22756, 10385, 1563, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 495, 12, 3542, 63, 505, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 12, 10366, 63, 6395, 199, 504, 1639, 14, 1208, 14, 1014, 492, 16511, 199, 199, 504, 1639, 14, 2828, 14, 2113, 492, 5024, 24703, 199, 504, 1639, 14, 2828, 14, 2113, 14, 3924, 492, 5289, 6541, 12976, 7521, 12, 5289, 6541, 12976, 1378, 792, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1419, 492, 1010, 4525, 7521, 5976, 12, 2281, 63, 13531, 2160, 63, 5568, 199, 504, 1639, 14, 2828, 14, 2113, 14, 1974, 492, 334, 3513, 12, 664, 63, 955, 63, 504, 63, 515, 12, 272, 4237, 63, 10065, 63, 12926, 12, 9275, 63, 3892, 63, 585, 9, 199, 199, 3, 7743, 513, 2202, 199, 1761, 63, 5568, 275, 283, 452, 7, 199, 12125, 63, 5568, 275, 283, 79, 7, 199, 12125, 63, 2711, 63, 5568, 275, 283, 357, 7, 199, 12898, 63, 5568, 275, 283, 80, 7, 199, 15962, 63, 5568, 275, 283, 81, 7, 199, 2566, 63, 8609, 63, 5568, 275, 283, 84, 7, 199, 3170, 63, 3719, 275, 283, 69, 7, 199, 199, 3203, 25517, 63, 17978, 275, 334, 272, 11727, 63, 5568, 12, 16044, 63, 5568, 12, 16044, 63, 2711, 63, 5568, 12, 5795, 7762, 63, 5568, 12, 2281, 63, 13531, 2160, 63, 5568, 12, 2296, 63, 8609, 63, 5568, 9, 199, 199, 3, 4516, 370, 2929, 4453, 1570, 13, 513, 1817, 10106, 340, 314, 574, 365, 4596, 14, 199, 13993, 63, 16062, 4924, 63, 7041, 275, 10366, 63, 6395, 14097, 403, 5942, 421, 199, 318, 485, 374, 63, 19043, 63, 16020, 8, 1069, 304, 272, 408, 272, 1803, 715, 340, 314, 22365, 9576, 2725, 365, 663, 14, 339, 961, 805, 365, 21399, 370, 30242, 1051, 323, 477, 9218, 1958, 314, 12139, 272, 574, 367, 2281, 63, 13531, 2160, 63, 5568, 436, 1077, 506, 4829, 737, 314, 1284, 402, 314, 272, 17831, 8643, 14, 272, 408, 339, 340, 2281, 63, 13531, 2160, 63, 5568, 315, 1056, 14, 2970, 26, 267, 372, 715, 339, 2281, 63, 25086, 22114, 63, 13531, 2160, 63, 5568, 275, 283, 1935, 7, 272, 340, 2281, 63, 25086, 22114, 63, 13531, 2160, 63, 5568, 315, 1056, 14, 2970, 26, 267, 3598, 14, 4050, 8, 267, 298, 1918, 18633, 83, 64, 9576, 2725, 965, 2757, 17864, 370, 18633, 83, 64, 2122, 450, 267, 334, 1311, 63, 25086, 22114, 63, 13531, 2160, 63, 5568, 12, 2281, 63, 13531, 2160, 63, 5568, 395, 267, 29216, 15561, 12, 499, 9, 267, 372, 715, 339, 372, 756, 421, 199, 533, 22756, 4001, 1296, 10385, 8, 16843, 10385, 1563, 304, 272, 17864, 63, 2474, 275, 334, 267, 661, 362, 63, 1131, 63, 409, 297, 283, 362, 63, 7924, 297, 29216, 15561, 395, 272, 776, 421, 199, 533, 7743, 1296, 8, 4174, 14, 1045, 63, 6577, 8, 16843, 4001, 1296, 10385, 2298, 272, 347, 636, 826, 721, 277, 12, 1056, 12, 1402, 12, 769, 63, 2918, 12, 769, 63, 2918, 63, 4614, 12, 288, 769, 63, 1541, 12, 1434, 63, 14861, 12, 2754, 63, 955, 12, 769, 63, 2416, 63, 2407, 12, 288, 769, 63, 529, 63, 1606, 12, 769, 63, 988, 63, 2384, 63, 452, 12, 769, 63, 10820, 12, 1402, 63, 2113, 304, 267, 291, 14, 1238, 275, 1402, 267, 291, 14, 3291, 275, 1402, 423, 2024, 267, 291, 14, 3892, 63, 3291, 275, 291, 14, 3291, 267, 291, 14, 1231, 63, 7924, 275, 1402, 63, 2113, 14, 362, 63, 7924, 8, 1069, 9, 267, 291, 14, 513, 63, 2918, 275, 769, 63, 2918, 267, 291, 14, 513, 63, 2918, 63, 4614, 275, 769, 63, 2918, 63, 4614, 267, 291, 14, 513, 63, 1541, 275, 769, 63, 1541, 267, 291, 14, 602, 63, 14861, 275, 1434, 63, 14861, 267, 291, 14, 1733, 63, 955, 275, 2754, 63, 955, 267, 291, 14, 513, 63, 2416, 63, 2407, 275, 769, 63, 2416, 63, 2407, 267, 291, 14, 513, 63, 529, 63, 1606, 275, 769, 63, 529, 63, 1606, 267, 291, 14, 513, 63, 988, 63, 2384, 63, 452, 275, 769, 63, 988, 63, 2384, 63, 452, 267, 291, 14, 1238, 63, 2113, 275, 1402, 63, 2113, 267, 291, 14, 32104, 63, 4273, 275, 1402, 63, 2113, 14, 362, 63, 32104, 63, 4273, 8, 1069, 9, 398, 327, 2372, 2754, 2633, 687, 314, 1827, 1059, 14, 267, 862, 26, 288, 291, 14, 1606, 63, 1507, 275, 1109, 8, 1069, 14, 2970, 14, 362, 8, 12898, 63, 5568, 12, 378, 430, 267, 871, 1722, 26, 288, 291, 14, 1606, 63, 1507, 275, 378, 267, 291, 14, 2384, 63, 452, 275, 11727, 63, 5568, 315, 1056, 14, 2970, 267, 291, 14, 374, 63, 16020, 275, 485, 374, 63, 19043, 63, 16020, 8, 1069, 9, 267, 370, 63, 698, 275, 1056, 14, 2970, 14, 362, 8, 2566, 63, 8609, 63, 5568, 9, 267, 340, 370, 63, 698, 436, 440, 1402, 63, 2113, 14, 475, 63, 698, 63, 6541, 8, 1069, 12, 370, 63, 698, 304, 288, 746, 5289, 6541, 12976, 1378, 792, 480, 1918, 901, 450, 83, 3913, 506, 11812, 2122, 450, 370, 63, 698, 9, 267, 291, 14, 475, 63, 698, 275, 370, 63, 698, 267, 291, 14, 1162, 275, 1211, 8, 1069, 14, 2970, 14, 1744, 1012, 267, 340, 510, 2962, 63, 5568, 315, 291, 14, 1162, 26, 288, 2150, 291, 14, 1162, 59, 12898, 63, 5568, 61, 267, 340, 12539, 63, 3719, 315, 291, 14, 1162, 26, 288, 2150, 291, 14, 1162, 59, 3170, 63, 3719, 61, 398, 340, 291, 14, 374, 63, 16020, 26, 288, 291, 14, 513, 63, 10820, 275, 6248, 267, 587, 26, 288, 291, 14, 513, 63, 10820, 275, 769, 63, 10820, 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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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 ]
uskudnik/ggrc-core
src/ggrc_basic_permissions/migrations/versions/20140519175934_1d1573d5812f_update_context_related_object_where_.py
2
1906
"""Update Context.related_object where missing Revision ID: 1d1573d5812f Revises: 5560713e91b2 Create Date: 2014-05-19 17:59:34.819427 """ # revision identifiers, used by Alembic. revision = '1d1573d5812f' down_revision = '5560713e91b2' from alembic import op import sqlalchemy as sa from sqlalchemy.sql import table, column, select, and_ contexts_table = table('contexts', column('id', sa.Integer), column('context_id', sa.Integer), column('related_object_id', sa.Integer), column('related_object_type', sa.String), ) programs_table = table('programs', column('id', sa.Integer), column('context_id', sa.Integer), ) def upgrade(): connection = op.get_bind() programs = connection.execute( select([programs_table.c.id, programs_table.c.context_id]) ).fetchall() program_ids_by_context = {} for program in programs: if program.context_id: program_ids_by_context[program.context_id] = program.id contexts = connection.execute( select([ contexts_table.c.id, contexts_table.c.related_object_id ])\ .where( and_( contexts_table.c.related_object_type == "Program", contexts_table.c.related_object_id == None )) ).fetchall() contexts_to_update = [] for context in contexts: if context.related_object_id is None: if context.id in program_ids_by_context: contexts_to_update.append({ "id": context.id, "related_object_id": program_ids_by_context[context.id] }) for context_data in contexts_to_update: op.execute( contexts_table.update()\ .values( related_object_id=context_data["related_object_id"] )\ .where(contexts_table.c.id == context_data["id"])) def downgrade(): # Non-reversible migration pass
apache-2.0
[ 199, 624, 4152, 9470, 14, 2407, 63, 785, 2382, 4124, 199, 199, 12714, 2870, 26, 413, 68, 1046, 2898, 68, 2010, 713, 70, 199, 497, 433, 874, 26, 31074, 1780, 969, 69, 3328, 66, 18, 199, 2499, 6148, 26, 6927, 13, 1717, 13, 1167, 5557, 26, 1427, 26, 1082, 14, 24, 10860, 1465, 199, 199, 624, 199, 199, 3, 6974, 14154, 12, 1202, 701, 6832, 20596, 14, 199, 5792, 275, 283, 17, 68, 1046, 2898, 68, 2010, 713, 70, 7, 199, 2110, 63, 5792, 275, 283, 1229, 16059, 969, 69, 3328, 66, 18, 7, 199, 199, 504, 30960, 20596, 492, 1687, 199, 646, 8335, 465, 2937, 199, 504, 8335, 14, 3009, 492, 1817, 12, 2763, 12, 3504, 12, 436, 63, 421, 199, 19010, 63, 1224, 275, 1817, 360, 19010, 297, 272, 2763, 360, 344, 297, 2937, 14, 2674, 395, 272, 2763, 360, 1100, 63, 344, 297, 2937, 14, 2674, 395, 272, 2763, 360, 2407, 63, 785, 63, 344, 297, 2937, 14, 2674, 395, 272, 2763, 360, 2407, 63, 785, 63, 466, 297, 2937, 14, 1558, 395, 272, 776, 421, 199, 28464, 63, 1224, 275, 1817, 360, 28464, 297, 272, 2763, 360, 344, 297, 2937, 14, 2674, 395, 272, 2763, 360, 1100, 63, 344, 297, 2937, 14, 2674, 395, 272, 776, 421, 199, 318, 10754, 837, 523, 1950, 275, 1687, 14, 362, 63, 3409, 342, 819, 18572, 275, 1950, 14, 2526, 8, 489, 3504, 779, 28464, 63, 1224, 14, 67, 14, 344, 12, 18572, 63, 1224, 14, 67, 14, 1100, 63, 344, 566, 489, 7092, 10174, 342, 523, 2240, 63, 1580, 63, 991, 63, 1100, 275, 1052, 523, 367, 2240, 315, 18572, 26, 272, 340, 2240, 14, 1100, 63, 344, 26, 489, 2240, 63, 1580, 63, 991, 63, 1100, 59, 6815, 14, 1100, 63, 344, 61, 275, 2240, 14, 344, 819, 18191, 275, 1950, 14, 2526, 8, 489, 3504, 779, 288, 18191, 63, 1224, 14, 67, 14, 344, 12, 288, 18191, 63, 1224, 14, 67, 14, 2407, 63, 785, 63, 344, 288, 4794, 60, 881, 1275, 4509, 8, 288, 436, 2531, 1598, 18191, 63, 1224, 14, 67, 14, 2407, 63, 785, 63, 466, 508, 298, 9184, 401, 1598, 18191, 63, 1224, 14, 67, 14, 2407, 63, 785, 63, 344, 508, 488, 1598, 5082, 489, 7092, 10174, 342, 819, 18191, 63, 475, 63, 873, 275, 942, 523, 367, 1067, 315, 18191, 26, 272, 340, 1067, 14, 2407, 63, 785, 63, 344, 365, 488, 26, 489, 340, 1067, 14, 344, 315, 2240, 63, 1580, 63, 991, 63, 1100, 26, 267, 18191, 63, 475, 63, 873, 14, 740, 2561, 881, 298, 344, 582, 1067, 14, 344, 12, 881, 298, 2407, 63, 785, 63, 344, 582, 2240, 63, 1580, 63, 991, 63, 1100, 59, 1100, 14, 344, 61, 881, 3828, 819, 367, 1067, 63, 576, 315, 18191, 63, 475, 63, 873, 26, 272, 1687, 14, 2526, 8, 267, 18191, 63, 1224, 14, 873, 17158, 288, 1275, 1459, 8, 1598, 4048, 63, 785, 63, 344, 29, 1100, 63, 576, 905, 2407, 63, 785, 63, 344, 937, 1598, 776, 60, 288, 1275, 4509, 8, 19010, 63, 1224, 14, 67, 14, 344, 508, 1067, 63, 576, 905, 344, 13045, 421, 199, 318, 32498, 837, 523, 327, 10172, 13, 264, 422, 1164, 8367, 523, 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 ]
[ 624, 4152, 9470, 14, 2407, 63, 785, 2382, 4124, 199, 199, 12714, 2870, 26, 413, 68, 1046, 2898, 68, 2010, 713, 70, 199, 497, 433, 874, 26, 31074, 1780, 969, 69, 3328, 66, 18, 199, 2499, 6148, 26, 6927, 13, 1717, 13, 1167, 5557, 26, 1427, 26, 1082, 14, 24, 10860, 1465, 199, 199, 624, 199, 199, 3, 6974, 14154, 12, 1202, 701, 6832, 20596, 14, 199, 5792, 275, 283, 17, 68, 1046, 2898, 68, 2010, 713, 70, 7, 199, 2110, 63, 5792, 275, 283, 1229, 16059, 969, 69, 3328, 66, 18, 7, 199, 199, 504, 30960, 20596, 492, 1687, 199, 646, 8335, 465, 2937, 199, 504, 8335, 14, 3009, 492, 1817, 12, 2763, 12, 3504, 12, 436, 63, 421, 199, 19010, 63, 1224, 275, 1817, 360, 19010, 297, 272, 2763, 360, 344, 297, 2937, 14, 2674, 395, 272, 2763, 360, 1100, 63, 344, 297, 2937, 14, 2674, 395, 272, 2763, 360, 2407, 63, 785, 63, 344, 297, 2937, 14, 2674, 395, 272, 2763, 360, 2407, 63, 785, 63, 466, 297, 2937, 14, 1558, 395, 272, 776, 421, 199, 28464, 63, 1224, 275, 1817, 360, 28464, 297, 272, 2763, 360, 344, 297, 2937, 14, 2674, 395, 272, 2763, 360, 1100, 63, 344, 297, 2937, 14, 2674, 395, 272, 776, 421, 199, 318, 10754, 837, 523, 1950, 275, 1687, 14, 362, 63, 3409, 342, 819, 18572, 275, 1950, 14, 2526, 8, 489, 3504, 779, 28464, 63, 1224, 14, 67, 14, 344, 12, 18572, 63, 1224, 14, 67, 14, 1100, 63, 344, 566, 489, 7092, 10174, 342, 523, 2240, 63, 1580, 63, 991, 63, 1100, 275, 1052, 523, 367, 2240, 315, 18572, 26, 272, 340, 2240, 14, 1100, 63, 344, 26, 489, 2240, 63, 1580, 63, 991, 63, 1100, 59, 6815, 14, 1100, 63, 344, 61, 275, 2240, 14, 344, 819, 18191, 275, 1950, 14, 2526, 8, 489, 3504, 779, 288, 18191, 63, 1224, 14, 67, 14, 344, 12, 288, 18191, 63, 1224, 14, 67, 14, 2407, 63, 785, 63, 344, 288, 4794, 60, 881, 1275, 4509, 8, 288, 436, 2531, 1598, 18191, 63, 1224, 14, 67, 14, 2407, 63, 785, 63, 466, 508, 298, 9184, 401, 1598, 18191, 63, 1224, 14, 67, 14, 2407, 63, 785, 63, 344, 508, 488, 1598, 5082, 489, 7092, 10174, 342, 819, 18191, 63, 475, 63, 873, 275, 942, 523, 367, 1067, 315, 18191, 26, 272, 340, 1067, 14, 2407, 63, 785, 63, 344, 365, 488, 26, 489, 340, 1067, 14, 344, 315, 2240, 63, 1580, 63, 991, 63, 1100, 26, 267, 18191, 63, 475, 63, 873, 14, 740, 2561, 881, 298, 344, 582, 1067, 14, 344, 12, 881, 298, 2407, 63, 785, 63, 344, 582, 2240, 63, 1580, 63, 991, 63, 1100, 59, 1100, 14, 344, 61, 881, 3828, 819, 367, 1067, 63, 576, 315, 18191, 63, 475, 63, 873, 26, 272, 1687, 14, 2526, 8, 267, 18191, 63, 1224, 14, 873, 17158, 288, 1275, 1459, 8, 1598, 4048, 63, 785, 63, 344, 29, 1100, 63, 576, 905, 2407, 63, 785, 63, 344, 937, 1598, 776, 60, 288, 1275, 4509, 8, 19010, 63, 1224, 14, 67, 14, 344, 508, 1067, 63, 576, 905, 344, 13045, 421, 199, 318, 32498, 837, 523, 327, 10172, 13, 264, 422, 1164, 8367, 523, 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, 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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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 ]
jakirkham/ilastik
ilastik/applets/vigraWatershedViewer/opVigraWatershedViewer.py
4
10658
############################################################################### # ilastik: interactive learning and segmentation toolkit # # Copyright (C) 2011-2014, the ilastik developers # <team@ilastik.org> # # This program 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. # # In addition, as a special exception, the copyright holders of # ilastik give you permission to combine ilastik with applets, # workflows and plugins which are not covered under the GNU # General Public License. # # See the LICENSE file for details. License information is also available # on the ilastik web site at: # http://ilastik.org/license.html ############################################################################### from lazyflow.graph import Operator, InputSlot, OutputSlot from lazyflow.operators import OpSlicedBlockedArrayCache, OpMultiArraySlicer2, OpMultiArrayMerger, OpPixelOperator from lazyflow.operators import OpVigraWatershed, OpColorizeLabels, OpVigraLabelVolume, OpFilterLabels import numpy import vigra from functools import partial import random import logging class OpVigraWatershedViewer(Operator): name = "OpWatershedViewer" category = "top-level" RawImage = InputSlot(optional=True) # Displayed in the GUI (not used in pipeline) InputImage = InputSlot() # The image to be sliced and watershedded InputChannelIndexes = InputSlot(stype='object') # opChannelSlicer WatershedPadding = InputSlot() # opWatershed FreezeCache = InputSlot() # opWatershedCache CacheBlockShape = InputSlot() # opWatershedCache block shapes. Expected: tuple of (width, depth) viewing shape OverrideLabels = InputSlot(stype='object') # opColorizer SeedThresholdValue = InputSlot(optional=True) # opThreshold MinSeedSize = InputSlot() # opSeedLabeler WatershedLabels = OutputSlot() # Watershed labeled output SummedInput = OutputSlot() # Watershed input (for gui display) ColoredPixels = OutputSlot() # Colored watershed labels (for gui display) ColoredSeeds = OutputSlot() # Seeds to the watershed (for gui display) SelectedInputChannels = OutputSlot(level=1) def __init__(self, *args, **kwargs): super(OpVigraWatershedViewer, self).__init__(*args, **kwargs) self._seedThreshold = None # Overview Schematic # Example here uses input channels 0,2,5 # InputChannelIndexes=[0,2,5] --- # \ # InputImage -------------------> opChannelSlicer .Slices[0] ---\ # .Slices[1] ----> opAverage --> opWatershed --> opWatershedCache --> opColorizer --> GUI # .Slices[2] ---/ / # / # SeedThresholdValue --- MinSeedSize --- / # \ \ / # InputImage ----------> opThreshold --> opSeedLabeler --> opSeedFilter ----- ---> opSeedCache --> opSeedColorizer --> GUI # Create operators self.opChannelSlicer = OpMultiArraySlicer2(parent=self) self.opAverage = OpMultiArrayMerger(parent=self) self.opWatershed = OpVigraWatershed(parent=self) self.opWatershedCache = OpSlicedBlockedArrayCache(parent=self) self.opColorizer = OpColorizeLabels(parent=self) self.opThreshold = OpPixelOperator(parent=self) self.opSeedLabeler = OpVigraLabelVolume(parent=self) self.opSeedFilter = OpFilterLabels(parent=self) self.opSeedCache = OpSlicedBlockedArrayCache(parent=self) self.opSeedColorizer = OpColorizeLabels(parent=self) # Select specific input channels self.opChannelSlicer.Input.connect( self.InputImage ) self.opChannelSlicer.SliceIndexes.connect( self.InputChannelIndexes ) self.opChannelSlicer.AxisFlag.setValue('c') # Average selected channels def average(arrays): if len(arrays) == 0: return 0 else: return sum(arrays) / float(len(arrays)) self.opAverage.MergingFunction.setValue( average ) self.opAverage.Inputs.connect( self.opChannelSlicer.Slices ) # Threshold for seeds self.opThreshold.Input.connect( self.opAverage.Output ) # Label seeds self.opSeedLabeler.Input.connect( self.opThreshold.Output ) # Filter seeds self.opSeedFilter.MinLabelSize.connect( self.MinSeedSize ) self.opSeedFilter.Input.connect( self.opSeedLabeler.Output ) # Cache seeds self.opSeedCache.fixAtCurrent.connect( self.FreezeCache ) self.opSeedCache.Input.connect(self.opSeedFilter.Output) # Color seeds for RBG display self.opSeedColorizer.Input.connect( self.opSeedCache.Output ) self.opSeedColorizer.OverrideColors.setValue( { 0: (0,0,0,0) } ) # Compute watershed labels (possibly with seeds, see setupOutputs) self.opWatershed.InputImage.connect( self.opAverage.Output ) self.opWatershed.PaddingWidth.connect( self.WatershedPadding ) # Cache the watershed output self.opWatershedCache.fixAtCurrent.connect( self.FreezeCache ) self.opWatershedCache.Input.connect(self.opWatershed.Output) # Colorize the watershed labels for RGB display self.opColorizer.Input.connect( self.opWatershedCache.Output ) self.opColorizer.OverrideColors.connect( self.OverrideLabels ) # Connnect external outputs the operators that provide them self.ColoredPixels.connect( self.opColorizer.Output ) self.SelectedInputChannels.connect( self.opChannelSlicer.Slices ) self.SummedInput.connect( self.opAverage.Output ) self.ColoredSeeds.connect( self.opSeedColorizer.Output ) def setupOutputs(self): # User has control over cache block shape # Width and depth are applied to x,y, or z depending on which slicing view is being used. width, depth = self.CacheBlockShape.value ## Cache blocks # Inner and outer block shapes are the same. # We're using this cache for the "sliced" property, not the "blocked" property. blockDimsX = { 't' : (1,1), 'z' : (width,width), 'y' : (width,width), 'x' : (depth,depth), 'c' : (1,1) } blockDimsY = { 't' : (1,1), 'z' : (width,width), 'y' : (depth,depth), 'x' : (width,width), 'c' : (1,1) } blockDimsZ = { 't' : (1,1), 'z' : (depth,depth), 'y' : (width,width), 'x' : (width,width), 'c' : (1,1) } # Set the blockshapes for each input image separately, depending on which axistags it has. axisOrder = [ tag.key for tag in self.InputImage.meta.axistags ] innerBlockShapeX = tuple( blockDimsX[k][0] for k in axisOrder ) outerBlockShapeX = tuple( blockDimsX[k][1] for k in axisOrder ) innerBlockShapeY = tuple( blockDimsY[k][0] for k in axisOrder ) outerBlockShapeY = tuple( blockDimsY[k][1] for k in axisOrder ) innerBlockShapeZ = tuple( blockDimsZ[k][0] for k in axisOrder ) outerBlockShapeZ = tuple( blockDimsZ[k][1] for k in axisOrder ) self.opWatershedCache.innerBlockShape.setValue( (innerBlockShapeX, innerBlockShapeY, innerBlockShapeZ) ) self.opWatershedCache.outerBlockShape.setValue( (outerBlockShapeX, outerBlockShapeY, outerBlockShapeZ) ) # Seed cache has same shape as watershed cache self.opSeedCache.innerBlockShape.setValue( (innerBlockShapeX, innerBlockShapeY, innerBlockShapeZ) ) self.opSeedCache.outerBlockShape.setValue( (outerBlockShapeX, outerBlockShapeY, outerBlockShapeZ) ) # For now watershed labels always come from the X-Y slicing view if len(self.opWatershedCache.InnerOutputs) > 0: self.WatershedLabels.connect( self.opWatershedCache.InnerOutputs[2] ) if self.SeedThresholdValue.ready(): seedThreshold = self.SeedThresholdValue.value if not self.opWatershed.SeedImage.connected() or seedThreshold != self._seedThreshold: self._seedThreshold = seedThreshold self.opThreshold.Function.setValue( lambda a: (a <= seedThreshold).astype(numpy.uint8) ) self.opWatershed.SeedImage.connect( self.opSeedFilter.Output ) else: self.opWatershed.SeedImage.disconnect() self.opThreshold.Function.disconnect() def propagateDirty(self, slot, subindex, roi): # All outputs are directly connected to internal operators pass if __name__ == "__main__": import h5py from lazyflow.graph import Graph from lazyflow.utility import Timer print "Reading data..." prediction_path = '/tmp/STACKED_prediction.h5' with h5py.File( prediction_path, 'r' ) as prediction_file: data = prediction_file['volume/predictions'][:] #[0:50,0:50,0:50,:] # Scale and convert to uint8, then add axistags and drange data = (data*255).astype(numpy.uint8) data = vigra.taggedView( data, 'xyzc' ) data.drange = (0,255) graph = Graph() op = OpVigraWatershedViewer(graph=graph) op.InputImage.setValue( data ) op.InputChannelIndexes.setValue([0]) op.WatershedPadding.setValue(0) op.FreezeCache.setValue(False) op.CacheBlockShape.setValue((520,520)) op.OverrideLabels.setValue({}) op.SeedThresholdValue.setValue(0) op.MinSeedSize.setValue(5) assert op.WatershedLabels.ready() print "Computing watershed..." with Timer() as timer: watershed_labels = op.opWatershed.Output[:].wait() print "Computing watershed took {} seconds".format( timer.seconds() ) print "Saving watershed..." with h5py.File('/tmp/watershed_output.h5', 'w') as output_file: output_file.create_dataset('watershed_labels', data=watershed_labels) print "DONE."
gpl-3.0
[ 11490, 199, 3, 257, 284, 2019, 3258, 26, 12777, 9328, 436, 27315, 4744, 6065, 199, 3, 199, 3, 755, 1898, 334, 35, 9, 7760, 13, 7280, 12, 314, 284, 2019, 3258, 19782, 199, 3, 13293, 665, 5969, 32, 382, 1810, 3258, 14, 1308, 30, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 199, 3, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 199, 3, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 1010, 10234, 12, 465, 282, 4539, 1919, 12, 314, 4248, 31976, 402, 199, 3, 284, 2019, 3258, 8120, 1265, 4983, 370, 13323, 284, 2019, 3258, 543, 1145, 16537, 12, 199, 3, 10431, 83, 436, 8963, 1314, 787, 440, 24295, 1334, 314, 1664, 199, 3, 1696, 1684, 844, 14, 199, 3, 199, 3, 1666, 314, 5113, 570, 367, 2436, 14, 844, 2556, 365, 2597, 2808, 199, 3, 641, 314, 284, 2019, 3258, 3330, 4770, 737, 26, 199, 3, 1057, 257, 1455, 921, 382, 1810, 3258, 14, 1308, 15, 1682, 14, 1360, 199, 11490, 199, 504, 9617, 1659, 14, 2180, 492, 11013, 12, 6924, 15183, 12, 7242, 15183, 199, 199, 504, 9617, 1659, 14, 12688, 492, 9319, 14034, 68, 3142, 20999, 4437, 12, 9319, 3947, 3836, 51, 27975, 18, 12, 9319, 3947, 3836, 16797, 836, 12, 9319, 14383, 7961, 199, 199, 504, 9617, 1659, 14, 12688, 492, 9319, 54, 528, 345, 25103, 609, 379, 12, 9319, 4117, 794, 14016, 12, 9319, 54, 528, 345, 4314, 6464, 12, 9319, 4131, 14016, 199, 199, 646, 2680, 199, 646, 373, 528, 345, 199, 504, 9143, 492, 7417, 199, 646, 2196, 199, 646, 2050, 199, 199, 533, 9319, 54, 528, 345, 25103, 609, 379, 22347, 8, 7961, 304, 272, 536, 275, 298, 4619, 25103, 609, 379, 22347, 2, 272, 4637, 275, 298, 2119, 13, 1896, 2, 2286, 13480, 3491, 275, 6924, 15183, 8, 4144, 29, 549, 9, 327, 12175, 379, 315, 314, 17160, 334, 1397, 1202, 315, 7679, 9, 2286, 6924, 3491, 275, 6924, 15183, 342, 327, 710, 1834, 370, 506, 6014, 68, 436, 22834, 609, 379, 770, 339, 6924, 5358, 2681, 397, 275, 6924, 15183, 8, 20615, 534, 785, 358, 327, 1687, 5358, 51, 27975, 272, 644, 6618, 609, 379, 15069, 275, 6924, 15183, 342, 327, 1687, 25103, 609, 379, 272, 2868, 806, 4437, 275, 6924, 15183, 342, 327, 1687, 25103, 609, 379, 4437, 272, 11977, 3142, 7238, 275, 6924, 15183, 342, 327, 1687, 25103, 609, 379, 4437, 1853, 11751, 14, 13796, 26, 2008, 402, 334, 2063, 12, 5818, 9, 2455, 316, 2215, 272, 11041, 14016, 275, 6924, 15183, 8, 20615, 534, 785, 358, 327, 1687, 4117, 1793, 272, 3240, 379, 12109, 1110, 275, 6924, 15183, 8, 4144, 29, 549, 9, 327, 1687, 12109, 272, 10195, 19554, 2320, 275, 6924, 15183, 342, 327, 1687, 19554, 44, 7570, 1435, 2286, 644, 6618, 609, 379, 14016, 275, 7242, 15183, 342, 221, 327, 644, 6618, 609, 379, 23677, 1072, 272, 12094, 3594, 3205, 275, 7242, 15183, 342, 420, 327, 644, 6618, 609, 379, 1324, 334, 509, 11621, 2929, 9, 272, 1849, 21252, 29170, 275, 7242, 15183, 342, 259, 327, 1849, 21252, 22834, 609, 379, 3628, 334, 509, 11621, 2929, 9, 272, 1849, 21252, 1513, 5923, 275, 7242, 15183, 342, 258, 327, 3240, 5923, 370, 314, 22834, 609, 379, 334, 509, 11621, 2929, 9, 2286, 3240, 2820, 3205, 27138, 275, 7242, 15183, 8, 1896, 29, 17, 9, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 4619, 54, 528, 345, 25103, 609, 379, 22347, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 423, 5176, 12109, 275, 488, 2728, 327, 7259, 1345, 13268, 764, 267, 327, 5679, 2348, 4440, 1324, 9245, 378, 12, 18, 12, 21, 2728, 327, 6924, 5358, 2681, 397, 1524, 16, 12, 18, 12, 21, 61, 10894, 267, 327, 13293, 971, 267, 327, 6924, 3491, 10652, 2595, 30, 1687, 5358, 51, 27975, 1275, 19804, 59, 16, 61, 1553, 2696, 267, 327, 2476, 463, 1275, 19804, 59, 17, 61, 4099, 30, 1687, 17400, 10541, 1687, 25103, 609, 379, 10541, 1687, 25103, 609, 379, 4437, 10541, 1687, 4117, 1793, 10541, 17160, 4960, 327, 2476, 463, 1275, 19804, 59, 18, 61, 10894, 15, 5185, 1182, 267, 327, 26209, 1182, 267, 327, 3240, 379, 12109, 1110, 10894, 7861, 10195, 19554, 2320, 10894, 8540, 1182, 267, 327, 9668, 971, 2476, 971, 8295, 1182, 267, 327, 6924, 3491, 4143, 30, 1687, 12109, 10541, 1687, 19554, 44, 7570, 1435, 10541, 1687, 19554, 4131, 9063, 1553, 5118, 1687, 19554, 4437, 10541, 1687, 19554, 4117, 1793, 10541, 17160, 2728, 327, 2790, 10211, 267, 291, 14, 411, 5358, 51, 27975, 275, 9319, 3947, 3836, 51, 27975, 18, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 17400, 275, 9319, 3947, 3836, 16797, 836, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 25103, 609, 379, 275, 9319, 54, 528, 345, 25103, 609, 379, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 25103, 609, 379, 4437, 275, 9319, 14034, 68, 3142, 20999, 4437, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 4117, 1793, 275, 9319, 4117, 794, 14016, 8, 1708, 29, 277, 9, 2728, 291, 14, 411, 12109, 275, 9319, 14383, 7961, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 19554, 44, 7570, 1435, 275, 9319, 54, 528, 345, 4314, 6464, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 19554, 4131, 275, 9319, 4131, 14016, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 19554, 4437, 275, 9319, 14034, 68, 3142, 20999, 4437, 8, 1708, 29, 277, 9, 18418, 291, 14, 411, 19554, 4117, 1793, 275, 9319, 4117, 794, 14016, 8, 1708, 29, 277, 9, 398, 327, 9496, 2488, 1324, 9245, 267, 291, 14, 411, 5358, 51, 27975, 14, 3205, 14, 2242, 8, 291, 14, 3205, 3491, 776, 267, 291, 14, 411, 5358, 51, 27975, 14, 14034, 2681, 397, 14, 2242, 8, 291, 14, 3205, 5358, 2681, 397, 776, 267, 291, 14, 411, 5358, 51, 27975, 14, 11220, 5318, 14, 14733, 360, 67, 358, 398, 327, 437, 3652, 4895, 9245 ]
[ 199, 3, 257, 284, 2019, 3258, 26, 12777, 9328, 436, 27315, 4744, 6065, 199, 3, 199, 3, 755, 1898, 334, 35, 9, 7760, 13, 7280, 12, 314, 284, 2019, 3258, 19782, 199, 3, 13293, 665, 5969, 32, 382, 1810, 3258, 14, 1308, 30, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 199, 3, 465, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 199, 3, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 1010, 10234, 12, 465, 282, 4539, 1919, 12, 314, 4248, 31976, 402, 199, 3, 284, 2019, 3258, 8120, 1265, 4983, 370, 13323, 284, 2019, 3258, 543, 1145, 16537, 12, 199, 3, 10431, 83, 436, 8963, 1314, 787, 440, 24295, 1334, 314, 1664, 199, 3, 1696, 1684, 844, 14, 199, 3, 199, 3, 1666, 314, 5113, 570, 367, 2436, 14, 844, 2556, 365, 2597, 2808, 199, 3, 641, 314, 284, 2019, 3258, 3330, 4770, 737, 26, 199, 3, 1057, 257, 1455, 921, 382, 1810, 3258, 14, 1308, 15, 1682, 14, 1360, 199, 11490, 199, 504, 9617, 1659, 14, 2180, 492, 11013, 12, 6924, 15183, 12, 7242, 15183, 199, 199, 504, 9617, 1659, 14, 12688, 492, 9319, 14034, 68, 3142, 20999, 4437, 12, 9319, 3947, 3836, 51, 27975, 18, 12, 9319, 3947, 3836, 16797, 836, 12, 9319, 14383, 7961, 199, 199, 504, 9617, 1659, 14, 12688, 492, 9319, 54, 528, 345, 25103, 609, 379, 12, 9319, 4117, 794, 14016, 12, 9319, 54, 528, 345, 4314, 6464, 12, 9319, 4131, 14016, 199, 199, 646, 2680, 199, 646, 373, 528, 345, 199, 504, 9143, 492, 7417, 199, 646, 2196, 199, 646, 2050, 199, 199, 533, 9319, 54, 528, 345, 25103, 609, 379, 22347, 8, 7961, 304, 272, 536, 275, 298, 4619, 25103, 609, 379, 22347, 2, 272, 4637, 275, 298, 2119, 13, 1896, 2, 2286, 13480, 3491, 275, 6924, 15183, 8, 4144, 29, 549, 9, 327, 12175, 379, 315, 314, 17160, 334, 1397, 1202, 315, 7679, 9, 2286, 6924, 3491, 275, 6924, 15183, 342, 327, 710, 1834, 370, 506, 6014, 68, 436, 22834, 609, 379, 770, 339, 6924, 5358, 2681, 397, 275, 6924, 15183, 8, 20615, 534, 785, 358, 327, 1687, 5358, 51, 27975, 272, 644, 6618, 609, 379, 15069, 275, 6924, 15183, 342, 327, 1687, 25103, 609, 379, 272, 2868, 806, 4437, 275, 6924, 15183, 342, 327, 1687, 25103, 609, 379, 4437, 272, 11977, 3142, 7238, 275, 6924, 15183, 342, 327, 1687, 25103, 609, 379, 4437, 1853, 11751, 14, 13796, 26, 2008, 402, 334, 2063, 12, 5818, 9, 2455, 316, 2215, 272, 11041, 14016, 275, 6924, 15183, 8, 20615, 534, 785, 358, 327, 1687, 4117, 1793, 272, 3240, 379, 12109, 1110, 275, 6924, 15183, 8, 4144, 29, 549, 9, 327, 1687, 12109, 272, 10195, 19554, 2320, 275, 6924, 15183, 342, 327, 1687, 19554, 44, 7570, 1435, 2286, 644, 6618, 609, 379, 14016, 275, 7242, 15183, 342, 221, 327, 644, 6618, 609, 379, 23677, 1072, 272, 12094, 3594, 3205, 275, 7242, 15183, 342, 420, 327, 644, 6618, 609, 379, 1324, 334, 509, 11621, 2929, 9, 272, 1849, 21252, 29170, 275, 7242, 15183, 342, 259, 327, 1849, 21252, 22834, 609, 379, 3628, 334, 509, 11621, 2929, 9, 272, 1849, 21252, 1513, 5923, 275, 7242, 15183, 342, 258, 327, 3240, 5923, 370, 314, 22834, 609, 379, 334, 509, 11621, 2929, 9, 2286, 3240, 2820, 3205, 27138, 275, 7242, 15183, 8, 1896, 29, 17, 9, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 4619, 54, 528, 345, 25103, 609, 379, 22347, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 291, 423, 5176, 12109, 275, 488, 2728, 327, 7259, 1345, 13268, 764, 267, 327, 5679, 2348, 4440, 1324, 9245, 378, 12, 18, 12, 21, 2728, 327, 6924, 5358, 2681, 397, 1524, 16, 12, 18, 12, 21, 61, 10894, 267, 327, 13293, 971, 267, 327, 6924, 3491, 10652, 2595, 30, 1687, 5358, 51, 27975, 1275, 19804, 59, 16, 61, 1553, 2696, 267, 327, 2476, 463, 1275, 19804, 59, 17, 61, 4099, 30, 1687, 17400, 10541, 1687, 25103, 609, 379, 10541, 1687, 25103, 609, 379, 4437, 10541, 1687, 4117, 1793, 10541, 17160, 4960, 327, 2476, 463, 1275, 19804, 59, 18, 61, 10894, 15, 5185, 1182, 267, 327, 26209, 1182, 267, 327, 3240, 379, 12109, 1110, 10894, 7861, 10195, 19554, 2320, 10894, 8540, 1182, 267, 327, 9668, 971, 2476, 971, 8295, 1182, 267, 327, 6924, 3491, 4143, 30, 1687, 12109, 10541, 1687, 19554, 44, 7570, 1435, 10541, 1687, 19554, 4131, 9063, 1553, 5118, 1687, 19554, 4437, 10541, 1687, 19554, 4117, 1793, 10541, 17160, 2728, 327, 2790, 10211, 267, 291, 14, 411, 5358, 51, 27975, 275, 9319, 3947, 3836, 51, 27975, 18, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 17400, 275, 9319, 3947, 3836, 16797, 836, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 25103, 609, 379, 275, 9319, 54, 528, 345, 25103, 609, 379, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 25103, 609, 379, 4437, 275, 9319, 14034, 68, 3142, 20999, 4437, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 4117, 1793, 275, 9319, 4117, 794, 14016, 8, 1708, 29, 277, 9, 2728, 291, 14, 411, 12109, 275, 9319, 14383, 7961, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 19554, 44, 7570, 1435, 275, 9319, 54, 528, 345, 4314, 6464, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 19554, 4131, 275, 9319, 4131, 14016, 8, 1708, 29, 277, 9, 267, 291, 14, 411, 19554, 4437, 275, 9319, 14034, 68, 3142, 20999, 4437, 8, 1708, 29, 277, 9, 18418, 291, 14, 411, 19554, 4117, 1793, 275, 9319, 4117, 794, 14016, 8, 1708, 29, 277, 9, 398, 327, 9496, 2488, 1324, 9245, 267, 291, 14, 411, 5358, 51, 27975, 14, 3205, 14, 2242, 8, 291, 14, 3205, 3491, 776, 267, 291, 14, 411, 5358, 51, 27975, 14, 14034, 2681, 397, 14, 2242, 8, 291, 14, 3205, 5358, 2681, 397, 776, 267, 291, 14, 411, 5358, 51, 27975, 14, 11220, 5318, 14, 14733, 360, 67, 358, 398, 327, 437, 3652, 4895, 9245, 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 ]
strk/QGIS
tests/src/python/test_qgsdataitemproviderregistry.py
2
2696
# -*- coding: utf-8 -*- """QGIS Unit tests for QgsDataItemProviderRegistry .. note:: This program 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. """ __author__ = 'Nyall Dawson' __date__ = '27/10/2018' __copyright__ = 'Copyright 2018, The QGIS Project' import qgis # NOQA from qgis.core import (QgsApplication, QgsDataItemProvider, QgsDataProvider, QgsDataItemProviderRegistry) from qgis.testing import start_app, unittest app = start_app() class TestProvider(QgsDataItemProvider): def __init__(self, name): super().__init__() self._name = name def name(self): return self._name def capabilities(self): return QgsDataProvider.File def createDataItem(self, path, parent): return None class TestQgsDataItemProviderRegistry(unittest.TestCase): def testAppRegistry(self): # ensure there is an application instance self.assertIsNotNone(QgsApplication.dataItemProviderRegistry()) def testRegistry(self): registry = QgsDataItemProviderRegistry() initial_providers = registry.providers() self.assertTrue(initial_providers) # we expect a bunch of default providers self.assertTrue([p.name() for p in initial_providers if p.name() == 'GDAL']) # add a new provider p1 = TestProvider('p1') registry.addProvider(p1) self.assertIn(p1, registry.providers()) p2 = TestProvider('p2') registry.addProvider(p2) self.assertIn(p1, registry.providers()) self.assertIn(p2, registry.providers()) registry.removeProvider(None) p3 = TestProvider('p3') # not in registry yet registry.removeProvider(p3) registry.removeProvider(p1) self.assertNotIn('p1', [p.name() for p in registry.providers()]) self.assertIn(p2, registry.providers()) registry.removeProvider(p2) self.assertNotIn('p2', [p.name() for p in registry.providers()]) self.assertEqual(registry.providers(), initial_providers) def testProviderKey(self): """Tests finding provider by name and return dataProviderKey""" registry = QgsDataItemProviderRegistry() self.assertIsNotNone(registry.provider('PostGIS')) self.assertIsNone(registry.provider('paper_and_pencil')) self.assertEqual(registry.provider('PostGIS').dataProviderKey(), 'postgres') if __name__ == '__main__': unittest.main()
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 31329, 12008, 2295, 367, 4888, 1451, 2081, 6663, 10899, 199, 199, 703, 5317, 447, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 390, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 1589, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 8, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 624, 199, 363, 2502, 363, 275, 283, 22781, 452, 577, 10084, 834, 7, 199, 363, 602, 363, 275, 283, 1465, 15, 709, 15, 12682, 7, 199, 363, 7307, 363, 275, 283, 7384, 14894, 12, 710, 27024, 7290, 7, 199, 199, 646, 15640, 221, 327, 20432, 199, 199, 504, 15640, 14, 1018, 492, 334, 7350, 5039, 12, 2432, 4888, 1451, 2081, 6663, 12, 2432, 4888, 1451, 6663, 12, 2432, 4888, 1451, 2081, 6663, 10899, 9, 199, 504, 15640, 14, 4776, 492, 1343, 63, 571, 12, 2882, 199, 199, 571, 275, 1343, 63, 571, 342, 421, 199, 533, 1379, 6663, 8, 7350, 1451, 2081, 6663, 304, 339, 347, 636, 826, 721, 277, 12, 536, 304, 267, 1613, 11027, 826, 4533, 267, 291, 423, 354, 275, 536, 339, 347, 536, 8, 277, 304, 267, 372, 291, 423, 354, 339, 347, 14918, 8, 277, 304, 267, 372, 4888, 1451, 6663, 14, 1173, 339, 347, 1218, 1451, 2081, 8, 277, 12, 931, 12, 1676, 304, 267, 372, 488, 421, 199, 533, 1379, 7350, 1451, 2081, 6663, 10899, 8, 2796, 14, 1746, 304, 339, 347, 511, 2640, 10899, 8, 277, 304, 267, 327, 4868, 2337, 365, 376, 4223, 1256, 267, 291, 14, 10389, 8, 7350, 5039, 14, 576, 2081, 6663, 10899, 1012, 339, 347, 511, 10899, 8, 277, 304, 267, 7086, 275, 4888, 1451, 2081, 6663, 10899, 342, 267, 2536, 63, 9710, 275, 7086, 14, 9710, 342, 267, 291, 14, 1815, 8, 2747, 63, 9710, 9, 327, 781, 4282, 282, 22219, 402, 849, 18032, 267, 291, 14, 1815, 779, 80, 14, 354, 342, 367, 299, 315, 2536, 63, 9710, 340, 299, 14, 354, 342, 508, 283, 17835, 1105, 398, 327, 1050, 282, 892, 5022, 267, 299, 17, 275, 1379, 6663, 360, 80, 17, 358, 267, 7086, 14, 525, 6663, 8, 80, 17, 9, 267, 291, 14, 4080, 8, 80, 17, 12, 7086, 14, 9710, 1012, 398, 299, 18, 275, 1379, 6663, 360, 80, 18, 358, 267, 7086, 14, 525, 6663, 8, 80, 18, 9, 267, 291, 14, 4080, 8, 80, 17, 12, 7086, 14, 9710, 1012, 267, 291, 14, 4080, 8, 80, 18, 12, 7086, 14, 9710, 1012, 398, 7086, 14, 2168, 6663, 8, 403, 9, 267, 299, 19, 275, 1379, 6663, 360, 80, 19, 358, 267, 327, 440, 315, 7086, 5966, 267, 7086, 14, 2168, 6663, 8, 80, 19, 9, 398, 7086, 14, 2168, 6663, 8, 80, 17, 9, 267, 291, 14, 8795, 360, 80, 17, 297, 359, 80, 14, 354, 342, 367, 299, 315, 7086, 14, 9710, 9383, 267, 291, 14, 4080, 8, 80, 18, 12, 7086, 14, 9710, 1012, 398, 7086, 14, 2168, 6663, 8, 80, 18, 9, 267, 291, 14, 8795, 360, 80, 18, 297, 359, 80, 14, 354, 342, 367, 299, 315, 7086, 14, 9710, 9383, 267, 291, 14, 629, 8, 5189, 14, 9710, 1062, 2536, 63, 9710, 9, 339, 347, 511, 6663, 1197, 8, 277, 304, 267, 408, 2925, 17196, 5022, 701, 536, 436, 372, 666, 6663, 1197, 624, 398, 7086, 275, 4888, 1451, 2081, 6663, 10899, 342, 267, 291, 14, 10389, 8, 5189, 14, 3780, 360, 6564, 11092, 1333, 267, 291, 14, 7702, 8, 5189, 14, 3780, 360, 10443, 63, 460, 63, 897, 24707, 1333, 267, 291, 14, 629, 8, 5189, 14, 3780, 360, 6564, 11092, 1959, 27735, 1197, 1062, 283, 10675, 358, 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 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 31329, 12008, 2295, 367, 4888, 1451, 2081, 6663, 10899, 199, 199, 703, 5317, 447, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 390, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 1589, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 8, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 624, 199, 363, 2502, 363, 275, 283, 22781, 452, 577, 10084, 834, 7, 199, 363, 602, 363, 275, 283, 1465, 15, 709, 15, 12682, 7, 199, 363, 7307, 363, 275, 283, 7384, 14894, 12, 710, 27024, 7290, 7, 199, 199, 646, 15640, 221, 327, 20432, 199, 199, 504, 15640, 14, 1018, 492, 334, 7350, 5039, 12, 2432, 4888, 1451, 2081, 6663, 12, 2432, 4888, 1451, 6663, 12, 2432, 4888, 1451, 2081, 6663, 10899, 9, 199, 504, 15640, 14, 4776, 492, 1343, 63, 571, 12, 2882, 199, 199, 571, 275, 1343, 63, 571, 342, 421, 199, 533, 1379, 6663, 8, 7350, 1451, 2081, 6663, 304, 339, 347, 636, 826, 721, 277, 12, 536, 304, 267, 1613, 11027, 826, 4533, 267, 291, 423, 354, 275, 536, 339, 347, 536, 8, 277, 304, 267, 372, 291, 423, 354, 339, 347, 14918, 8, 277, 304, 267, 372, 4888, 1451, 6663, 14, 1173, 339, 347, 1218, 1451, 2081, 8, 277, 12, 931, 12, 1676, 304, 267, 372, 488, 421, 199, 533, 1379, 7350, 1451, 2081, 6663, 10899, 8, 2796, 14, 1746, 304, 339, 347, 511, 2640, 10899, 8, 277, 304, 267, 327, 4868, 2337, 365, 376, 4223, 1256, 267, 291, 14, 10389, 8, 7350, 5039, 14, 576, 2081, 6663, 10899, 1012, 339, 347, 511, 10899, 8, 277, 304, 267, 7086, 275, 4888, 1451, 2081, 6663, 10899, 342, 267, 2536, 63, 9710, 275, 7086, 14, 9710, 342, 267, 291, 14, 1815, 8, 2747, 63, 9710, 9, 327, 781, 4282, 282, 22219, 402, 849, 18032, 267, 291, 14, 1815, 779, 80, 14, 354, 342, 367, 299, 315, 2536, 63, 9710, 340, 299, 14, 354, 342, 508, 283, 17835, 1105, 398, 327, 1050, 282, 892, 5022, 267, 299, 17, 275, 1379, 6663, 360, 80, 17, 358, 267, 7086, 14, 525, 6663, 8, 80, 17, 9, 267, 291, 14, 4080, 8, 80, 17, 12, 7086, 14, 9710, 1012, 398, 299, 18, 275, 1379, 6663, 360, 80, 18, 358, 267, 7086, 14, 525, 6663, 8, 80, 18, 9, 267, 291, 14, 4080, 8, 80, 17, 12, 7086, 14, 9710, 1012, 267, 291, 14, 4080, 8, 80, 18, 12, 7086, 14, 9710, 1012, 398, 7086, 14, 2168, 6663, 8, 403, 9, 267, 299, 19, 275, 1379, 6663, 360, 80, 19, 358, 267, 327, 440, 315, 7086, 5966, 267, 7086, 14, 2168, 6663, 8, 80, 19, 9, 398, 7086, 14, 2168, 6663, 8, 80, 17, 9, 267, 291, 14, 8795, 360, 80, 17, 297, 359, 80, 14, 354, 342, 367, 299, 315, 7086, 14, 9710, 9383, 267, 291, 14, 4080, 8, 80, 18, 12, 7086, 14, 9710, 1012, 398, 7086, 14, 2168, 6663, 8, 80, 18, 9, 267, 291, 14, 8795, 360, 80, 18, 297, 359, 80, 14, 354, 342, 367, 299, 315, 7086, 14, 9710, 9383, 267, 291, 14, 629, 8, 5189, 14, 9710, 1062, 2536, 63, 9710, 9, 339, 347, 511, 6663, 1197, 8, 277, 304, 267, 408, 2925, 17196, 5022, 701, 536, 436, 372, 666, 6663, 1197, 624, 398, 7086, 275, 4888, 1451, 2081, 6663, 10899, 342, 267, 291, 14, 10389, 8, 5189, 14, 3780, 360, 6564, 11092, 1333, 267, 291, 14, 7702, 8, 5189, 14, 3780, 360, 10443, 63, 460, 63, 897, 24707, 1333, 267, 291, 14, 629, 8, 5189, 14, 3780, 360, 6564, 11092, 1959, 27735, 1197, 1062, 283, 10675, 358, 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, 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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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 ]
HyperBaton/ansible
lib/ansible/modules/cloud/google/_gcspanner.py
37
9993
#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright: (c) 2017, Google Inc. # 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': ['deprecated'], 'supported_by': 'community'} DOCUMENTATION = ''' --- module: gcspanner version_added: "2.3" short_description: Create and Delete Instances/Databases on Spanner description: - Create and Delete Instances/Databases on Spanner. See U(https://cloud.google.com/spanner/docs) for an overview. requirements: - python >= 2.6 - google-auth >= 0.5.0 - google-cloud-spanner >= 0.23.0 notes: - Changing the configuration on an existing instance is not supported. deprecated: removed_in: "2.12" why: Updated modules released with increased functionality alternative: Use M(gcp_spanner_database) and/or M(gcp_spanner_instance) instead. author: - Tom Melendez (@supertom) <tom@supertom.com> options: configuration: description: - Configuration the instance should use. - Examples are us-central1, asia-east1 and europe-west1. required: yes instance_id: description: - GCP spanner instance name. required: yes database_name: description: - Name of database contained on the instance. force_instance_delete: description: - To delete an instance, this argument must exist and be true (along with state being equal to absent). type: bool default: 'no' instance_display_name: description: - Name of Instance to display. - If not specified, instance_id will be used instead. node_count: description: - Number of nodes in the instance. default: 1 state: description: - State of the instance or database. Applies to the most granular resource. - If a C(database_name) is specified we remove it. - If only C(instance_id) is specified, that is what is removed. choices: [ absent, present ] default: present ''' EXAMPLES = ''' - name: Create instance gcspanner: instance_id: '{{ instance_id }}' configuration: '{{ configuration }}' state: present node_count: 1 - name: Create database gcspanner: instance_id: '{{ instance_id }}' configuration: '{{ configuration }}' database_name: '{{ database_name }}' state: present - name: Delete instance (and all databases) - gcspanner: instance_id: '{{ instance_id }}' configuration: '{{ configuration }}' state: absent force_instance_delete: yes ''' RETURN = ''' state: description: The state of the instance or database. Value will be either 'absent' or 'present'. returned: Always type: str sample: "present" database_name: description: Name of database. returned: When database name is specified type: str sample: "mydatabase" instance_id: description: Name of instance. returned: Always type: str sample: "myinstance" previous_values: description: List of dictionaries containing previous values prior to update. returned: When an instance update has occurred and a field has been modified. type: dict sample: "'previous_values': { 'instance': { 'instance_display_name': 'my-instance', 'node_count': 1 } }" updated: description: Boolean field to denote an update has occurred. returned: When an update has occurred. type: bool sample: True ''' try: from ast import literal_eval HAS_PYTHON26 = True except ImportError: HAS_PYTHON26 = False try: from google.cloud import spanner from google.gax.errors import GaxError HAS_GOOGLE_CLOUD_SPANNER = True except ImportError as e: HAS_GOOGLE_CLOUD_SPANNER = False from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.gcp import check_min_pkg_version, get_google_cloud_credentials from ansible.module_utils.six import string_types CLOUD_CLIENT = 'google-cloud-spanner' CLOUD_CLIENT_MINIMUM_VERSION = '0.23.0' CLOUD_CLIENT_USER_AGENT = 'ansible-spanner-0.1' def get_spanner_configuration_name(config_name, project_name): config_name = 'projects/%s/instanceConfigs/regional-%s' % (project_name, config_name) return config_name def instance_update(instance): """ Call update method on spanner client. Note: A ValueError exception is thrown despite the client succeeding. So, we validate the node_count and instance_display_name parameters and then ignore the ValueError exception. :param instance: a Spanner instance object :type instance: class `google.cloud.spanner.Instance` :returns True on success, raises ValueError on type error. :rtype ``bool`` """ errmsg = '' if not isinstance(instance.node_count, int): errmsg = 'node_count must be an integer %s (%s)' % ( instance.node_count, type(instance.node_count)) if instance.display_name and not isinstance(instance.display_name, string_types): errmsg = 'instance_display_name must be an string %s (%s)' % ( instance.display_name, type(instance.display_name)) if errmsg: raise ValueError(errmsg) try: instance.update() except ValueError: # The ValueError here is the one we 'expect'. pass return True def main(): module = AnsibleModule( argument_spec=dict( instance_id=dict(type='str', required=True), state=dict(type='str', default='present', choices=['absent', 'present']), database_name=dict(type='str'), configuration=dict(type='str', required=True), node_count=dict(type='int', default=1), instance_display_name=dict(type='str'), force_instance_delete=dict(type='bool', default=False), service_account_email=dict(type='str'), credentials_file=dict(type='str'), project_id=dict(type='str'), ), ) if not HAS_PYTHON26: module.fail_json( msg="GCE module requires python's 'ast' module, python v2.6+") if not HAS_GOOGLE_CLOUD_SPANNER: module.fail_json(msg="Please install google-cloud-spanner.") if not check_min_pkg_version(CLOUD_CLIENT, CLOUD_CLIENT_MINIMUM_VERSION): module.fail_json(msg="Please install %s client version %s" % (CLOUD_CLIENT, CLOUD_CLIENT_MINIMUM_VERSION)) mod_params = {} mod_params['state'] = module.params.get('state') mod_params['instance_id'] = module.params.get('instance_id') mod_params['database_name'] = module.params.get('database_name') mod_params['configuration'] = module.params.get('configuration') mod_params['node_count'] = module.params.get('node_count', None) mod_params['instance_display_name'] = module.params.get('instance_display_name') mod_params['force_instance_delete'] = module.params.get('force_instance_delete') creds, params = get_google_cloud_credentials(module) spanner_client = spanner.Client(project=params['project_id'], credentials=creds, user_agent=CLOUD_CLIENT_USER_AGENT) changed = False json_output = {} i = None if mod_params['instance_id']: config_name = get_spanner_configuration_name( mod_params['configuration'], params['project_id']) i = spanner_client.instance(mod_params['instance_id'], configuration_name=config_name) d = None if mod_params['database_name']: # TODO(supertom): support DDL ddl_statements = '' d = i.database(mod_params['database_name'], ddl_statements) if mod_params['state'] == 'absent': # Remove the most granular resource. If database is specified # we remove it. If only instance is specified, that is what is removed. if d is not None and d.exists(): d.drop() changed = True else: if i.exists(): if mod_params['force_instance_delete']: i.delete() else: module.fail_json( msg=(("Cannot delete Spanner instance: " "'force_instance_delete' argument not specified"))) changed = True elif mod_params['state'] == 'present': if not i.exists(): i = spanner_client.instance(mod_params['instance_id'], configuration_name=config_name, display_name=mod_params['instance_display_name'], node_count=mod_params['node_count'] or 1) i.create() changed = True else: # update instance i.reload() inst_prev_vals = {} if i.display_name != mod_params['instance_display_name']: inst_prev_vals['instance_display_name'] = i.display_name i.display_name = mod_params['instance_display_name'] if mod_params['node_count']: if i.node_count != mod_params['node_count']: inst_prev_vals['node_count'] = i.node_count i.node_count = mod_params['node_count'] if inst_prev_vals: changed = instance_update(i) json_output['updated'] = changed json_output['previous_values'] = {'instance': inst_prev_vals} if d: if not d.exists(): d.create() d.reload() changed = True json_output['changed'] = changed json_output.update(mod_params) module.exit_json(**json_output) 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, 4475, 3277, 14, 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, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 6667, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 9486, 681, 5161, 199, 1023, 63, 3270, 26, 298, 18, 14, 19, 2, 199, 3612, 63, 1802, 26, 2790, 436, 8496, 10066, 83, 15, 7243, 83, 641, 8360, 5161, 199, 1802, 26, 272, 446, 2790, 436, 8496, 10066, 83, 15, 7243, 83, 641, 8360, 5161, 14, 489, 1666, 738, 8, 2859, 921, 4091, 14, 3098, 14, 957, 15, 681, 5161, 15, 4757, 9, 367, 376, 23503, 14, 199, 7538, 26, 523, 446, 2366, 2356, 499, 14, 22, 523, 446, 6233, 13, 1178, 2356, 378, 14, 21, 14, 16, 523, 446, 6233, 13, 4091, 13, 681, 5161, 2356, 378, 14, 1789, 14, 16, 199, 5983, 26, 523, 446, 27854, 314, 2897, 641, 376, 3411, 1256, 365, 440, 3748, 14, 199, 6667, 26, 272, 4829, 63, 262, 26, 298, 18, 14, 713, 2, 272, 10842, 26, 6162, 68, 4621, 14286, 543, 10035, 11185, 9330, 272, 13943, 26, 3645, 603, 8, 20622, 63, 681, 5161, 63, 4659, 9, 436, 15, 269, 603, 8, 20622, 63, 681, 5161, 63, 842, 9, 3140, 14, 199, 2502, 26, 523, 446, 21644, 3194, 552, 271, 90, 8593, 4792, 3151, 9, 665, 3151, 32, 4792, 3151, 14, 957, 30, 199, 1419, 26, 523, 2897, 26, 272, 1369, 26, 2126, 446, 11595, 314, 1256, 1077, 675, 14, 2126, 446, 6058, 787, 2739, 13, 16067, 17, 12, 282, 10971, 13, 14346, 17, 436, 325, 12646, 13, 19082, 17, 14, 272, 1415, 26, 9456, 523, 1256, 63, 344, 26, 272, 1369, 26, 2126, 446, 30902, 2249, 5161, 1256, 536, 14, 272, 1415, 26, 9456, 523, 3050, 63, 354, 26, 272, 1369, 26, 2126, 446, 2812, 402, 3050, 10470, 641, 314, 1256, 14, 523, 3542, 63, 842, 63, 1807, 26, 272, 1369, 26, 2126, 446, 4005, 3145, 376, 1256, 12, 642, 1423, 1471, 2187, 436, 506, 2549, 334, 21632, 543, 1174, 3769, 4472, 370, 9552, 680, 272, 730, 26, 2155, 272, 849, 26, 283, 889, 7, 523, 1256, 63, 2918, 63, 354, 26, 272, 1369, 26, 2126, 446, 2812, 402, 10066, 370, 2929, 14, 2126, 446, 982, 440, 2013, 12, 1256, 63, 344, 911, 506, 1202, 3140, 14, 523, 1031, 63, 835, 26, 272, 1369, 26, 2126, 446, 4860, 402, 3380, 315, 314, 1256, 14, 272, 849, 26, 413, 523, 1174, 26, 272, 1369, 26, 272, 446, 8511, 402, 314, 1256, 503, 3050, 14, 4693, 6528, 370, 314, 4750, 9202, 2238, 2073, 14, 272, 446, 982, 282, 445, 8, 4659, 63, 354, 9, 365, 2013, 781, 2813, 652, 14, 272, 446, 982, 1454, 445, 8, 842, 63, 344, 9, 365, 2013, 12, 626, 365, 4052, 365, 4829, 14, 272, 3415, 26, 359, 9552, 12, 3451, 1622, 272, 849, 26, 3451, 199, 2344, 199, 199, 8918, 275, 1449, 199, 13, 536, 26, 2790, 1256, 523, 9486, 681, 5161, 26, 272, 1256, 63, 344, 26, 11400, 1256, 63, 344, 16339, 272, 2897, 26, 11400, 2897, 16339, 272, 1174, 26, 3451, 272, 1031, 63, 835, 26, 413, 199, 199, 13, 536, 26, 2790, 3050, 523, 9486, 681, 5161, 26, 272, 1256, 63, 344, 26, 11400, 1256, 63, 344, 16339, 272, 2897, 26, 11400, 2897, 16339, 272, 3050, 63, 354, 26, 11400, 3050, 63, 354, 16339, 272, 1174, 26, 3451, 199, 199, 13, 536, 26, 8496, 1256, 334, 460, 1006, 16219, 9, 199, 13, 9486, 681, 5161, 26, 272, 1256, 63, 344, 26, 11400, 1256, 63, 344, 16339, 272, 2897, 26, 11400, 2897, 16339, 272, 1174, 26, 9552, 272, 3542, 63, 842, 63, 1807, 26, 9456, 199, 2344, 199, 199, 9677, 275, 1449, 199, 929, 26, 272, 1369, 26, 710, 1174, 402, 314, 1256, 503, 3050, 14, 1594, 911, 506, 1902, 283, 5575, 7, 503, 283, 1881, 1370, 272, 2138, 26, 16763, 272, 730, 26, 620, 272, 2690, 26, 298, 1881, 2, 199, 199, 4659, 63, 354, 26, 272, 1369, 26, 2812, 402, 3050, 14, 272, 2138, 26, 3979, 3050, 536, 365, 2013, 272, 730, 26, 620, 272, 2690, 26, 298, 1662, 4659, 2, 199, 199, 842, 63, 344, 26, 272, 1369, 26, 2812, 402, 1256, 14, 272, 2138, 26, 16763, 272, 730, 26, 620, 272, 2690, 26, 298, 1662, 842, 2, 199, 199, 6352, 63, 1459, 26, 2043, 1369, 26, 3820, 402, 11196, 3035, 4136, 1338, 6791, 370, 1678, 14, 2043, 2138, 26, 3979, 376, 1256, 1678, 965, 8920, 436, 282, 901, 965, 2757, 6042, 14, 2043, 730, 26, 1211, 2043, 2690, 26, 3546, 6352, 63, 1459, 356, 469, 283, 842, 356, 469, 283, 842, 63, 2918, 63, 354, 356, 283, 1662, 13, 842, 297, 283, 932, 63, 835, 356, 413, 789, 789, 2, 199, 199, 5334, 26, 2043, 1369, 26, 9411, 901, 370, 477, 4610, 376, 1678, 965, 8920, 14, 2043, 2138, 26, 3979, 376, 1678, 965, 8920, 14, 2043, 730, 26, 2155, 2043, 2690, 26, 715, 199, 2344, 199, 893, 26, 272, 687, 6073, 492, 8785, 63, 2579, 272, 7509, 63, 11720, 1479, 275, 715, 199, 2590, 3545, 26, 272, 7509, 63, 11720, 1479, 275, 756, 199, 199, 893, 26, 272, 687, 6233, 14, 4091, 492, 2249, 5161, 272, 687, 6233, 14, 71, 1219, 14, 2550, 492, 598, 1219, 547, 272, 7509, 63, 24243, 63, 29495, 63, 5763, 879, 15215, 275, 715, 199, 2590, 3545, 465, 325, 26, 272, 7509, 63, 24243, 63, 29495, 63, 5763, 879, 15215, 275, 756, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 20622, 492, 1104, 63, 827, 63, 4600, 63, 1023, 12, 664, 63 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 1898, 26, 334, 67, 9, 9708, 12, 4475, 3277, 14, 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, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 6667, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 9486, 681, 5161, 199, 1023, 63, 3270, 26, 298, 18, 14, 19, 2, 199, 3612, 63, 1802, 26, 2790, 436, 8496, 10066, 83, 15, 7243, 83, 641, 8360, 5161, 199, 1802, 26, 272, 446, 2790, 436, 8496, 10066, 83, 15, 7243, 83, 641, 8360, 5161, 14, 489, 1666, 738, 8, 2859, 921, 4091, 14, 3098, 14, 957, 15, 681, 5161, 15, 4757, 9, 367, 376, 23503, 14, 199, 7538, 26, 523, 446, 2366, 2356, 499, 14, 22, 523, 446, 6233, 13, 1178, 2356, 378, 14, 21, 14, 16, 523, 446, 6233, 13, 4091, 13, 681, 5161, 2356, 378, 14, 1789, 14, 16, 199, 5983, 26, 523, 446, 27854, 314, 2897, 641, 376, 3411, 1256, 365, 440, 3748, 14, 199, 6667, 26, 272, 4829, 63, 262, 26, 298, 18, 14, 713, 2, 272, 10842, 26, 6162, 68, 4621, 14286, 543, 10035, 11185, 9330, 272, 13943, 26, 3645, 603, 8, 20622, 63, 681, 5161, 63, 4659, 9, 436, 15, 269, 603, 8, 20622, 63, 681, 5161, 63, 842, 9, 3140, 14, 199, 2502, 26, 523, 446, 21644, 3194, 552, 271, 90, 8593, 4792, 3151, 9, 665, 3151, 32, 4792, 3151, 14, 957, 30, 199, 1419, 26, 523, 2897, 26, 272, 1369, 26, 2126, 446, 11595, 314, 1256, 1077, 675, 14, 2126, 446, 6058, 787, 2739, 13, 16067, 17, 12, 282, 10971, 13, 14346, 17, 436, 325, 12646, 13, 19082, 17, 14, 272, 1415, 26, 9456, 523, 1256, 63, 344, 26, 272, 1369, 26, 2126, 446, 30902, 2249, 5161, 1256, 536, 14, 272, 1415, 26, 9456, 523, 3050, 63, 354, 26, 272, 1369, 26, 2126, 446, 2812, 402, 3050, 10470, 641, 314, 1256, 14, 523, 3542, 63, 842, 63, 1807, 26, 272, 1369, 26, 2126, 446, 4005, 3145, 376, 1256, 12, 642, 1423, 1471, 2187, 436, 506, 2549, 334, 21632, 543, 1174, 3769, 4472, 370, 9552, 680, 272, 730, 26, 2155, 272, 849, 26, 283, 889, 7, 523, 1256, 63, 2918, 63, 354, 26, 272, 1369, 26, 2126, 446, 2812, 402, 10066, 370, 2929, 14, 2126, 446, 982, 440, 2013, 12, 1256, 63, 344, 911, 506, 1202, 3140, 14, 523, 1031, 63, 835, 26, 272, 1369, 26, 2126, 446, 4860, 402, 3380, 315, 314, 1256, 14, 272, 849, 26, 413, 523, 1174, 26, 272, 1369, 26, 272, 446, 8511, 402, 314, 1256, 503, 3050, 14, 4693, 6528, 370, 314, 4750, 9202, 2238, 2073, 14, 272, 446, 982, 282, 445, 8, 4659, 63, 354, 9, 365, 2013, 781, 2813, 652, 14, 272, 446, 982, 1454, 445, 8, 842, 63, 344, 9, 365, 2013, 12, 626, 365, 4052, 365, 4829, 14, 272, 3415, 26, 359, 9552, 12, 3451, 1622, 272, 849, 26, 3451, 199, 2344, 199, 199, 8918, 275, 1449, 199, 13, 536, 26, 2790, 1256, 523, 9486, 681, 5161, 26, 272, 1256, 63, 344, 26, 11400, 1256, 63, 344, 16339, 272, 2897, 26, 11400, 2897, 16339, 272, 1174, 26, 3451, 272, 1031, 63, 835, 26, 413, 199, 199, 13, 536, 26, 2790, 3050, 523, 9486, 681, 5161, 26, 272, 1256, 63, 344, 26, 11400, 1256, 63, 344, 16339, 272, 2897, 26, 11400, 2897, 16339, 272, 3050, 63, 354, 26, 11400, 3050, 63, 354, 16339, 272, 1174, 26, 3451, 199, 199, 13, 536, 26, 8496, 1256, 334, 460, 1006, 16219, 9, 199, 13, 9486, 681, 5161, 26, 272, 1256, 63, 344, 26, 11400, 1256, 63, 344, 16339, 272, 2897, 26, 11400, 2897, 16339, 272, 1174, 26, 9552, 272, 3542, 63, 842, 63, 1807, 26, 9456, 199, 2344, 199, 199, 9677, 275, 1449, 199, 929, 26, 272, 1369, 26, 710, 1174, 402, 314, 1256, 503, 3050, 14, 1594, 911, 506, 1902, 283, 5575, 7, 503, 283, 1881, 1370, 272, 2138, 26, 16763, 272, 730, 26, 620, 272, 2690, 26, 298, 1881, 2, 199, 199, 4659, 63, 354, 26, 272, 1369, 26, 2812, 402, 3050, 14, 272, 2138, 26, 3979, 3050, 536, 365, 2013, 272, 730, 26, 620, 272, 2690, 26, 298, 1662, 4659, 2, 199, 199, 842, 63, 344, 26, 272, 1369, 26, 2812, 402, 1256, 14, 272, 2138, 26, 16763, 272, 730, 26, 620, 272, 2690, 26, 298, 1662, 842, 2, 199, 199, 6352, 63, 1459, 26, 2043, 1369, 26, 3820, 402, 11196, 3035, 4136, 1338, 6791, 370, 1678, 14, 2043, 2138, 26, 3979, 376, 1256, 1678, 965, 8920, 436, 282, 901, 965, 2757, 6042, 14, 2043, 730, 26, 1211, 2043, 2690, 26, 3546, 6352, 63, 1459, 356, 469, 283, 842, 356, 469, 283, 842, 63, 2918, 63, 354, 356, 283, 1662, 13, 842, 297, 283, 932, 63, 835, 356, 413, 789, 789, 2, 199, 199, 5334, 26, 2043, 1369, 26, 9411, 901, 370, 477, 4610, 376, 1678, 965, 8920, 14, 2043, 2138, 26, 3979, 376, 1678, 965, 8920, 14, 2043, 730, 26, 2155, 2043, 2690, 26, 715, 199, 2344, 199, 893, 26, 272, 687, 6073, 492, 8785, 63, 2579, 272, 7509, 63, 11720, 1479, 275, 715, 199, 2590, 3545, 26, 272, 7509, 63, 11720, 1479, 275, 756, 199, 199, 893, 26, 272, 687, 6233, 14, 4091, 492, 2249, 5161, 272, 687, 6233, 14, 71, 1219, 14, 2550, 492, 598, 1219, 547, 272, 7509, 63, 24243, 63, 29495, 63, 5763, 879, 15215, 275, 715, 199, 2590, 3545, 465, 325, 26, 272, 7509, 63, 24243, 63, 29495, 63, 5763, 879, 15215, 275, 756, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 20622, 492, 1104, 63, 827, 63, 4600, 63, 1023, 12, 664, 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,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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 ]
LaoZhongGu/kbengine
kbe/src/lib/python/Lib/plat-os2emx/IN.py
57
1869
# Generated by h2py from f:/emx/include/netinet/in.h # Included from sys/param.h PAGE_SIZE = 0x1000 HZ = 100 MAXNAMLEN = 260 MAXPATHLEN = 260 def htonl(X): return _swapl(X) def ntohl(X): return _swapl(X) def htons(X): return _swaps(X) def ntohs(X): return _swaps(X) IPPROTO_IP = 0 IPPROTO_ICMP = 1 IPPROTO_IGMP = 2 IPPROTO_GGP = 3 IPPROTO_TCP = 6 IPPROTO_EGP = 8 IPPROTO_PUP = 12 IPPROTO_UDP = 17 IPPROTO_IDP = 22 IPPROTO_TP = 29 IPPROTO_EON = 80 IPPROTO_RAW = 255 IPPROTO_MAX = 256 IPPORT_RESERVED = 1024 IPPORT_USERRESERVED = 5000 def IN_CLASSA(i): return (((int)(i) & 0x80000000) == 0) IN_CLASSA_NET = 0xff000000 IN_CLASSA_NSHIFT = 24 IN_CLASSA_HOST = 0x00ffffff IN_CLASSA_MAX = 128 def IN_CLASSB(i): return (((int)(i) & 0xc0000000) == 0x80000000) IN_CLASSB_NET = 0xffff0000 IN_CLASSB_NSHIFT = 16 IN_CLASSB_HOST = 0x0000ffff IN_CLASSB_MAX = 65536 def IN_CLASSC(i): return (((int)(i) & 0xe0000000) == 0xc0000000) IN_CLASSC_NET = 0xffffff00 IN_CLASSC_NSHIFT = 8 IN_CLASSC_HOST = 0x000000ff def IN_CLASSD(i): return (((int)(i) & 0xf0000000) == 0xe0000000) IN_CLASSD_NET = 0xf0000000 IN_CLASSD_NSHIFT = 28 IN_CLASSD_HOST = 0x0fffffff def IN_MULTICAST(i): return IN_CLASSD(i) def IN_EXPERIMENTAL(i): return (((int)(i) & 0xe0000000) == 0xe0000000) def IN_BADCLASS(i): return (((int)(i) & 0xf0000000) == 0xf0000000) INADDR_ANY = 0x00000000 INADDR_LOOPBACK = 0x7f000001 INADDR_BROADCAST = 0xffffffff INADDR_NONE = 0xffffffff INADDR_UNSPEC_GROUP = 0xe0000000 INADDR_ALLHOSTS_GROUP = 0xe0000001 INADDR_MAX_LOCAL_GROUP = 0xe00000ff IN_LOOPBACKNET = 127 IP_OPTIONS = 1 IP_MULTICAST_IF = 2 IP_MULTICAST_TTL = 3 IP_MULTICAST_LOOP = 4 IP_ADD_MEMBERSHIP = 5 IP_DROP_MEMBERSHIP = 6 IP_HDRINCL = 2 IP_TOS = 3 IP_TTL = 4 IP_RECVOPTS = 5 IP_RECVRETOPTS = 6 IP_RECVDSTADDR = 7 IP_RETOPTS = 8 IP_DEFAULT_MULTICAST_TTL = 1 IP_DEFAULT_MULTICAST_LOOP = 1 IP_MAX_MEMBERSHIPS = 20
lgpl-3.0
[ 3, 17065, 701, 394, 18, 647, 687, 289, 11254, 5633, 88, 15, 2613, 15, 846, 10811, 15, 262, 14, 72, 199, 199, 3, 32732, 687, 984, 15, 635, 14, 72, 199, 12898, 63, 4305, 275, 378, 88, 5279, 199, 25955, 275, 2948, 199, 4283, 7335, 5304, 275, 499, 2259, 199, 4283, 3243, 5304, 275, 499, 2259, 199, 318, 1243, 265, 76, 8, 56, 304, 372, 485, 9286, 76, 8, 56, 9, 199, 199, 318, 302, 475, 15544, 8, 56, 304, 372, 485, 9286, 76, 8, 56, 9, 199, 199, 318, 1243, 4654, 8, 56, 304, 372, 485, 3519, 7461, 8, 56, 9, 199, 199, 318, 302, 475, 4213, 8, 56, 304, 372, 485, 3519, 7461, 8, 56, 9, 199, 199, 20130, 63, 1772, 275, 378, 199, 20130, 63, 26616, 275, 413, 199, 20130, 63, 1277, 1658, 275, 499, 199, 20130, 63, 2916, 48, 275, 650, 199, 20130, 63, 9735, 275, 1227, 199, 20130, 63, 4680, 48, 275, 1695, 199, 20130, 63, 48, 2160, 275, 3144, 199, 20130, 63, 17457, 275, 5557, 199, 20130, 63, 998, 48, 275, 6928, 199, 20130, 63, 6495, 275, 7349, 199, 20130, 63, 37, 615, 275, 5939, 199, 20130, 63, 4307, 275, 5450, 199, 20130, 63, 4283, 275, 7633, 199, 1772, 3657, 63, 26933, 275, 6619, 199, 1772, 3657, 63, 1668, 2666, 654, 540, 14112, 275, 22369, 199, 318, 1621, 63, 6885, 33, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 88, 24, 9084, 9, 508, 378, 9, 199, 199, 568, 63, 6885, 33, 63, 7278, 275, 378, 3581, 3273, 199, 568, 63, 6885, 33, 63, 2709, 11183, 2161, 275, 5504, 199, 568, 63, 6885, 33, 63, 5449, 275, 378, 88, 383, 12596, 199, 568, 63, 6885, 33, 63, 4283, 275, 7960, 199, 318, 1621, 63, 6885, 34, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1812, 9084, 9, 508, 378, 88, 24, 9084, 9, 199, 199, 568, 63, 6885, 34, 63, 7278, 275, 378, 27581, 993, 199, 568, 63, 6885, 34, 63, 2709, 11183, 2161, 275, 3193, 199, 568, 63, 6885, 34, 63, 5449, 275, 378, 88, 993, 4717, 199, 568, 63, 6885, 34, 63, 4283, 275, 25980, 199, 318, 1621, 63, 6885, 35, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1845, 9084, 9, 508, 378, 1812, 9084, 9, 199, 199, 568, 63, 6885, 35, 63, 7278, 275, 378, 3581, 4717, 383, 199, 568, 63, 6885, 35, 63, 2709, 11183, 2161, 275, 1695, 199, 568, 63, 6885, 35, 63, 5449, 275, 378, 88, 3273, 556, 199, 318, 1621, 63, 1981, 1179, 3693, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1949, 9084, 9, 508, 378, 1845, 9084, 9, 199, 199, 568, 63, 1981, 1179, 3693, 63, 7278, 275, 378, 1949, 9084, 199, 568, 63, 1981, 1179, 3693, 63, 2709, 11183, 2161, 275, 7294, 199, 568, 63, 1981, 1179, 3693, 63, 5449, 275, 378, 88, 16, 12596, 70, 199, 318, 1621, 63, 8203, 948, 11307, 8, 73, 304, 372, 1621, 63, 1981, 1179, 3693, 8, 73, 9, 199, 199, 318, 1621, 63, 28722, 1309, 748, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1845, 9084, 9, 508, 378, 1845, 9084, 9, 199, 199, 318, 1621, 63, 9439, 6885, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1949, 9084, 9, 508, 378, 1949, 9084, 9, 199, 199, 568, 7803, 63, 8974, 275, 378, 88, 3607, 199, 568, 7803, 63, 26573, 7111, 275, 378, 88, 23, 70, 19983, 199, 568, 7803, 63, 21111, 32215, 275, 378, 21870, 199, 568, 7803, 63, 9185, 275, 378, 21870, 199, 568, 7803, 63, 1734, 24147, 63, 7823, 275, 378, 1845, 9084, 199, 568, 7803, 63, 1761, 23775, 63, 7823, 275, 378, 1845, 3273, 17, 199, 568, 7803, 63, 4283, 63, 7486, 63, 7823, 275, 378, 1845, 5345, 556, 199, 568, 63, 26573, 7111, 7278, 275, 12792, 199, 1772, 63, 8808, 275, 413, 199, 1772, 63, 8203, 948, 11307, 63, 4656, 275, 499, 199, 1772, 63, 8203, 948, 11307, 63, 25567, 275, 650, 199, 1772, 63, 8203, 948, 11307, 63, 26573, 275, 841, 199, 1772, 63, 9732, 63, 26682, 3234, 1772, 275, 959, 199, 1772, 63, 14764, 63, 26682, 3234, 1772, 275, 1227, 199, 1772, 63, 40, 4564, 568, 1981, 275, 499, 199, 1772, 63, 2566, 51, 275, 650, 199, 1772, 63, 25567, 275, 841, 199, 1772, 63, 9481, 54, 25636, 275, 959, 199, 1772, 63, 9481, 54, 7341, 25636, 275, 1227, 199, 1772, 63, 9481, 54, 18651, 7803, 275, 1520, 199, 1772, 63, 7341, 25636, 275, 1695, 199, 1772, 63, 3472, 63, 8203, 948, 11307, 63, 25567, 275, 413, 199, 1772, 63, 3472, 63, 8203, 948, 11307, 63, 26573, 275, 413, 199, 1772, 63, 4283, 63, 26682, 3234, 12346, 275, 3388, 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 ]
[ 17065, 701, 394, 18, 647, 687, 289, 11254, 5633, 88, 15, 2613, 15, 846, 10811, 15, 262, 14, 72, 199, 199, 3, 32732, 687, 984, 15, 635, 14, 72, 199, 12898, 63, 4305, 275, 378, 88, 5279, 199, 25955, 275, 2948, 199, 4283, 7335, 5304, 275, 499, 2259, 199, 4283, 3243, 5304, 275, 499, 2259, 199, 318, 1243, 265, 76, 8, 56, 304, 372, 485, 9286, 76, 8, 56, 9, 199, 199, 318, 302, 475, 15544, 8, 56, 304, 372, 485, 9286, 76, 8, 56, 9, 199, 199, 318, 1243, 4654, 8, 56, 304, 372, 485, 3519, 7461, 8, 56, 9, 199, 199, 318, 302, 475, 4213, 8, 56, 304, 372, 485, 3519, 7461, 8, 56, 9, 199, 199, 20130, 63, 1772, 275, 378, 199, 20130, 63, 26616, 275, 413, 199, 20130, 63, 1277, 1658, 275, 499, 199, 20130, 63, 2916, 48, 275, 650, 199, 20130, 63, 9735, 275, 1227, 199, 20130, 63, 4680, 48, 275, 1695, 199, 20130, 63, 48, 2160, 275, 3144, 199, 20130, 63, 17457, 275, 5557, 199, 20130, 63, 998, 48, 275, 6928, 199, 20130, 63, 6495, 275, 7349, 199, 20130, 63, 37, 615, 275, 5939, 199, 20130, 63, 4307, 275, 5450, 199, 20130, 63, 4283, 275, 7633, 199, 1772, 3657, 63, 26933, 275, 6619, 199, 1772, 3657, 63, 1668, 2666, 654, 540, 14112, 275, 22369, 199, 318, 1621, 63, 6885, 33, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 88, 24, 9084, 9, 508, 378, 9, 199, 199, 568, 63, 6885, 33, 63, 7278, 275, 378, 3581, 3273, 199, 568, 63, 6885, 33, 63, 2709, 11183, 2161, 275, 5504, 199, 568, 63, 6885, 33, 63, 5449, 275, 378, 88, 383, 12596, 199, 568, 63, 6885, 33, 63, 4283, 275, 7960, 199, 318, 1621, 63, 6885, 34, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1812, 9084, 9, 508, 378, 88, 24, 9084, 9, 199, 199, 568, 63, 6885, 34, 63, 7278, 275, 378, 27581, 993, 199, 568, 63, 6885, 34, 63, 2709, 11183, 2161, 275, 3193, 199, 568, 63, 6885, 34, 63, 5449, 275, 378, 88, 993, 4717, 199, 568, 63, 6885, 34, 63, 4283, 275, 25980, 199, 318, 1621, 63, 6885, 35, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1845, 9084, 9, 508, 378, 1812, 9084, 9, 199, 199, 568, 63, 6885, 35, 63, 7278, 275, 378, 3581, 4717, 383, 199, 568, 63, 6885, 35, 63, 2709, 11183, 2161, 275, 1695, 199, 568, 63, 6885, 35, 63, 5449, 275, 378, 88, 3273, 556, 199, 318, 1621, 63, 1981, 1179, 3693, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1949, 9084, 9, 508, 378, 1845, 9084, 9, 199, 199, 568, 63, 1981, 1179, 3693, 63, 7278, 275, 378, 1949, 9084, 199, 568, 63, 1981, 1179, 3693, 63, 2709, 11183, 2161, 275, 7294, 199, 568, 63, 1981, 1179, 3693, 63, 5449, 275, 378, 88, 16, 12596, 70, 199, 318, 1621, 63, 8203, 948, 11307, 8, 73, 304, 372, 1621, 63, 1981, 1179, 3693, 8, 73, 9, 199, 199, 318, 1621, 63, 28722, 1309, 748, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1845, 9084, 9, 508, 378, 1845, 9084, 9, 199, 199, 318, 1621, 63, 9439, 6885, 8, 73, 304, 372, 20337, 442, 5130, 73, 9, 1253, 378, 1949, 9084, 9, 508, 378, 1949, 9084, 9, 199, 199, 568, 7803, 63, 8974, 275, 378, 88, 3607, 199, 568, 7803, 63, 26573, 7111, 275, 378, 88, 23, 70, 19983, 199, 568, 7803, 63, 21111, 32215, 275, 378, 21870, 199, 568, 7803, 63, 9185, 275, 378, 21870, 199, 568, 7803, 63, 1734, 24147, 63, 7823, 275, 378, 1845, 9084, 199, 568, 7803, 63, 1761, 23775, 63, 7823, 275, 378, 1845, 3273, 17, 199, 568, 7803, 63, 4283, 63, 7486, 63, 7823, 275, 378, 1845, 5345, 556, 199, 568, 63, 26573, 7111, 7278, 275, 12792, 199, 1772, 63, 8808, 275, 413, 199, 1772, 63, 8203, 948, 11307, 63, 4656, 275, 499, 199, 1772, 63, 8203, 948, 11307, 63, 25567, 275, 650, 199, 1772, 63, 8203, 948, 11307, 63, 26573, 275, 841, 199, 1772, 63, 9732, 63, 26682, 3234, 1772, 275, 959, 199, 1772, 63, 14764, 63, 26682, 3234, 1772, 275, 1227, 199, 1772, 63, 40, 4564, 568, 1981, 275, 499, 199, 1772, 63, 2566, 51, 275, 650, 199, 1772, 63, 25567, 275, 841, 199, 1772, 63, 9481, 54, 25636, 275, 959, 199, 1772, 63, 9481, 54, 7341, 25636, 275, 1227, 199, 1772, 63, 9481, 54, 18651, 7803, 275, 1520, 199, 1772, 63, 7341, 25636, 275, 1695, 199, 1772, 63, 3472, 63, 8203, 948, 11307, 63, 25567, 275, 413, 199, 1772, 63, 3472, 63, 8203, 948, 11307, 63, 26573, 275, 413, 199, 1772, 63, 4283, 63, 26682, 3234, 12346, 275, 3388, 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, 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,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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
lexodistro/blissflixx
lib/chanutils/reddit/__init__.py
3
1251
import chanutils, playitem def search(subreddit, q, moviesubs=False): url = "http://www.reddit.com/r/" + subreddit + "/search.json" data = chanutils.get_json(url, params={'q':q, 'restrict_sr':'on'}) return _extract(data, moviesubs) def get_feed(feed, moviesubs=False): data = chanutils.get_json(feed['url']) return _extract(data, moviesubs) def _extract(data, moviesubs): results = playitem.PlayItemList() if not 'data' in data or len(data['data']['children']) == 0: return results rtree = data['data']['children'] for r in rtree: r = r['data'] # Internal reddit question/discussion if r['is_self']: continue thumb = None if r['thumbnail'] and r['thumbnail'].find('/') > -1: thumb = r['thumbnail'] subtitle = "Score: " + str(r['score']) comments = "<a target='_blank' href='http://reddit.com" + r['permalink'] + "'>Comments:" + str(r['num_comments']) + "</a>" subtitle = subtitle + ", " + comments title = chanutils.replace_entity(r['title']) url = chanutils.replace_entity(r['url']) subs = None if moviesubs: subs = chanutils.movie_title_year(title) item = playitem.PlayItem(title, thumb, url, subtitle, subs=subs) results.add(item) return results
gpl-2.0
[ 646, 15985, 1208, 12, 5232, 1053, 199, 199, 318, 2754, 8, 954, 18374, 12, 1894, 12, 1303, 14484, 30327, 29, 797, 304, 523, 1166, 275, 298, 1014, 921, 1544, 14, 18374, 14, 957, 15, 82, 6687, 435, 1007, 18374, 435, 3286, 1733, 14, 1001, 2, 523, 666, 275, 15985, 1208, 14, 362, 63, 1001, 8, 633, 12, 1862, 3713, 81, 356, 81, 12, 283, 22188, 63, 5474, 5242, 265, 3071, 523, 372, 485, 5005, 8, 576, 12, 1303, 14484, 30327, 9, 199, 199, 318, 664, 63, 3871, 8, 3871, 12, 1303, 14484, 30327, 29, 797, 304, 523, 666, 275, 15985, 1208, 14, 362, 63, 1001, 8, 3871, 459, 633, 1105, 523, 372, 485, 5005, 8, 576, 12, 1303, 14484, 30327, 9, 199, 199, 318, 485, 5005, 8, 576, 12, 1303, 14484, 30327, 304, 523, 2058, 275, 5232, 1053, 14, 9651, 2081, 1296, 342, 523, 340, 440, 283, 576, 7, 315, 666, 503, 822, 8, 576, 459, 576, 2545, 3223, 1105, 508, 378, 26, 272, 372, 2058, 523, 519, 2350, 275, 666, 459, 576, 2545, 3223, 418, 523, 367, 519, 315, 519, 2350, 26, 272, 519, 275, 519, 459, 576, 418, 272, 327, 12624, 8992, 1741, 7894, 15, 14410, 272, 340, 519, 459, 374, 63, 277, 2565, 489, 1980, 272, 21541, 275, 488, 272, 340, 519, 459, 8311, 418, 436, 519, 459, 8311, 2278, 1623, 7825, 690, 446, 17, 26, 489, 21541, 275, 519, 459, 8311, 418, 272, 18197, 275, 298, 12642, 26, 298, 435, 620, 8, 82, 459, 3397, 1105, 272, 6786, 275, 3886, 65, 1347, 17574, 2500, 7, 4369, 534, 1014, 921, 18374, 14, 957, 2, 435, 519, 459, 529, 2174, 2292, 418, 435, 3546, 30, 18929, 5424, 435, 620, 8, 82, 459, 1507, 63, 6223, 1105, 435, 15683, 65, 4335, 5591, 18197, 275, 18197, 435, 3872, 298, 435, 6786, 272, 2538, 275, 15985, 1208, 14, 1814, 63, 4502, 8, 82, 459, 1213, 1105, 272, 1166, 275, 15985, 1208, 14, 1814, 63, 4502, 8, 82, 459, 633, 1105, 272, 13868, 275, 488, 272, 340, 1303, 14484, 30327, 26, 489, 13868, 275, 15985, 1208, 14, 10888, 63, 1213, 63, 3403, 8, 1213, 9, 272, 1242, 275, 5232, 1053, 14, 9651, 2081, 8, 1213, 12, 21541, 12, 1166, 12, 18197, 12, 13868, 29, 9841, 9, 272, 2058, 14, 525, 8, 1053, 9, 523, 372, 2058, 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 ]
[ 15985, 1208, 12, 5232, 1053, 199, 199, 318, 2754, 8, 954, 18374, 12, 1894, 12, 1303, 14484, 30327, 29, 797, 304, 523, 1166, 275, 298, 1014, 921, 1544, 14, 18374, 14, 957, 15, 82, 6687, 435, 1007, 18374, 435, 3286, 1733, 14, 1001, 2, 523, 666, 275, 15985, 1208, 14, 362, 63, 1001, 8, 633, 12, 1862, 3713, 81, 356, 81, 12, 283, 22188, 63, 5474, 5242, 265, 3071, 523, 372, 485, 5005, 8, 576, 12, 1303, 14484, 30327, 9, 199, 199, 318, 664, 63, 3871, 8, 3871, 12, 1303, 14484, 30327, 29, 797, 304, 523, 666, 275, 15985, 1208, 14, 362, 63, 1001, 8, 3871, 459, 633, 1105, 523, 372, 485, 5005, 8, 576, 12, 1303, 14484, 30327, 9, 199, 199, 318, 485, 5005, 8, 576, 12, 1303, 14484, 30327, 304, 523, 2058, 275, 5232, 1053, 14, 9651, 2081, 1296, 342, 523, 340, 440, 283, 576, 7, 315, 666, 503, 822, 8, 576, 459, 576, 2545, 3223, 1105, 508, 378, 26, 272, 372, 2058, 523, 519, 2350, 275, 666, 459, 576, 2545, 3223, 418, 523, 367, 519, 315, 519, 2350, 26, 272, 519, 275, 519, 459, 576, 418, 272, 327, 12624, 8992, 1741, 7894, 15, 14410, 272, 340, 519, 459, 374, 63, 277, 2565, 489, 1980, 272, 21541, 275, 488, 272, 340, 519, 459, 8311, 418, 436, 519, 459, 8311, 2278, 1623, 7825, 690, 446, 17, 26, 489, 21541, 275, 519, 459, 8311, 418, 272, 18197, 275, 298, 12642, 26, 298, 435, 620, 8, 82, 459, 3397, 1105, 272, 6786, 275, 3886, 65, 1347, 17574, 2500, 7, 4369, 534, 1014, 921, 18374, 14, 957, 2, 435, 519, 459, 529, 2174, 2292, 418, 435, 3546, 30, 18929, 5424, 435, 620, 8, 82, 459, 1507, 63, 6223, 1105, 435, 15683, 65, 4335, 5591, 18197, 275, 18197, 435, 3872, 298, 435, 6786, 272, 2538, 275, 15985, 1208, 14, 1814, 63, 4502, 8, 82, 459, 1213, 1105, 272, 1166, 275, 15985, 1208, 14, 1814, 63, 4502, 8, 82, 459, 633, 1105, 272, 13868, 275, 488, 272, 340, 1303, 14484, 30327, 26, 489, 13868, 275, 15985, 1208, 14, 10888, 63, 1213, 63, 3403, 8, 1213, 9, 272, 1242, 275, 5232, 1053, 14, 9651, 2081, 8, 1213, 12, 21541, 12, 1166, 12, 18197, 12, 13868, 29, 9841, 9, 272, 2058, 14, 525, 8, 1053, 9, 523, 372, 2058, 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, 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,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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 ]
geminateCoder/Character-Archive-Website
Lib/site-packages/pycparser/__init__.py
41
2903
#----------------------------------------------------------------- # pycparser: __init__.py # # This package file exports some convenience functions for # interacting with pycparser # # Copyright (C) 2008-2015, Eli Bendersky # License: BSD #----------------------------------------------------------------- __all__ = ['c_lexer', 'c_parser', 'c_ast'] __version__ = '2.14' from subprocess import Popen, PIPE from .c_parser import CParser def preprocess_file(filename, cpp_path='cpp', cpp_args=''): """ Preprocess a file using cpp. filename: Name of the file you want to preprocess. cpp_path: cpp_args: Refer to the documentation of parse_file for the meaning of these arguments. When successful, returns the preprocessed file's contents. Errors from cpp will be printed out. """ path_list = [cpp_path] if isinstance(cpp_args, list): path_list += cpp_args elif cpp_args != '': path_list += [cpp_args] path_list += [filename] try: # Note the use of universal_newlines to treat all newlines # as \n for Python's purpose # pipe = Popen( path_list, stdout=PIPE, universal_newlines=True) text = pipe.communicate()[0] except OSError as e: raise RuntimeError("Unable to invoke 'cpp'. " + 'Make sure its path was passed correctly\n' + ('Original error: %s' % e)) return text def parse_file(filename, use_cpp=False, cpp_path='cpp', cpp_args='', parser=None): """ Parse a C file using pycparser. filename: Name of the file you want to parse. use_cpp: Set to True if you want to execute the C pre-processor on the file prior to parsing it. cpp_path: If use_cpp is True, this is the path to 'cpp' on your system. If no path is provided, it attempts to just execute 'cpp', so it must be in your PATH. cpp_args: If use_cpp is True, set this to the command line arguments strings to cpp. Be careful with quotes - it's best to pass a raw string (r'') here. For example: r'-I../utils/fake_libc_include' If several arguments are required, pass a list of strings. parser: Optional parser object to be used instead of the default CParser When successful, an AST is returned. ParseError can be thrown if the file doesn't parse successfully. Errors from cpp will be printed out. """ if use_cpp: text = preprocess_file(filename, cpp_path, cpp_args) else: with open(filename, 'rU') as f: text = f.read() if parser is None: parser = CParser() return parser.parse(text, filename)
cc0-1.0
[ 7656, 13, 199, 3, 28968, 2087, 26, 636, 826, 4343, 647, 199, 3, 199, 3, 961, 2559, 570, 22609, 2005, 16777, 3423, 367, 199, 3, 17232, 316, 543, 28968, 2087, 199, 3, 199, 3, 1898, 334, 35, 9, 9079, 13, 7806, 12, 662, 317, 699, 13747, 12267, 199, 3, 844, 26, 6289, 199, 7656, 13, 199, 363, 452, 363, 275, 788, 67, 63, 11729, 297, 283, 67, 63, 2087, 297, 283, 67, 63, 1810, 418, 199, 363, 1023, 363, 275, 283, 18, 14, 1079, 7, 199, 199, 504, 3873, 492, 13995, 12, 22773, 199, 504, 1275, 67, 63, 2087, 492, 445, 2842, 421, 199, 318, 23351, 63, 493, 8, 1501, 12, 7246, 63, 515, 534, 5910, 297, 7246, 63, 589, 9280, 272, 408, 5543, 1412, 282, 570, 1808, 7246, 14, 398, 1788, 26, 288, 2812, 402, 314, 570, 1265, 2934, 370, 23351, 14, 398, 7246, 63, 515, 26, 267, 7246, 63, 589, 26, 288, 21751, 370, 314, 3794, 402, 2198, 63, 493, 367, 314, 11150, 402, 3520, 288, 2368, 14, 398, 3979, 9512, 12, 2529, 314, 876, 7292, 570, 1159, 4072, 14, 267, 20456, 687, 7246, 911, 506, 12487, 734, 14, 272, 408, 272, 931, 63, 513, 275, 359, 5910, 63, 515, 61, 272, 340, 1228, 8, 5910, 63, 589, 12, 769, 304, 267, 931, 63, 513, 847, 7246, 63, 589, 272, 916, 7246, 63, 589, 1137, 8061, 267, 931, 63, 513, 847, 359, 5910, 63, 589, 61, 272, 931, 63, 513, 847, 359, 1501, 61, 339, 862, 26, 267, 327, 3390, 314, 675, 402, 17508, 63, 13839, 370, 14312, 1006, 14930, 267, 327, 465, 971, 78, 367, 2018, 1159, 12016, 267, 327, 267, 5200, 275, 13995, 8, 257, 931, 63, 513, 12, 717, 3839, 29, 6089, 12, 717, 17508, 63, 13839, 29, 549, 9, 267, 1318, 275, 5200, 14, 10664, 3430, 16, 61, 272, 871, 6440, 465, 325, 26, 267, 746, 6064, 480, 6005, 370, 12677, 283, 5910, 1370, 221, 298, 435, 288, 283, 5483, 3238, 2399, 931, 1990, 3032, 6657, 60, 78, 7, 435, 288, 661, 17286, 1125, 26, 450, 83, 7, 450, 325, 430, 339, 372, 1318, 421, 199, 318, 2198, 63, 493, 8, 1501, 12, 675, 63, 5910, 29, 797, 12, 7246, 63, 515, 534, 5910, 297, 7246, 63, 589, 4581, 2049, 1798, 29, 403, 304, 272, 408, 6077, 282, 445, 570, 1808, 28968, 2087, 14, 398, 1788, 26, 288, 2812, 402, 314, 570, 1265, 2934, 370, 2198, 14, 398, 675, 63, 5910, 26, 288, 2494, 370, 715, 340, 1265, 2934, 370, 5341, 314, 445, 876, 13, 6459, 288, 641, 314, 570, 6791, 370, 6057, 652, 14, 398, 7246, 63, 515, 26, 288, 982, 675, 63, 5910, 365, 715, 12, 642, 365, 314, 931, 370, 283, 5910, 7, 641, 2195, 288, 2656, 14, 982, 949, 931, 365, 2741, 12, 652, 12454, 370, 2951, 288, 5341, 283, 5910, 297, 880, 652, 1471, 506, 315, 2195, 15097, 14, 398, 7246, 63, 589, 26, 288, 982, 675, 63, 5910, 365, 715, 12, 663, 642, 370, 314, 1414, 1004, 2368, 3326, 288, 370, 7246, 14, 6423, 25082, 543, 9344, 446, 652, 1159, 5526, 370, 986, 282, 3066, 1059, 288, 334, 82, 17483, 2348, 14, 2104, 2893, 26, 288, 519, 12418, 41, 5093, 1208, 15, 3183, 63, 20217, 63, 2613, 7, 288, 982, 9978, 2368, 787, 1415, 12, 986, 282, 769, 402, 3326, 14, 398, 1798, 26, 288, 4879, 1798, 909, 370, 506, 1202, 3140, 402, 314, 849, 445, 2842, 398, 3979, 9512, 12, 376, 20788, 365, 2138, 14, 21743, 883, 506, 267, 14031, 340, 314, 570, 3181, 1133, 2198, 8792, 14, 398, 20456, 687, 7246, 911, 506, 12487, 734, 14, 272, 408, 272, 340, 675, 63, 5910, 26, 267, 1318, 275, 23351, 63, 493, 8, 1501, 12, 7246, 63, 515, 12, 7246, 63, 589, 9, 272, 587, 26, 267, 543, 1551, 8, 1501, 12, 283, 28978, 358, 465, 289, 26, 288, 1318, 275, 289, 14, 739, 342, 339, 340, 1798, 365, 488, 26, 267, 1798, 275, 445, 2842, 342, 272, 372, 1798, 14, 1122, 8, 505, 12, 1788, 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 ]
[ 13, 199, 3, 28968, 2087, 26, 636, 826, 4343, 647, 199, 3, 199, 3, 961, 2559, 570, 22609, 2005, 16777, 3423, 367, 199, 3, 17232, 316, 543, 28968, 2087, 199, 3, 199, 3, 1898, 334, 35, 9, 9079, 13, 7806, 12, 662, 317, 699, 13747, 12267, 199, 3, 844, 26, 6289, 199, 7656, 13, 199, 363, 452, 363, 275, 788, 67, 63, 11729, 297, 283, 67, 63, 2087, 297, 283, 67, 63, 1810, 418, 199, 363, 1023, 363, 275, 283, 18, 14, 1079, 7, 199, 199, 504, 3873, 492, 13995, 12, 22773, 199, 504, 1275, 67, 63, 2087, 492, 445, 2842, 421, 199, 318, 23351, 63, 493, 8, 1501, 12, 7246, 63, 515, 534, 5910, 297, 7246, 63, 589, 9280, 272, 408, 5543, 1412, 282, 570, 1808, 7246, 14, 398, 1788, 26, 288, 2812, 402, 314, 570, 1265, 2934, 370, 23351, 14, 398, 7246, 63, 515, 26, 267, 7246, 63, 589, 26, 288, 21751, 370, 314, 3794, 402, 2198, 63, 493, 367, 314, 11150, 402, 3520, 288, 2368, 14, 398, 3979, 9512, 12, 2529, 314, 876, 7292, 570, 1159, 4072, 14, 267, 20456, 687, 7246, 911, 506, 12487, 734, 14, 272, 408, 272, 931, 63, 513, 275, 359, 5910, 63, 515, 61, 272, 340, 1228, 8, 5910, 63, 589, 12, 769, 304, 267, 931, 63, 513, 847, 7246, 63, 589, 272, 916, 7246, 63, 589, 1137, 8061, 267, 931, 63, 513, 847, 359, 5910, 63, 589, 61, 272, 931, 63, 513, 847, 359, 1501, 61, 339, 862, 26, 267, 327, 3390, 314, 675, 402, 17508, 63, 13839, 370, 14312, 1006, 14930, 267, 327, 465, 971, 78, 367, 2018, 1159, 12016, 267, 327, 267, 5200, 275, 13995, 8, 257, 931, 63, 513, 12, 717, 3839, 29, 6089, 12, 717, 17508, 63, 13839, 29, 549, 9, 267, 1318, 275, 5200, 14, 10664, 3430, 16, 61, 272, 871, 6440, 465, 325, 26, 267, 746, 6064, 480, 6005, 370, 12677, 283, 5910, 1370, 221, 298, 435, 288, 283, 5483, 3238, 2399, 931, 1990, 3032, 6657, 60, 78, 7, 435, 288, 661, 17286, 1125, 26, 450, 83, 7, 450, 325, 430, 339, 372, 1318, 421, 199, 318, 2198, 63, 493, 8, 1501, 12, 675, 63, 5910, 29, 797, 12, 7246, 63, 515, 534, 5910, 297, 7246, 63, 589, 4581, 2049, 1798, 29, 403, 304, 272, 408, 6077, 282, 445, 570, 1808, 28968, 2087, 14, 398, 1788, 26, 288, 2812, 402, 314, 570, 1265, 2934, 370, 2198, 14, 398, 675, 63, 5910, 26, 288, 2494, 370, 715, 340, 1265, 2934, 370, 5341, 314, 445, 876, 13, 6459, 288, 641, 314, 570, 6791, 370, 6057, 652, 14, 398, 7246, 63, 515, 26, 288, 982, 675, 63, 5910, 365, 715, 12, 642, 365, 314, 931, 370, 283, 5910, 7, 641, 2195, 288, 2656, 14, 982, 949, 931, 365, 2741, 12, 652, 12454, 370, 2951, 288, 5341, 283, 5910, 297, 880, 652, 1471, 506, 315, 2195, 15097, 14, 398, 7246, 63, 589, 26, 288, 982, 675, 63, 5910, 365, 715, 12, 663, 642, 370, 314, 1414, 1004, 2368, 3326, 288, 370, 7246, 14, 6423, 25082, 543, 9344, 446, 652, 1159, 5526, 370, 986, 282, 3066, 1059, 288, 334, 82, 17483, 2348, 14, 2104, 2893, 26, 288, 519, 12418, 41, 5093, 1208, 15, 3183, 63, 20217, 63, 2613, 7, 288, 982, 9978, 2368, 787, 1415, 12, 986, 282, 769, 402, 3326, 14, 398, 1798, 26, 288, 4879, 1798, 909, 370, 506, 1202, 3140, 402, 314, 849, 445, 2842, 398, 3979, 9512, 12, 376, 20788, 365, 2138, 14, 21743, 883, 506, 267, 14031, 340, 314, 570, 3181, 1133, 2198, 8792, 14, 398, 20456, 687, 7246, 911, 506, 12487, 734, 14, 272, 408, 272, 340, 675, 63, 5910, 26, 267, 1318, 275, 23351, 63, 493, 8, 1501, 12, 7246, 63, 515, 12, 7246, 63, 589, 9, 272, 587, 26, 267, 543, 1551, 8, 1501, 12, 283, 28978, 358, 465, 289, 26, 288, 1318, 275, 289, 14, 739, 342, 339, 340, 1798, 365, 488, 26, 267, 1798, 275, 445, 2842, 342, 272, 372, 1798, 14, 1122, 8, 505, 12, 1788, 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, 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,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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 ]
ssato/sos-analyzer
sos_analyzer/cli.py
1
3519
# # Author: Satoru SATOH <ssato redhat.com> # License: GPLv3+ # import anyconfig import logging import optparse import os import os.path import sys from sos_analyzer.globals import DATA_SUBDIR import sos_analyzer.archive import sos_analyzer.runner import sos_analyzer.utils LOGGER = logging.getLogger(__name__) DEFAULTS = dict(loglevel=1, conf=None, workdir=None, analyze=True, report=False) USAGE = """%prog [Options...] SOS_REPORT_ARCHIVE_PATH Examples: %prog --workdir ./result /tmp/sosreport-host_abc_01-12345-67e056.tar.bz2""" def option_parser(defaults=DEFAULTS, usage=USAGE): p = optparse.OptionParser(usage) p.set_defaults(**defaults) p.add_option("-C", "--conf", help="Configuration file path or paths or its pattern " "such as '/a/b/*.json'") p.add_option("-w", "--workdir", help="Workding dir to save result. Computed and created " "automatically by default.") p.add_option("", "--no-analyze", action="store_false", help="Do not analyze (scanned) data") p.add_option("", "--report", action="store_true", help="Generate reports. It must not be specified w/ " "--no-analyze option") p.add_option("-s", "--silent", action="store_const", dest="loglevel", const=0, help="Silent or quiet mode") p.add_option("-q", "--quiet", action="store_const", dest="loglevel", const=0, help="Same as --silent option") p.add_option("-v", "--verbose", action="store_const", dest="loglevel", const=2, help="Verbose mode") return p def main(argv=sys.argv): p = option_parser() (options, args) = p.parse_args(argv[1:]) sos_analyzer.utils.set_loglevel(options.loglevel) if not args: p.print_usage() return -1 conf = anyconfig.load(options.conf) if options.conf else None if options.workdir: LOGGER.info("Try using working dir: %s", options.workdir) sos_analyzer.utils.setup_workdir(options.workdir) else: options.workdir = sos_analyzer.utils.setup_workdir() LOGGER.info("Created working dir: %s", options.workdir) tarfile = args[0] datadir = os.path.join(options.workdir, DATA_SUBDIR) if not os.path.exists(datadir): LOGGER.info("Create datadir: %s", datadir) os.makedirs(datadir) d = sos_analyzer.utils.find_dir_has_target(datadir, "sos_commands") if d: LOGGER.info("sosreport archive looks already extracted in %s", d) datadir = d else: LOGGER.info("Extract sosreport archive %s to %s", tarfile, datadir) sos_analyzer.archive.extract_archive(tarfile, datadir) d = sos_analyzer.utils.find_dir_has_target(datadir, "sos_commands") if d: LOGGER.info("Set datadir to %s", d) datadir = d else: LOGGER.error("No sosreport data found under %s", d) return -1 sos_analyzer.runner.run_scanners(options.workdir, datadir, conf) if options.analyze: sos_analyzer.runner.run_analyzers(options.workdir, datadir, conf) sos_analyzer.runner.dump_collected_results(options.workdir) if options.report: sos_analyzer.runner.run_report_generators(options.workdir, options.conf) return 0 if __name__ == '__main__': sys.exit(main(sys.argv)) # vim:sw=4:ts=4:et:
gpl-3.0
[ 3, 199, 3, 6529, 26, 428, 707, 85, 428, 619, 30454, 665, 385, 11318, 295, 7821, 292, 14, 957, 30, 199, 3, 844, 26, 14629, 86, 19, 11, 199, 3, 199, 646, 1263, 888, 199, 646, 2050, 199, 646, 8691, 199, 646, 747, 199, 646, 747, 14, 515, 199, 646, 984, 199, 199, 504, 308, 736, 63, 17965, 14, 8473, 492, 7126, 63, 6348, 3022, 199, 199, 646, 308, 736, 63, 17965, 14, 6404, 199, 646, 308, 736, 63, 17965, 14, 5933, 199, 646, 308, 736, 63, 17965, 14, 1208, 421, 199, 10186, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 30773, 275, 1211, 8, 26629, 29, 17, 12, 3743, 29, 403, 12, 1736, 694, 29, 403, 12, 19897, 29, 549, 12, 355, 3622, 29, 797, 9, 199, 199, 20274, 275, 408, 5, 6595, 359, 4558, 18737, 428, 3100, 63, 17356, 63, 28800, 63, 3243, 199, 199, 22787, 26, 523, 450, 6595, 1553, 19132, 16605, 1099, 1182, 2791, 15, 83, 736, 3070, 13, 1102, 63, 3175, 63, 614, 13, 13261, 13, 1822, 69, 25369, 14, 5369, 14, 10582, 18, 624, 421, 199, 318, 945, 63, 2087, 8, 4322, 29, 30773, 12, 4503, 29, 20274, 304, 272, 299, 275, 8691, 14, 14553, 8, 3807, 9, 272, 299, 14, 409, 63, 4322, 3682, 4322, 9, 339, 299, 14, 525, 63, 1422, 6096, 35, 401, 4320, 2190, 401, 326, 1720, 628, 5688, 570, 931, 503, 3792, 503, 2399, 3851, 298, 1993, 298, 10180, 465, 1994, 65, 15, 66, 20362, 1001, 9859, 272, 299, 14, 525, 63, 1422, 6096, 87, 401, 4320, 19132, 401, 326, 1720, 628, 6517, 1098, 2935, 370, 3354, 754, 14, 3599, 4241, 436, 2737, 298, 1993, 298, 2495, 17174, 701, 849, 2685, 272, 299, 14, 525, 63, 1422, 12398, 4320, 889, 13, 21184, 401, 1595, 628, 1617, 63, 3910, 401, 326, 1720, 628, 2585, 440, 19897, 334, 551, 9386, 9, 666, 531, 272, 299, 14, 525, 63, 1422, 12398, 4320, 3070, 401, 1595, 628, 1617, 63, 2052, 401, 326, 1720, 628, 6864, 13924, 14, 2779, 1471, 440, 506, 2013, 336, 15, 298, 1993, 4320, 889, 13, 21184, 945, 531, 339, 299, 14, 525, 63, 1422, 6096, 83, 401, 4320, 14434, 401, 1595, 628, 1617, 63, 1297, 401, 2053, 628, 26629, 401, 326, 950, 29, 16, 12, 1720, 628, 51, 441, 343, 503, 11971, 818, 531, 272, 299, 14, 525, 63, 1422, 6096, 81, 401, 4320, 10243, 401, 1595, 628, 1617, 63, 1297, 401, 2053, 628, 26629, 401, 326, 950, 29, 16, 12, 1720, 628, 8479, 465, 1553, 14434, 945, 531, 272, 299, 14, 525, 63, 1422, 6096, 86, 401, 4320, 3832, 401, 1595, 628, 1617, 63, 1297, 401, 2053, 628, 26629, 401, 326, 950, 29, 18, 12, 1720, 628, 21879, 818, 531, 339, 372, 299, 421, 199, 318, 2446, 8, 3020, 29, 1274, 14, 3020, 304, 272, 299, 275, 945, 63, 2087, 342, 272, 334, 1419, 12, 1249, 9, 275, 299, 14, 1122, 63, 589, 8, 3020, 59, 17, 5728, 339, 308, 736, 63, 17965, 14, 1208, 14, 409, 63, 26629, 8, 1419, 14, 26629, 9, 339, 340, 440, 1249, 26, 267, 299, 14, 1361, 63, 3807, 342, 267, 372, 446, 17, 339, 3743, 275, 1263, 888, 14, 912, 8, 1419, 14, 2190, 9, 340, 1511, 14, 2190, 587, 488, 339, 340, 1511, 14, 19132, 26, 267, 20184, 14, 815, 480, 12357, 1808, 6449, 2935, 26, 450, 83, 401, 1511, 14, 19132, 9, 267, 308, 736, 63, 17965, 14, 1208, 14, 2758, 63, 19132, 8, 1419, 14, 19132, 9, 272, 587, 26, 267, 1511, 14, 19132, 275, 308, 736, 63, 17965, 14, 1208, 14, 2758, 63, 19132, 342, 267, 20184, 14, 815, 480, 10502, 6449, 2935, 26, 450, 83, 401, 1511, 14, 19132, 9, 339, 13608, 275, 1249, 59, 16, 61, 272, 666, 694, 275, 747, 14, 515, 14, 904, 8, 1419, 14, 19132, 12, 7126, 63, 6348, 3022, 9, 339, 340, 440, 747, 14, 515, 14, 2444, 8, 18259, 304, 267, 20184, 14, 815, 480, 2499, 666, 694, 26, 450, 83, 401, 666, 694, 9, 267, 747, 14, 8347, 8, 18259, 9, 339, 366, 275, 308, 736, 63, 17965, 14, 1208, 14, 1623, 63, 694, 63, 1989, 63, 1375, 8, 18259, 12, 298, 83, 736, 63, 4405, 531, 272, 340, 366, 26, 267, 20184, 14, 815, 480, 83, 736, 3070, 6359, 10734, 2575, 12509, 315, 450, 83, 401, 366, 9, 267, 666, 694, 275, 366, 272, 587, 26, 267, 20184, 14, 815, 480, 12147, 308, 736, 3070, 6359, 450, 83, 370, 450, 83, 401, 13608, 12, 666, 694, 9, 267, 308, 736, 63, 17965, 14, 6404, 14, 5005, 63, 6404, 8, 19862, 12, 666, 694, 9, 398, 366, 275, 308, 736, 63, 17965, 14, 1208, 14, 1623, 63, 694, 63, 1989, 63, 1375, 8, 18259, 12, 298, 83, 736, 63, 4405, 531, 267, 340, 366, 26, 288, 20184, 14, 815, 480, 1084, 666, 694, 370, 450, 83, 401, 366, 9, 288, 666, 694, 275, 366, 267, 587, 26, 288, 20184, 14, 705, 480, 1944, 308, 736, 3070, 666, 1911, 1334, 450, 83, 401, 366, 9, 288, 372, 446, 17, 339, 308, 736, 63, 17965, 14, 5933, 14, 1065, 63, 551, 27297, 8, 1419, 14, 19132, 12, 666, 694, 12, 3743, 9, 339, 340, 1511, 14, 21184, 26, 267, 308, 736, 63, 17965, 14, 5933, 14, 1065, 63, 4797, 90, 1192, 8, 1419, 14, 19132, 12, 666, 694, 12, 3743, 9, 267, 308, 736, 63, 17965, 14, 5933, 14, 2724, 63, 22766, 63, 2604, 8, 1419, 14, 19132, 9, 398, 340, 1511, 14, 3070, 26, 288, 308, 736, 63, 17965, 14, 5933, 14, 1065, 63, 3070, 63, 20748, 8, 1419, 14, 19132, 12, 10028, 1511, 14, 2190, 9, 339, 372, 378, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 984, 14, 2224, 8, 973, 8, 1274, 14, 3020, 430, 199, 199, 3, 6695, 26, 3519, 29, 20, 26, 1086, 29, 20, 26, 386, 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 ]
[ 199, 3, 6529, 26, 428, 707, 85, 428, 619, 30454, 665, 385, 11318, 295, 7821, 292, 14, 957, 30, 199, 3, 844, 26, 14629, 86, 19, 11, 199, 3, 199, 646, 1263, 888, 199, 646, 2050, 199, 646, 8691, 199, 646, 747, 199, 646, 747, 14, 515, 199, 646, 984, 199, 199, 504, 308, 736, 63, 17965, 14, 8473, 492, 7126, 63, 6348, 3022, 199, 199, 646, 308, 736, 63, 17965, 14, 6404, 199, 646, 308, 736, 63, 17965, 14, 5933, 199, 646, 308, 736, 63, 17965, 14, 1208, 421, 199, 10186, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 30773, 275, 1211, 8, 26629, 29, 17, 12, 3743, 29, 403, 12, 1736, 694, 29, 403, 12, 19897, 29, 549, 12, 355, 3622, 29, 797, 9, 199, 199, 20274, 275, 408, 5, 6595, 359, 4558, 18737, 428, 3100, 63, 17356, 63, 28800, 63, 3243, 199, 199, 22787, 26, 523, 450, 6595, 1553, 19132, 16605, 1099, 1182, 2791, 15, 83, 736, 3070, 13, 1102, 63, 3175, 63, 614, 13, 13261, 13, 1822, 69, 25369, 14, 5369, 14, 10582, 18, 624, 421, 199, 318, 945, 63, 2087, 8, 4322, 29, 30773, 12, 4503, 29, 20274, 304, 272, 299, 275, 8691, 14, 14553, 8, 3807, 9, 272, 299, 14, 409, 63, 4322, 3682, 4322, 9, 339, 299, 14, 525, 63, 1422, 6096, 35, 401, 4320, 2190, 401, 326, 1720, 628, 5688, 570, 931, 503, 3792, 503, 2399, 3851, 298, 1993, 298, 10180, 465, 1994, 65, 15, 66, 20362, 1001, 9859, 272, 299, 14, 525, 63, 1422, 6096, 87, 401, 4320, 19132, 401, 326, 1720, 628, 6517, 1098, 2935, 370, 3354, 754, 14, 3599, 4241, 436, 2737, 298, 1993, 298, 2495, 17174, 701, 849, 2685, 272, 299, 14, 525, 63, 1422, 12398, 4320, 889, 13, 21184, 401, 1595, 628, 1617, 63, 3910, 401, 326, 1720, 628, 2585, 440, 19897, 334, 551, 9386, 9, 666, 531, 272, 299, 14, 525, 63, 1422, 12398, 4320, 3070, 401, 1595, 628, 1617, 63, 2052, 401, 326, 1720, 628, 6864, 13924, 14, 2779, 1471, 440, 506, 2013, 336, 15, 298, 1993, 4320, 889, 13, 21184, 945, 531, 339, 299, 14, 525, 63, 1422, 6096, 83, 401, 4320, 14434, 401, 1595, 628, 1617, 63, 1297, 401, 2053, 628, 26629, 401, 326, 950, 29, 16, 12, 1720, 628, 51, 441, 343, 503, 11971, 818, 531, 272, 299, 14, 525, 63, 1422, 6096, 81, 401, 4320, 10243, 401, 1595, 628, 1617, 63, 1297, 401, 2053, 628, 26629, 401, 326, 950, 29, 16, 12, 1720, 628, 8479, 465, 1553, 14434, 945, 531, 272, 299, 14, 525, 63, 1422, 6096, 86, 401, 4320, 3832, 401, 1595, 628, 1617, 63, 1297, 401, 2053, 628, 26629, 401, 326, 950, 29, 18, 12, 1720, 628, 21879, 818, 531, 339, 372, 299, 421, 199, 318, 2446, 8, 3020, 29, 1274, 14, 3020, 304, 272, 299, 275, 945, 63, 2087, 342, 272, 334, 1419, 12, 1249, 9, 275, 299, 14, 1122, 63, 589, 8, 3020, 59, 17, 5728, 339, 308, 736, 63, 17965, 14, 1208, 14, 409, 63, 26629, 8, 1419, 14, 26629, 9, 339, 340, 440, 1249, 26, 267, 299, 14, 1361, 63, 3807, 342, 267, 372, 446, 17, 339, 3743, 275, 1263, 888, 14, 912, 8, 1419, 14, 2190, 9, 340, 1511, 14, 2190, 587, 488, 339, 340, 1511, 14, 19132, 26, 267, 20184, 14, 815, 480, 12357, 1808, 6449, 2935, 26, 450, 83, 401, 1511, 14, 19132, 9, 267, 308, 736, 63, 17965, 14, 1208, 14, 2758, 63, 19132, 8, 1419, 14, 19132, 9, 272, 587, 26, 267, 1511, 14, 19132, 275, 308, 736, 63, 17965, 14, 1208, 14, 2758, 63, 19132, 342, 267, 20184, 14, 815, 480, 10502, 6449, 2935, 26, 450, 83, 401, 1511, 14, 19132, 9, 339, 13608, 275, 1249, 59, 16, 61, 272, 666, 694, 275, 747, 14, 515, 14, 904, 8, 1419, 14, 19132, 12, 7126, 63, 6348, 3022, 9, 339, 340, 440, 747, 14, 515, 14, 2444, 8, 18259, 304, 267, 20184, 14, 815, 480, 2499, 666, 694, 26, 450, 83, 401, 666, 694, 9, 267, 747, 14, 8347, 8, 18259, 9, 339, 366, 275, 308, 736, 63, 17965, 14, 1208, 14, 1623, 63, 694, 63, 1989, 63, 1375, 8, 18259, 12, 298, 83, 736, 63, 4405, 531, 272, 340, 366, 26, 267, 20184, 14, 815, 480, 83, 736, 3070, 6359, 10734, 2575, 12509, 315, 450, 83, 401, 366, 9, 267, 666, 694, 275, 366, 272, 587, 26, 267, 20184, 14, 815, 480, 12147, 308, 736, 3070, 6359, 450, 83, 370, 450, 83, 401, 13608, 12, 666, 694, 9, 267, 308, 736, 63, 17965, 14, 6404, 14, 5005, 63, 6404, 8, 19862, 12, 666, 694, 9, 398, 366, 275, 308, 736, 63, 17965, 14, 1208, 14, 1623, 63, 694, 63, 1989, 63, 1375, 8, 18259, 12, 298, 83, 736, 63, 4405, 531, 267, 340, 366, 26, 288, 20184, 14, 815, 480, 1084, 666, 694, 370, 450, 83, 401, 366, 9, 288, 666, 694, 275, 366, 267, 587, 26, 288, 20184, 14, 705, 480, 1944, 308, 736, 3070, 666, 1911, 1334, 450, 83, 401, 366, 9, 288, 372, 446, 17, 339, 308, 736, 63, 17965, 14, 5933, 14, 1065, 63, 551, 27297, 8, 1419, 14, 19132, 12, 666, 694, 12, 3743, 9, 339, 340, 1511, 14, 21184, 26, 267, 308, 736, 63, 17965, 14, 5933, 14, 1065, 63, 4797, 90, 1192, 8, 1419, 14, 19132, 12, 666, 694, 12, 3743, 9, 267, 308, 736, 63, 17965, 14, 5933, 14, 2724, 63, 22766, 63, 2604, 8, 1419, 14, 19132, 9, 398, 340, 1511, 14, 3070, 26, 288, 308, 736, 63, 17965, 14, 5933, 14, 1065, 63, 3070, 63, 20748, 8, 1419, 14, 19132, 12, 10028, 1511, 14, 2190, 9, 339, 372, 378, 199, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 984, 14, 2224, 8, 973, 8, 1274, 14, 3020, 430, 199, 199, 3, 6695, 26, 3519, 29, 20, 26, 1086, 29, 20, 26, 386, 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, 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,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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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
vegetableman/phantomjs
src/qt/qtwebkit/Tools/Scripts/webkitpy/common/system/filesystem_mock.py
122
16269
# Copyright (C) 2009 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 StringIO import errno import hashlib import os import re from webkitpy.common.system import path class MockFileSystem(object): sep = '/' pardir = '..' def __init__(self, files=None, dirs=None, cwd='/'): """Initializes a "mock" filesystem that can be used to completely stub out a filesystem. Args: files: a dict of filenames -> file contents. A file contents value of None is used to indicate that the file should not exist. """ self.files = files or {} self.written_files = {} self.last_tmpdir = None self.current_tmpno = 0 self.cwd = cwd self.dirs = set(dirs or []) self.dirs.add(cwd) for f in self.files: d = self.dirname(f) while not d in self.dirs: self.dirs.add(d) d = self.dirname(d) def clear_written_files(self): # This function can be used to track what is written between steps in a test. self.written_files = {} def _raise_not_found(self, path): raise IOError(errno.ENOENT, path, os.strerror(errno.ENOENT)) def _split(self, path): # This is not quite a full implementation of os.path.split # http://docs.python.org/library/os.path.html#os.path.split if self.sep in path: return path.rsplit(self.sep, 1) return ('', path) def abspath(self, path): if os.path.isabs(path): return self.normpath(path) return self.abspath(self.join(self.cwd, path)) def realpath(self, path): return self.abspath(path) def basename(self, path): return self._split(path)[1] def expanduser(self, path): if path[0] != "~": return path parts = path.split(self.sep, 1) home_directory = self.sep + "Users" + self.sep + "mock" if len(parts) == 1: return home_directory return home_directory + self.sep + parts[1] def path_to_module(self, module_name): return "/mock-checkout/Tools/Scripts/" + module_name.replace('.', '/') + ".py" def chdir(self, path): path = self.normpath(path) if not self.isdir(path): raise OSError(errno.ENOENT, path, os.strerror(errno.ENOENT)) self.cwd = path def copyfile(self, source, destination): if not self.exists(source): self._raise_not_found(source) if self.isdir(source): raise IOError(errno.EISDIR, source, os.strerror(errno.EISDIR)) if self.isdir(destination): raise IOError(errno.EISDIR, destination, os.strerror(errno.EISDIR)) if not self.exists(self.dirname(destination)): raise IOError(errno.ENOENT, destination, os.strerror(errno.ENOENT)) self.files[destination] = self.files[source] self.written_files[destination] = self.files[source] def dirname(self, path): return self._split(path)[0] def exists(self, path): return self.isfile(path) or self.isdir(path) def files_under(self, path, dirs_to_skip=[], file_filter=None): def filter_all(fs, dirpath, basename): return True file_filter = file_filter or filter_all files = [] if self.isfile(path): if file_filter(self, self.dirname(path), self.basename(path)) and self.files[path] is not None: files.append(path) return files if self.basename(path) in dirs_to_skip: return [] if not path.endswith(self.sep): path += self.sep dir_substrings = [self.sep + d + self.sep for d in dirs_to_skip] for filename in self.files: if not filename.startswith(path): continue suffix = filename[len(path) - 1:] if any(dir_substring in suffix for dir_substring in dir_substrings): continue dirpath, basename = self._split(filename) if file_filter(self, dirpath, basename) and self.files[filename] is not None: files.append(filename) return files def getcwd(self): return self.cwd def glob(self, glob_string): # FIXME: This handles '*', but not '?', '[', or ']'. glob_string = re.escape(glob_string) glob_string = glob_string.replace('\\*', '[^\\/]*') + '$' glob_string = glob_string.replace('\\/', '/') path_filter = lambda path: re.match(glob_string, path) # We could use fnmatch.fnmatch, but that might not do the right thing on windows. existing_files = [path for path, contents in self.files.items() if contents is not None] return filter(path_filter, existing_files) + filter(path_filter, self.dirs) def isabs(self, path): return path.startswith(self.sep) def isfile(self, path): return path in self.files and self.files[path] is not None def isdir(self, path): return self.normpath(path) in self.dirs def _slow_but_correct_join(self, *comps): return re.sub(re.escape(os.path.sep), self.sep, os.path.join(*comps)) def join(self, *comps): # This function is called a lot, so we optimize it; there are # unittests to check that we match _slow_but_correct_join(), above. path = '' sep = self.sep for comp in comps: if not comp: continue if comp[0] == sep: path = comp continue if path: path += sep path += comp if comps[-1] == '' and path: path += '/' path = path.replace(sep + sep, sep) return path def listdir(self, path): sep = self.sep if not self.isdir(path): raise OSError("%s is not a directory" % path) if not path.endswith(sep): path += sep dirs = [] files = [] for f in self.files: if self.exists(f) and f.startswith(path): remaining = f[len(path):] if sep in remaining: dir = remaining[:remaining.index(sep)] if not dir in dirs: dirs.append(dir) else: files.append(remaining) return dirs + files def mtime(self, path): if self.exists(path): return 0 self._raise_not_found(path) def _mktemp(self, suffix='', prefix='tmp', dir=None, **kwargs): if dir is None: dir = self.sep + '__im_tmp' curno = self.current_tmpno self.current_tmpno += 1 self.last_tmpdir = self.join(dir, '%s_%u_%s' % (prefix, curno, suffix)) return self.last_tmpdir def mkdtemp(self, **kwargs): class TemporaryDirectory(object): def __init__(self, fs, **kwargs): self._kwargs = kwargs self._filesystem = fs self._directory_path = fs._mktemp(**kwargs) fs.maybe_make_directory(self._directory_path) def __str__(self): return self._directory_path def __enter__(self): return self._directory_path def __exit__(self, type, value, traceback): # Only self-delete if necessary. # FIXME: Should we delete non-empty directories? if self._filesystem.exists(self._directory_path): self._filesystem.rmtree(self._directory_path) return TemporaryDirectory(fs=self, **kwargs) def maybe_make_directory(self, *path): norm_path = self.normpath(self.join(*path)) while norm_path and not self.isdir(norm_path): self.dirs.add(norm_path) norm_path = self.dirname(norm_path) def move(self, source, destination): if self.files[source] is None: self._raise_not_found(source) self.files[destination] = self.files[source] self.written_files[destination] = self.files[destination] self.files[source] = None self.written_files[source] = None def _slow_but_correct_normpath(self, path): return re.sub(re.escape(os.path.sep), self.sep, os.path.normpath(path)) def normpath(self, path): # This function is called a lot, so we try to optimize the common cases # instead of always calling _slow_but_correct_normpath(), above. if '..' in path or '/./' in path: # This doesn't happen very often; don't bother trying to optimize it. return self._slow_but_correct_normpath(path) if not path: return '.' if path == '/': return path if path == '/.': return '/' if path.endswith('/.'): return path[:-2] if path.endswith('/'): return path[:-1] return path def open_binary_tempfile(self, suffix=''): path = self._mktemp(suffix) return (WritableBinaryFileObject(self, path), path) def open_binary_file_for_reading(self, path): if self.files[path] is None: self._raise_not_found(path) return ReadableBinaryFileObject(self, path, self.files[path]) def read_binary_file(self, path): # Intentionally raises KeyError if we don't recognize the path. if self.files[path] is None: self._raise_not_found(path) return self.files[path] def write_binary_file(self, path, contents): # FIXME: should this assert if dirname(path) doesn't exist? self.maybe_make_directory(self.dirname(path)) self.files[path] = contents self.written_files[path] = contents def open_text_file_for_reading(self, path): if self.files[path] is None: self._raise_not_found(path) return ReadableTextFileObject(self, path, self.files[path]) def open_text_file_for_writing(self, path): return WritableTextFileObject(self, path) def read_text_file(self, path): return self.read_binary_file(path).decode('utf-8') def write_text_file(self, path, contents): return self.write_binary_file(path, contents.encode('utf-8')) def sha1(self, path): contents = self.read_binary_file(path) return hashlib.sha1(contents).hexdigest() def relpath(self, path, start='.'): # Since os.path.relpath() calls os.path.normpath() # (see http://docs.python.org/library/os.path.html#os.path.abspath ) # it also removes trailing slashes and converts forward and backward # slashes to the preferred slash os.sep. start = self.abspath(start) path = self.abspath(path) if not path.lower().startswith(start.lower()): # path is outside the directory given by start; compute path from root return '../' * start.count('/') + path rel_path = path[len(start):] if not rel_path: # Then the paths are the same. pass elif rel_path[0] == self.sep: # It is probably sufficient to remove just the first character # since os.path.normpath() collapses separators, but we use # lstrip() just to be sure. rel_path = rel_path.lstrip(self.sep) else: # We are in the case typified by the following example: # path = "/tmp/foobar", start = "/tmp/foo" -> rel_path = "bar" # FIXME: We return a less-than-optimal result here. return '../' * start.count('/') + path return rel_path def remove(self, path): if self.files[path] is None: self._raise_not_found(path) self.files[path] = None self.written_files[path] = None def rmtree(self, path): path = self.normpath(path) for f in self.files: if f.startswith(path): self.files[f] = None self.dirs = set(filter(lambda d: not d.startswith(path), self.dirs)) def copytree(self, source, destination): source = self.normpath(source) destination = self.normpath(destination) for source_file in self.files: if source_file.startswith(source): destination_path = self.join(destination, self.relpath(source_file, source)) self.maybe_make_directory(self.dirname(destination_path)) self.files[destination_path] = self.files[source_file] def split(self, path): idx = path.rfind(self.sep) if idx == -1: return ('', path) return (path[:idx], path[(idx + 1):]) def splitext(self, path): idx = path.rfind('.') if idx == -1: idx = len(path) return (path[0:idx], path[idx:]) class WritableBinaryFileObject(object): def __init__(self, fs, path): self.fs = fs self.path = path self.closed = False self.fs.files[path] = "" def __enter__(self): return self def __exit__(self, type, value, traceback): self.close() def close(self): self.closed = True def write(self, str): self.fs.files[self.path] += str self.fs.written_files[self.path] = self.fs.files[self.path] class WritableTextFileObject(WritableBinaryFileObject): def write(self, str): WritableBinaryFileObject.write(self, str.encode('utf-8')) class ReadableBinaryFileObject(object): def __init__(self, fs, path, data): self.fs = fs self.path = path self.closed = False self.data = data self.offset = 0 def __enter__(self): return self def __exit__(self, type, value, traceback): self.close() def close(self): self.closed = True def read(self, bytes=None): if not bytes: return self.data[self.offset:] start = self.offset self.offset += bytes return self.data[start:self.offset] class ReadableTextFileObject(ReadableBinaryFileObject): def __init__(self, fs, path, data): super(ReadableTextFileObject, self).__init__(fs, path, StringIO.StringIO(data.decode("utf-8"))) def close(self): self.data.close() super(ReadableTextFileObject, self).close() def read(self, bytes=-1): return self.data.read(bytes) def readline(self, length=None): return self.data.readline(length) def __iter__(self): return self.data.__iter__() def next(self): return self.data.next() def seek(self, offset, whence=os.SEEK_SET): self.data.seek(offset, whence)
bsd-3-clause
[ 3, 1898, 334, 35, 9, 8937, 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, 259, 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, 259, 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, 259, 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, 5228, 199, 646, 7554, 199, 646, 8337, 199, 646, 747, 199, 646, 295, 199, 199, 504, 18007, 14, 2330, 14, 2253, 492, 931, 421, 199, 533, 4420, 17521, 8, 785, 304, 272, 7375, 275, 7324, 272, 623, 694, 275, 11541, 7, 339, 347, 636, 826, 721, 277, 12, 1584, 29, 403, 12, 7606, 29, 403, 12, 8288, 8805, 735, 267, 408, 23489, 282, 298, 1805, 2, 10036, 626, 883, 506, 1202, 370, 14793, 267, 10098, 734, 282, 10036, 14, 398, 3033, 26, 288, 1584, 26, 282, 1211, 402, 6203, 1035, 570, 4072, 14, 437, 570, 4072, 355, 574, 402, 488, 365, 1202, 370, 6623, 626, 314, 570, 1077, 355, 440, 2187, 14, 267, 408, 267, 291, 14, 1725, 275, 1584, 503, 1052, 267, 291, 14, 8938, 63, 1725, 275, 1052, 267, 291, 14, 2019, 63, 8616, 275, 488, 267, 291, 14, 1818, 63, 2791, 889, 275, 378, 267, 291, 14, 6525, 275, 8288, 267, 291, 14, 3220, 275, 663, 8, 3220, 503, 3073, 267, 291, 14, 3220, 14, 525, 8, 6525, 9, 267, 367, 289, 315, 291, 14, 1725, 26, 288, 366, 275, 291, 14, 3475, 8, 70, 9, 288, 1830, 440, 366, 315, 291, 14, 3220, 26, 355, 291, 14, 3220, 14, 525, 8, 68, 9, 355, 366, 275, 291, 14, 3475, 8, 68, 9, 339, 347, 5436, 63, 8938, 63, 1725, 8, 277, 304, 267, 327, 961, 805, 883, 506, 1202, 370, 4426, 4052, 365, 5313, 3382, 7124, 315, 282, 511, 14, 267, 291, 14, 8938, 63, 1725, 275, 1052, 339, 347, 485, 3730, 63, 1397, 63, 4214, 8, 277, 12, 931, 304, 267, 746, 5925, 8, 7931, 14, 20465, 12, 931, 12, 747, 14, 20395, 8, 7931, 14, 20465, 430, 339, 347, 485, 1294, 8, 277, 12, 931, 304, 267, 327, 961, 365, 440, 18794, 282, 2615, 4514, 402, 747, 14, 515, 14, 1294, 267, 327, 1455, 921, 4757, 14, 1548, 14, 1308, 15, 4342, 15, 736, 14, 515, 14, 1360, 3, 736, 14, 515, 14, 1294, 267, 340, 291, 14, 4127, 315, 931, 26, 288, 372, 931, 14, 13490, 8, 277, 14, 4127, 12, 413, 9, 267, 372, 13134, 931, 9, 339, 347, 19529, 8, 277, 12, 931, 304, 267, 340, 747, 14, 515, 14, 17896, 8, 515, 304, 288, 372, 291, 14, 9267, 8, 515, 9, 267, 372, 291, 14, 4832, 8, 277, 14, 904, 8, 277, 14, 6525, 12, 931, 430, 339, 347, 3363, 515, 8, 277, 12, 931, 304, 267, 372, 291, 14, 4832, 8, 515, 9, 339, 347, 9593, 8, 277, 12, 931, 304, 267, 372, 291, 423, 1294, 8, 515, 2788, 17, 61, 339, 347, 6544, 751, 8, 277, 12, 931, 304, 267, 340, 931, 59, 16, 61, 1137, 26810, 582, 288, 372, 931, 267, 4184, 275, 931, 14, 1294, 8, 277, 14, 4127, 12, 413, 9, 267, 5629, 63, 3619, 275, 291, 14, 4127, 435, 298, 12117, 2, 435, 291, 14, 4127, 435, 298, 1805, 2, 267, 340, 822, 8, 4181, 9, 508, 413, 26, 288, 372, 5629, 63, 3619, 267, 372, 5629, 63, 3619, 435, 291, 14, 4127, 435, 4184, 59, 17, 61, 339, 347, 931, 63, 475, 63, 578, 8, 277, 12, 859, 63, 354, 304, 267, 372, 3286, 1805, 13, 12891, 15, 11654, 15, 25681, 6687, 435, 859, 63, 354, 14, 1814, 14078, 15107, 435, 3680, 647, 2, 339, 347, 13097, 8, 277, 12, 931, 304, 267, 931, 275, 291, 14, 9267, 8, 515, 9, 267, 340, 440, 291, 14, 6027, 8, 515, 304, 288, 746, 6440, 8, 7931, 14, 20465, 12, 931, 12, 747, 14, 20395, 8, 7931, 14, 20465, 430, 267, 291, 14, 6525, 275, 931, 339, 347, 1331, 493, 8, 277, 12, 1350, 12, 5724, 304, 267, 340, 440, 291, 14, 2444, 8, 1365, 304, 288, 291, 423, 3730, 63, 1397, 63, 4214, 8, 1365, 9, 267, 340, 291, 14, 6027, 8, 1365, 304, 288, 746, 5925, 8, 7931, 14, 37, 1311, 3022, 12, 1350, 12, 747, 14, 20395, 8, 7931, 14, 37, 1311, 3022, 430, 267, 340, 291, 14, 6027, 8, 6881, 304, 288, 746, 5925, 8, 7931, 14, 37, 1311, 3022, 12, 5724, 12, 747, 14, 20395, 8, 7931, 14, 37, 1311, 3022, 430, 267, 340, 440, 291, 14, 2444, 8, 277, 14 ]
[ 1898, 334, 35, 9, 8937, 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, 259, 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, 259, 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, 259, 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, 5228, 199, 646, 7554, 199, 646, 8337, 199, 646, 747, 199, 646, 295, 199, 199, 504, 18007, 14, 2330, 14, 2253, 492, 931, 421, 199, 533, 4420, 17521, 8, 785, 304, 272, 7375, 275, 7324, 272, 623, 694, 275, 11541, 7, 339, 347, 636, 826, 721, 277, 12, 1584, 29, 403, 12, 7606, 29, 403, 12, 8288, 8805, 735, 267, 408, 23489, 282, 298, 1805, 2, 10036, 626, 883, 506, 1202, 370, 14793, 267, 10098, 734, 282, 10036, 14, 398, 3033, 26, 288, 1584, 26, 282, 1211, 402, 6203, 1035, 570, 4072, 14, 437, 570, 4072, 355, 574, 402, 488, 365, 1202, 370, 6623, 626, 314, 570, 1077, 355, 440, 2187, 14, 267, 408, 267, 291, 14, 1725, 275, 1584, 503, 1052, 267, 291, 14, 8938, 63, 1725, 275, 1052, 267, 291, 14, 2019, 63, 8616, 275, 488, 267, 291, 14, 1818, 63, 2791, 889, 275, 378, 267, 291, 14, 6525, 275, 8288, 267, 291, 14, 3220, 275, 663, 8, 3220, 503, 3073, 267, 291, 14, 3220, 14, 525, 8, 6525, 9, 267, 367, 289, 315, 291, 14, 1725, 26, 288, 366, 275, 291, 14, 3475, 8, 70, 9, 288, 1830, 440, 366, 315, 291, 14, 3220, 26, 355, 291, 14, 3220, 14, 525, 8, 68, 9, 355, 366, 275, 291, 14, 3475, 8, 68, 9, 339, 347, 5436, 63, 8938, 63, 1725, 8, 277, 304, 267, 327, 961, 805, 883, 506, 1202, 370, 4426, 4052, 365, 5313, 3382, 7124, 315, 282, 511, 14, 267, 291, 14, 8938, 63, 1725, 275, 1052, 339, 347, 485, 3730, 63, 1397, 63, 4214, 8, 277, 12, 931, 304, 267, 746, 5925, 8, 7931, 14, 20465, 12, 931, 12, 747, 14, 20395, 8, 7931, 14, 20465, 430, 339, 347, 485, 1294, 8, 277, 12, 931, 304, 267, 327, 961, 365, 440, 18794, 282, 2615, 4514, 402, 747, 14, 515, 14, 1294, 267, 327, 1455, 921, 4757, 14, 1548, 14, 1308, 15, 4342, 15, 736, 14, 515, 14, 1360, 3, 736, 14, 515, 14, 1294, 267, 340, 291, 14, 4127, 315, 931, 26, 288, 372, 931, 14, 13490, 8, 277, 14, 4127, 12, 413, 9, 267, 372, 13134, 931, 9, 339, 347, 19529, 8, 277, 12, 931, 304, 267, 340, 747, 14, 515, 14, 17896, 8, 515, 304, 288, 372, 291, 14, 9267, 8, 515, 9, 267, 372, 291, 14, 4832, 8, 277, 14, 904, 8, 277, 14, 6525, 12, 931, 430, 339, 347, 3363, 515, 8, 277, 12, 931, 304, 267, 372, 291, 14, 4832, 8, 515, 9, 339, 347, 9593, 8, 277, 12, 931, 304, 267, 372, 291, 423, 1294, 8, 515, 2788, 17, 61, 339, 347, 6544, 751, 8, 277, 12, 931, 304, 267, 340, 931, 59, 16, 61, 1137, 26810, 582, 288, 372, 931, 267, 4184, 275, 931, 14, 1294, 8, 277, 14, 4127, 12, 413, 9, 267, 5629, 63, 3619, 275, 291, 14, 4127, 435, 298, 12117, 2, 435, 291, 14, 4127, 435, 298, 1805, 2, 267, 340, 822, 8, 4181, 9, 508, 413, 26, 288, 372, 5629, 63, 3619, 267, 372, 5629, 63, 3619, 435, 291, 14, 4127, 435, 4184, 59, 17, 61, 339, 347, 931, 63, 475, 63, 578, 8, 277, 12, 859, 63, 354, 304, 267, 372, 3286, 1805, 13, 12891, 15, 11654, 15, 25681, 6687, 435, 859, 63, 354, 14, 1814, 14078, 15107, 435, 3680, 647, 2, 339, 347, 13097, 8, 277, 12, 931, 304, 267, 931, 275, 291, 14, 9267, 8, 515, 9, 267, 340, 440, 291, 14, 6027, 8, 515, 304, 288, 746, 6440, 8, 7931, 14, 20465, 12, 931, 12, 747, 14, 20395, 8, 7931, 14, 20465, 430, 267, 291, 14, 6525, 275, 931, 339, 347, 1331, 493, 8, 277, 12, 1350, 12, 5724, 304, 267, 340, 440, 291, 14, 2444, 8, 1365, 304, 288, 291, 423, 3730, 63, 1397, 63, 4214, 8, 1365, 9, 267, 340, 291, 14, 6027, 8, 1365, 304, 288, 746, 5925, 8, 7931, 14, 37, 1311, 3022, 12, 1350, 12, 747, 14, 20395, 8, 7931, 14, 37, 1311, 3022, 430, 267, 340, 291, 14, 6027, 8, 6881, 304, 288, 746, 5925, 8, 7931, 14, 37, 1311, 3022, 12, 5724, 12, 747, 14, 20395, 8, 7931, 14, 37, 1311, 3022, 430, 267, 340, 440, 291, 14, 2444, 8, 277, 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,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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 ]
Dhivyap/ansible
lib/ansible/modules/network/ios/ios_ntp.py
10
8739
#!/usr/bin/python # Copyright: Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'network'} DOCUMENTATION = ''' --- module: ios_ntp extends_documentation_fragment: ios version_added: "2.8" short_description: Manages core NTP configuration. description: - Manages core NTP configuration. author: - Federico Olivieri (@Federico87) options: server: description: - Network address of NTP server. source_int: description: - Source interface for NTP packets. acl: description: - ACL for peer/server access restricition. logging: description: - Enable NTP logs. Data type boolean. type: bool default: False auth: description: - Enable NTP authentication. Data type boolean. type: bool default: False auth_key: description: - md5 NTP authentication key of tye 7. key_id: description: - auth_key id. Data type string state: description: - Manage the state of the resource. default: present choices: ['present', 'absent'] ''' EXAMPLES = ''' # Set new NTP server and source interface - ios_ntp: server: 10.0.255.10 source_int: Loopback0 logging: false state: present # Remove NTP ACL and logging - ios_ntp: acl: NTP_ACL logging: true state: absent # Set NTP authentication - ios_ntp: key_id: 10 auth_key: 15435A030726242723273C21181319000A auth: true state: present # Set new NTP configuration - ios_ntp: server: 10.0.255.10 source_int: Loopback0 acl: NTP_ACL logging: true key_id: 10 auth_key: 15435A030726242723273C21181319000A auth: true state: present ''' RETURN = ''' commands: description: command sent to the device returned: always type: list sample: ["no ntp server 10.0.255.10", "no ntp source Loopback0"] ''' import re from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.ios.ios import get_config, load_config from ansible.module_utils.network.ios.ios import ios_argument_spec def parse_server(line, dest): if dest == 'server': match = re.search(r'(ntp server )(\d+\.\d+\.\d+\.\d+)', line, re.M) if match: server = match.group(2) return server def parse_source_int(line, dest): if dest == 'source': match = re.search(r'(ntp source )(\S+)', line, re.M) if match: source = match.group(2) return source def parse_acl(line, dest): if dest == 'access-group': match = re.search(r'ntp access-group (?:peer|serve)(?:\s+)(\S+)', line, re.M) if match: acl = match.group(1) return acl def parse_logging(line, dest): if dest == 'logging': logging = dest return logging def parse_auth_key(line, dest): if dest == 'authentication-key': match = re.search(r'(ntp authentication-key \d+ md5 )(\w+)', line, re.M) if match: auth_key = match.group(2) return auth_key def parse_key_id(line, dest): if dest == 'trusted-key': match = re.search(r'(ntp trusted-key )(\d+)', line, re.M) if match: auth_key = match.group(2) return auth_key def parse_auth(dest): if dest == 'authenticate': return dest def map_config_to_obj(module): obj_dict = {} obj = [] server_list = [] config = get_config(module, flags=['| include ntp']) for line in config.splitlines(): match = re.search(r'ntp (\S+)', line, re.M) if match: dest = match.group(1) server = parse_server(line, dest) source_int = parse_source_int(line, dest) acl = parse_acl(line, dest) logging = parse_logging(line, dest) auth = parse_auth(dest) auth_key = parse_auth_key(line, dest) key_id = parse_key_id(line, dest) if server: server_list.append(server) if source_int: obj_dict['source_int'] = source_int if acl: obj_dict['acl'] = acl if logging: obj_dict['logging'] = True if auth: obj_dict['auth'] = True if auth_key: obj_dict['auth_key'] = auth_key if key_id: obj_dict['key_id'] = key_id obj_dict['server'] = server_list obj.append(obj_dict) return obj def map_params_to_obj(module): obj = [] obj.append({ 'state': module.params['state'], 'server': module.params['server'], 'source_int': module.params['source_int'], 'logging': module.params['logging'], 'acl': module.params['acl'], 'auth': module.params['auth'], 'auth_key': module.params['auth_key'], 'key_id': module.params['key_id'] }) return obj def map_obj_to_commands(want, have, module): commands = list() server_have = have[0].get('server', None) source_int_have = have[0].get('source_int', None) acl_have = have[0].get('acl', None) logging_have = have[0].get('logging', None) auth_have = have[0].get('auth', None) auth_key_have = have[0].get('auth_key', None) key_id_have = have[0].get('key_id', None) for w in want: server = w['server'] source_int = w['source_int'] acl = w['acl'] logging = w['logging'] state = w['state'] auth = w['auth'] auth_key = w['auth_key'] key_id = w['key_id'] if state == 'absent': if server_have and server in server_have: commands.append('no ntp server {0}'.format(server)) if source_int and source_int_have: commands.append('no ntp source {0}'.format(source_int)) if acl and acl_have: commands.append('no ntp access-group peer {0}'.format(acl)) if logging is True and logging_have: commands.append('no ntp logging') if auth is True and auth_have: commands.append('no ntp authenticate') if key_id and key_id_have: commands.append('no ntp trusted-key {0}'.format(key_id)) if auth_key and auth_key_have: if key_id and key_id_have: commands.append('no ntp authentication-key {0} md5 {1} 7'.format(key_id, auth_key)) elif state == 'present': if server is not None and server not in server_have: commands.append('ntp server {0}'.format(server)) if source_int is not None and source_int != source_int_have: commands.append('ntp source {0}'.format(source_int)) if acl is not None and acl != acl_have: commands.append('ntp access-group peer {0}'.format(acl)) if logging is not None and logging != logging_have and logging is not False: commands.append('ntp logging') if auth is not None and auth != auth_have and auth is not False: commands.append('ntp authenticate') if key_id is not None and key_id != key_id_have: commands.append('ntp trusted-key {0}'.format(key_id)) if auth_key is not None and auth_key != auth_key_have: if key_id is not None: commands.append('ntp authentication-key {0} md5 {1} 7'.format(key_id, auth_key)) return commands def main(): argument_spec = dict( server=dict(), source_int=dict(), acl=dict(), logging=dict(type='bool', default=False), auth=dict(type='bool', default=False), auth_key=dict(), key_id=dict(), state=dict(choices=['absent', 'present'], default='present') ) argument_spec.update(ios_argument_spec) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True ) result = {'changed': False} warnings = list() if warnings: result['warnings'] = warnings want = map_params_to_obj(module) have = map_config_to_obj(module) commands = map_obj_to_commands(want, have, module) result['commands'] = commands if commands: if not module.check_mode: load_config(module, commands) result['changed'] = True module.exit_json(**result) if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1898, 26, 2622, 7290, 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, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 1200, 936, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 29516, 63, 15893, 199, 11036, 63, 9970, 63, 7677, 26, 29516, 199, 1023, 63, 3270, 26, 298, 18, 14, 24, 2, 199, 3612, 63, 1802, 26, 21612, 6170, 653, 6495, 2897, 14, 199, 1802, 26, 272, 446, 21612, 6170, 653, 6495, 2897, 14, 199, 2502, 26, 272, 446, 7949, 9910, 331, 593, 317, 26645, 73, 8593, 3456, 9910, 331, 1555, 9, 199, 1419, 26, 272, 1654, 26, 267, 1369, 26, 288, 446, 7220, 2287, 402, 653, 6495, 1654, 14, 272, 1350, 63, 442, 26, 267, 1369, 26, 288, 446, 5800, 3217, 367, 653, 6495, 14593, 14, 272, 15316, 26, 267, 1369, 26, 288, 446, 16543, 367, 9104, 15, 1000, 2879, 7213, 559, 296, 14, 272, 2050, 26, 267, 1369, 26, 288, 446, 12030, 653, 6495, 9610, 14, 3918, 730, 5046, 14, 267, 730, 26, 2155, 267, 849, 26, 756, 272, 1790, 26, 267, 1369, 26, 288, 446, 12030, 653, 6495, 6299, 14, 3918, 730, 5046, 14, 267, 730, 26, 2155, 267, 849, 26, 756, 272, 1790, 63, 498, 26, 267, 1369, 26, 288, 446, 6128, 21, 653, 6495, 6299, 790, 402, 307, 8048, 1520, 14, 272, 790, 63, 344, 26, 267, 1369, 26, 288, 446, 1790, 63, 498, 1305, 14, 3918, 730, 1059, 272, 1174, 26, 267, 1369, 26, 288, 446, 14944, 314, 1174, 402, 314, 2073, 14, 267, 849, 26, 3451, 267, 3415, 26, 788, 1881, 297, 283, 5575, 418, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 2494, 892, 653, 6495, 1654, 436, 1350, 3217, 199, 13, 29516, 63, 15893, 26, 272, 1654, 26, 1616, 14, 16, 14, 2299, 14, 709, 272, 1350, 63, 442, 26, 18175, 894, 16, 272, 2050, 26, 3055, 272, 1174, 26, 3451, 199, 199, 3, 5852, 653, 6495, 16543, 436, 2050, 199, 13, 29516, 63, 15893, 26, 272, 15316, 26, 653, 6495, 63, 18765, 272, 2050, 26, 2549, 272, 1174, 26, 9552, 199, 199, 3, 2494, 653, 6495, 6299, 199, 13, 29516, 63, 15893, 26, 272, 790, 63, 344, 26, 1616, 272, 1790, 63, 498, 26, 31693, 1276, 33, 16, 11516, 1479, 1194, 1465, 8001, 2898, 35, 18, 7906, 969, 1167, 1493, 33, 272, 1790, 26, 2549, 272, 1174, 26, 3451, 199, 199, 3, 2494, 892, 653, 6495, 2897, 199, 13, 29516, 63, 15893, 26, 272, 1654, 26, 1616, 14, 16, 14, 2299, 14, 709, 272, 1350, 63, 442, 26, 18175, 894, 16, 272, 15316, 26, 653, 6495, 63, 18765, 272, 2050, 26, 2549, 272, 790, 63, 344, 26, 1616, 272, 1790, 63, 498, 26, 31693, 1276, 33, 16, 11516, 1479, 1194, 1465, 8001, 2898, 35, 18, 7906, 969, 1167, 1493, 33, 272, 1790, 26, 2549, 272, 1174, 26, 3451, 199, 2344, 199, 199, 9677, 275, 1449, 199, 4405, 26, 272, 1369, 26, 1414, 4847, 370, 314, 2243, 272, 2138, 26, 3544, 272, 730, 26, 769, 272, 2690, 26, 2097, 889, 28581, 1654, 1616, 14, 16, 14, 2299, 14, 709, 401, 298, 889, 28581, 1350, 18175, 894, 16, 937, 199, 2344, 199, 646, 295, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 9207, 492, 664, 63, 888, 12, 2248, 63, 888, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 9207, 492, 29516, 63, 2094, 63, 1650, 421, 199, 318, 2198, 63, 1000, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 1000, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 6774, 15893, 1654, 776, 2961, 68, 23294, 68, 23294, 68, 23294, 68, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 1654, 275, 1336, 14, 923, 8, 18, 9, 288, 372, 1654, 421, 199, 318, 2198, 63, 1365, 63, 442, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 1365, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 6774, 15893, 1350, 776, 2961, 51, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 1350, 275, 1336, 14, 923, 8, 18, 9, 288, 372, 1350, 421, 199, 318, 2198, 63, 5853, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 2732, 13, 923, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 7, 15893, 2879, 13, 923, 16697, 7866, 92, 4909, 9, 15840, 83, 27860, 51, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 15316, 275, 1336, 14, 923, 8, 17, 9, 288, 372, 15316, 421, 199, 318, 2198, 63, 4806, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 4806, 356, 267, 2050, 275, 2053, 267, 372, 2050, 421, 199, 318, 2198, 63, 1178, 63, 498, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 11725, 13, 498, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 6774, 15893, 6299, 13, 498, 971, 68, 11, 6128, 21, 776, 2961, 87, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 1790, 63, 498, 275, 1336, 14, 923, 8, 18, 9, 288, 372, 1790, 63, 498, 421, 199, 318, 2198, 63, 498, 63, 344, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 17549, 13, 498, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 6774, 15893, 19427, 13, 498, 776, 2961, 68, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 1790, 63, 498, 275, 1336, 14, 923, 8, 18, 9, 288, 372, 1790, 63, 498, 421, 199, 318, 2198, 63, 1178, 8, 2614, 304, 272, 340, 2053, 508, 283, 13975, 356, 267, 372, 2053, 421, 199, 318, 2341, 63, 888, 63, 475, 63, 1113, 8, 578, 304, 339, 1559, 63, 807, 275, 1052, 272, 1559, 275, 942, 272, 1654, 63, 513, 275, 942, 339, 1101 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1898, 26, 2622, 7290, 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, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 1200, 936, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 29516, 63, 15893, 199, 11036, 63, 9970, 63, 7677, 26, 29516, 199, 1023, 63, 3270, 26, 298, 18, 14, 24, 2, 199, 3612, 63, 1802, 26, 21612, 6170, 653, 6495, 2897, 14, 199, 1802, 26, 272, 446, 21612, 6170, 653, 6495, 2897, 14, 199, 2502, 26, 272, 446, 7949, 9910, 331, 593, 317, 26645, 73, 8593, 3456, 9910, 331, 1555, 9, 199, 1419, 26, 272, 1654, 26, 267, 1369, 26, 288, 446, 7220, 2287, 402, 653, 6495, 1654, 14, 272, 1350, 63, 442, 26, 267, 1369, 26, 288, 446, 5800, 3217, 367, 653, 6495, 14593, 14, 272, 15316, 26, 267, 1369, 26, 288, 446, 16543, 367, 9104, 15, 1000, 2879, 7213, 559, 296, 14, 272, 2050, 26, 267, 1369, 26, 288, 446, 12030, 653, 6495, 9610, 14, 3918, 730, 5046, 14, 267, 730, 26, 2155, 267, 849, 26, 756, 272, 1790, 26, 267, 1369, 26, 288, 446, 12030, 653, 6495, 6299, 14, 3918, 730, 5046, 14, 267, 730, 26, 2155, 267, 849, 26, 756, 272, 1790, 63, 498, 26, 267, 1369, 26, 288, 446, 6128, 21, 653, 6495, 6299, 790, 402, 307, 8048, 1520, 14, 272, 790, 63, 344, 26, 267, 1369, 26, 288, 446, 1790, 63, 498, 1305, 14, 3918, 730, 1059, 272, 1174, 26, 267, 1369, 26, 288, 446, 14944, 314, 1174, 402, 314, 2073, 14, 267, 849, 26, 3451, 267, 3415, 26, 788, 1881, 297, 283, 5575, 418, 199, 2344, 199, 199, 8918, 275, 1449, 199, 3, 2494, 892, 653, 6495, 1654, 436, 1350, 3217, 199, 13, 29516, 63, 15893, 26, 272, 1654, 26, 1616, 14, 16, 14, 2299, 14, 709, 272, 1350, 63, 442, 26, 18175, 894, 16, 272, 2050, 26, 3055, 272, 1174, 26, 3451, 199, 199, 3, 5852, 653, 6495, 16543, 436, 2050, 199, 13, 29516, 63, 15893, 26, 272, 15316, 26, 653, 6495, 63, 18765, 272, 2050, 26, 2549, 272, 1174, 26, 9552, 199, 199, 3, 2494, 653, 6495, 6299, 199, 13, 29516, 63, 15893, 26, 272, 790, 63, 344, 26, 1616, 272, 1790, 63, 498, 26, 31693, 1276, 33, 16, 11516, 1479, 1194, 1465, 8001, 2898, 35, 18, 7906, 969, 1167, 1493, 33, 272, 1790, 26, 2549, 272, 1174, 26, 3451, 199, 199, 3, 2494, 892, 653, 6495, 2897, 199, 13, 29516, 63, 15893, 26, 272, 1654, 26, 1616, 14, 16, 14, 2299, 14, 709, 272, 1350, 63, 442, 26, 18175, 894, 16, 272, 15316, 26, 653, 6495, 63, 18765, 272, 2050, 26, 2549, 272, 790, 63, 344, 26, 1616, 272, 1790, 63, 498, 26, 31693, 1276, 33, 16, 11516, 1479, 1194, 1465, 8001, 2898, 35, 18, 7906, 969, 1167, 1493, 33, 272, 1790, 26, 2549, 272, 1174, 26, 3451, 199, 2344, 199, 199, 9677, 275, 1449, 199, 4405, 26, 272, 1369, 26, 1414, 4847, 370, 314, 2243, 272, 2138, 26, 3544, 272, 730, 26, 769, 272, 2690, 26, 2097, 889, 28581, 1654, 1616, 14, 16, 14, 2299, 14, 709, 401, 298, 889, 28581, 1350, 18175, 894, 16, 937, 199, 2344, 199, 646, 295, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 4316, 492, 6953, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 9207, 492, 664, 63, 888, 12, 2248, 63, 888, 199, 504, 3242, 14, 578, 63, 1208, 14, 1200, 14, 9207, 14, 9207, 492, 29516, 63, 2094, 63, 1650, 421, 199, 318, 2198, 63, 1000, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 1000, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 6774, 15893, 1654, 776, 2961, 68, 23294, 68, 23294, 68, 23294, 68, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 1654, 275, 1336, 14, 923, 8, 18, 9, 288, 372, 1654, 421, 199, 318, 2198, 63, 1365, 63, 442, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 1365, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 6774, 15893, 1350, 776, 2961, 51, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 1350, 275, 1336, 14, 923, 8, 18, 9, 288, 372, 1350, 421, 199, 318, 2198, 63, 5853, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 2732, 13, 923, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 7, 15893, 2879, 13, 923, 16697, 7866, 92, 4909, 9, 15840, 83, 27860, 51, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 15316, 275, 1336, 14, 923, 8, 17, 9, 288, 372, 15316, 421, 199, 318, 2198, 63, 4806, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 4806, 356, 267, 2050, 275, 2053, 267, 372, 2050, 421, 199, 318, 2198, 63, 1178, 63, 498, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 11725, 13, 498, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 6774, 15893, 6299, 13, 498, 971, 68, 11, 6128, 21, 776, 2961, 87, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 1790, 63, 498, 275, 1336, 14, 923, 8, 18, 9, 288, 372, 1790, 63, 498, 421, 199, 318, 2198, 63, 498, 63, 344, 8, 604, 12, 2053, 304, 272, 340, 2053, 508, 283, 17549, 13, 498, 356, 267, 1336, 275, 295, 14, 1733, 8, 82, 6774, 15893, 19427, 13, 498, 776, 2961, 68, 14705, 1004, 12, 295, 14, 45, 9, 267, 340, 1336, 26, 288, 1790, 63, 498, 275, 1336, 14, 923, 8, 18, 9, 288, 372, 1790, 63, 498, 421, 199, 318, 2198, 63, 1178, 8, 2614, 304, 272, 340, 2053, 508, 283, 13975, 356, 267, 372, 2053, 421, 199, 318, 2341, 63, 888, 63, 475, 63, 1113, 8, 578, 304, 339, 1559, 63, 807, 275, 1052, 272, 1559, 275, 942, 272, 1654, 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1, 1, 1, 1, 1, 1, 1, 1, 1 ]
TeslaProject/external_chromium_org
chrome/browser/metrics/variations/generate_resources_map.py
64
5458
#!/usr/bin/python # Copyright 2014 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. import collections import hashlib import operator import os import re import sys RESOURCE_EXTRACT_REGEX = re.compile('^#define (\S*) (\d*)$', re.MULTILINE) class Error(Exception): """Base error class for all exceptions in generated_resources_map.""" class HashCollisionError(Error): """Multiple resource names hash to the same value.""" Resource = collections.namedtuple("Resource", ['hash', 'name', 'index']) def _HashName(name): """Returns the hash id for a name. Args: name: The name to hash. Returns: An int that is at most 32 bits. """ md5hash = hashlib.md5() md5hash.update(name) return int(md5hash.hexdigest()[:8], 16) def _GetNameIndexPairsIter(string_to_scan): """Gets an iterator of the resource name and index pairs of the given string. Scans the input string for lines of the form "#define NAME INDEX" and returns an iterator over all matching (NAME, INDEX) pairs. Args: string_to_scan: The input string to scan. Yields: A tuple of name and index. """ for match in RESOURCE_EXTRACT_REGEX.finditer(string_to_scan): yield match.group(1, 2) def _GetResourceListFromString(resources_content): """Produces a list of |Resource| objects from a string. The input string conaints lines of the form "#define NAME INDEX". The returned list is sorted primarily by hash, then name, and then index. Args: resources_content: The input string to process, contains lines of the form "#define NAME INDEX". Returns: A sorted list of |Resource| objects. """ resources = [Resource(_HashName(name), name, index) for name, index in _GetNameIndexPairsIter(resources_content)] # The default |Resource| order makes |resources| sorted by the hash, then # name, then index. resources.sort() return resources def _CheckForHashCollisions(sorted_resource_list): """Checks a sorted list of |Resource| objects for hash collisions. Args: sorted_resource_list: A sorted list of |Resource| objects. Returns: A set of all |Resource| objects with collisions. """ collisions = set() for i in xrange(len(sorted_resource_list) - 1): resource = sorted_resource_list[i] next_resource = sorted_resource_list[i+1] if resource.hash == next_resource.hash: collisions.add(resource) collisions.add(next_resource) return collisions def _GenDataArray( resources, entry_pattern, array_name, array_type, data_getter): """Generates a C++ statement defining a literal array containing the hashes. Args: resources: A sorted list of |Resource| objects. entry_pattern: A pattern to be used to generate each entry in the array. The pattern is expected to have a place for data and one for a comment, in that order. array_name: The name of the array being generated. array_type: The type of the array being generated. data_getter: A function that gets the array data from a |Resource| object. Returns: A string containing a C++ statement defining the an array. """ lines = [entry_pattern % (data_getter(r), r.name) for r in resources] pattern = """const %(type)s %(name)s[] = { %(content)s }; """ return pattern % {'type': array_type, 'name': array_name, 'content': '\n'.join(lines)} def _GenerateFileContent(resources_content): """Generates the .cc content from the given generated_resources.h content. Args: resources_content: The input string to process, contains lines of the form "#define NAME INDEX". Returns: .cc file content defining the kResourceHashes and kResourceIndices arrays. """ hashed_tuples = _GetResourceListFromString(resources_content) collisions = _CheckForHashCollisions(hashed_tuples) if collisions: error_message = "\n".join( ["hash: %i, name: %s" % (i[0], i[1]) for i in sorted(collisions)]) error_message = ("\nThe following names had hash collisions " "(sorted by the hash value):\n%s\n" %(error_message)) raise HashCollisionError(error_message) hashes_array = _GenDataArray( hashed_tuples, " %iU, // %s", 'kResourceHashes', 'uint32_t', operator.attrgetter('hash')) indices_array = _GenDataArray( hashed_tuples, " %s, // %s", 'kResourceIndices', 'int', operator.attrgetter('index')) return ( "// This file was generated by generate_resources_map.py. Do not edit.\n" "\n\n" "#include " "\"chrome/browser/metrics/variations/generated_resources_map.h\"\n\n" "namespace chrome_variations {\n\n" "const size_t kNumResources = %i;\n\n" "%s" "\n" "%s" "\n" "} // namespace chrome_variations\n") % ( len(hashed_tuples), hashes_array, indices_array) def main(resources_file, map_file): generated_resources_h = "" with open(resources_file, "r") as resources: generated_resources_h = resources.read() if len(generated_resources_h) == 0: raise Error("No content loaded for %s." % (resources_file)) file_content = _GenerateFileContent(generated_resources_h) with open(map_file, "w") as generated_file: generated_file.write(file_content) if __name__ == '__main__': sys.exit(main(sys.argv[1], sys.argv[2]))
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1898, 6927, 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, 646, 5055, 199, 646, 8337, 199, 646, 4182, 199, 646, 747, 199, 646, 295, 199, 646, 984, 421, 199, 14110, 63, 30335, 63, 10710, 275, 295, 14, 2014, 9097, 3, 4640, 14749, 51, 13278, 14749, 68, 13278, 4268, 295, 14, 16661, 9, 199, 199, 533, 4520, 8, 1726, 304, 523, 408, 1563, 1125, 1021, 367, 1006, 4967, 315, 4046, 63, 4435, 63, 1130, 1041, 421, 199, 533, 16101, 2001, 23656, 547, 8, 547, 304, 523, 408, 8433, 2073, 1561, 2631, 370, 314, 2011, 574, 1041, 421, 199, 4031, 275, 5055, 14, 18921, 480, 4031, 401, 788, 2227, 297, 283, 354, 297, 283, 1080, 1105, 421, 199, 318, 485, 3476, 985, 8, 354, 304, 523, 408, 3407, 314, 2631, 1305, 367, 282, 536, 14, 819, 3033, 26, 272, 536, 26, 710, 536, 370, 2631, 14, 819, 1803, 26, 272, 1626, 1109, 626, 365, 737, 4750, 4337, 5821, 14, 523, 408, 523, 6128, 21, 2227, 275, 8337, 14, 1064, 21, 342, 523, 6128, 21, 2227, 14, 873, 8, 354, 9, 523, 372, 1109, 8, 1064, 21, 2227, 14, 11453, 20523, 24, 467, 3193, 9, 421, 199, 318, 485, 21266, 2681, 12882, 83, 3315, 8, 875, 63, 475, 63, 6282, 304, 523, 408, 14426, 376, 6122, 402, 314, 2073, 536, 436, 1478, 6342, 402, 314, 1627, 1059, 14, 819, 13916, 796, 314, 1324, 1059, 367, 2385, 402, 314, 1824, 5426, 4640, 13637, 17055, 2, 436, 2529, 523, 376, 6122, 1806, 1006, 4877, 334, 2339, 12, 17055, 9, 6342, 14, 819, 3033, 26, 272, 1059, 63, 475, 63, 6282, 26, 710, 1324, 1059, 370, 8000, 14, 819, 23771, 83, 26, 272, 437, 2008, 402, 536, 436, 1478, 14, 523, 408, 523, 367, 1336, 315, 30061, 63, 30335, 63, 10710, 14, 19373, 8, 875, 63, 475, 63, 6282, 304, 272, 1995, 1336, 14, 923, 8, 17, 12, 499, 9, 421, 199, 318, 485, 1002, 4031, 1296, 7671, 8, 4435, 63, 1317, 304, 523, 408, 919, 10569, 282, 769, 402, 1204, 4031, 92, 2251, 687, 282, 1059, 14, 819, 710, 1324, 1059, 406, 65, 13141, 2385, 402, 314, 1824, 5426, 4640, 13637, 17055, 1674, 710, 2138, 523, 769, 365, 3355, 1979, 30468, 701, 2631, 12, 2066, 536, 12, 436, 2066, 1478, 14, 819, 3033, 26, 272, 5944, 63, 1317, 26, 710, 1324, 1059, 370, 2112, 12, 3509, 2385, 402, 314, 1824, 267, 5426, 4640, 13637, 17055, 1674, 819, 1803, 26, 272, 437, 3355, 769, 402, 1204, 4031, 92, 2251, 14, 523, 408, 523, 5944, 275, 359, 4031, 1547, 3476, 985, 8, 354, 395, 536, 12, 1478, 9, 367, 536, 12, 1478, 315, 2049, 485, 21266, 2681, 12882, 83, 3315, 8, 4435, 63, 1317, 1874, 819, 327, 710, 849, 1204, 4031, 92, 1865, 7704, 1204, 4435, 92, 3355, 701, 314, 2631, 12, 2066, 523, 327, 536, 12, 2066, 1478, 14, 523, 5944, 14, 3191, 342, 819, 372, 5944, 421, 199, 318, 485, 1799, 1858, 3476, 2001, 317, 1356, 8, 5917, 63, 1927, 63, 513, 304, 523, 408, 11834, 282, 3355, 769, 402, 1204, 4031, 92, 2251, 367, 2631, 30063, 14, 819, 3033, 26, 272, 3355, 63, 1927, 63, 513, 26, 437, 3355, 769, 402, 1204, 4031, 92, 2251, 14, 819, 1803, 26, 272, 437, 663, 402, 1006, 1204, 4031, 92, 2251, 543, 30063, 14, 523, 408, 523, 30063, 275, 663, 342, 523, 367, 284, 315, 4945, 8, 552, 8, 5917, 63, 1927, 63, 513, 9, 446, 413, 304, 272, 2073, 275, 3355, 63, 1927, 63, 513, 59, 73, 61, 272, 2163, 63, 1927, 275, 3355, 63, 1927, 63, 513, 59, 73, 11, 17, 61, 272, 340, 2073, 14, 2227, 508, 2163, 63, 1927, 14, 2227, 26, 489, 30063, 14, 525, 8, 1927, 9, 489, 30063, 14, 525, 8, 2184, 63, 1927, 9, 819, 372, 30063, 421, 199, 318, 485, 8168, 1451, 3836, 8, 272, 5944, 12, 2397, 63, 3401, 12, 1625, 63, 354, 12, 1625, 63, 466, 12, 666, 63, 7416, 304, 523, 408, 20551, 282, 445, 4176, 5164, 12669, 282, 8785, 1625, 3035, 314, 14647, 14, 819, 3033, 26, 272, 5944, 26, 437, 3355, 769, 402, 1204, 4031, 92, 2251, 14, 272, 2397, 63, 3401, 26, 437, 3851, 370, 506, 1202, 370, 3550, 1924, 2397, 315, 314, 1625, 14, 710, 267, 3851, 365, 1420, 370, 1172, 282, 4192, 367, 666, 436, 1373, 367, 282, 3721, 12, 315, 267, 626, 1865, 14, 272, 1625, 63, 354, 26, 710, 536, 402, 314, 1625, 3769, 4046, 14, 272, 1625, 63, 466, 26, 710, 730, 402, 314, 1625, 3769, 4046, 14, 272, 666, 63, 7416, 26, 437, 805, 626, 7545, 314, 1625, 666, 687, 282, 1204, 4031, 92, 909, 14, 819, 1803, 26, 272, 437, 1059, 3035, 282, 445, 4176, 5164, 12669, 314, 376, 1625, 14, 523, 408, 523, 2385, 275, 359, 2373, 63, 3401, 450, 334, 576, 63, 7416, 8, 82, 395, 519, 14, 354, 9, 367, 519, 315, 5944, 61, 523, 3851, 275, 408, 1297, 2818, 466, 9, 83, 2818, 354, 9, 83, 8607, 275, 469, 199, 2840, 1317, 9, 83, 199, 12084, 199, 624, 523, 372, 3851, 450, 791, 466, 356, 1625, 63, 466, 12, 490, 283, 354, 356, 1625, 63, 354, 12, 490, 283, 1317, 356, 1557, 78, 1370, 904, 8, 1278, 6769, 421, 199, 318, 485, 6864, 1173, 2714, 8, 4435, 63, 1317, 304, 523, 408, 20551, 314, 1275, 2055, 1564, 687, 314, 1627, 4046, 63, 4435, 14, 72, 1564, 14, 819, 3033, 26, 272, 5944, 63, 1317, 26, 710, 1324, 1059, 370, 2112, 12, 3509, 2385, 402, 314, 1824, 267, 5426, 4640, 13637, 17055, 1674, 819, 1803, 26, 272, 1275, 2055, 570, 1564, 12669, 314, 1022, 4031, 31660, 436, 1022, 4031, 18488, 6572, 14, 523, 408, 523, 19871, 63, 11760, 275, 485, 1002, 4031, 1296, 7671, 8, 4435, 63, 1317, 9, 819, 30063, 275, 485, 1799, 1858, 3476, 2001, 317, 1356, 8, 26368, 63, 11760, 9, 523, 340, 30063, 26, 272, 1125, 63, 1188, 275, 1867, 78, 1674, 904, 8, 267, 2097 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1898, 6927, 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, 646, 5055, 199, 646, 8337, 199, 646, 4182, 199, 646, 747, 199, 646, 295, 199, 646, 984, 421, 199, 14110, 63, 30335, 63, 10710, 275, 295, 14, 2014, 9097, 3, 4640, 14749, 51, 13278, 14749, 68, 13278, 4268, 295, 14, 16661, 9, 199, 199, 533, 4520, 8, 1726, 304, 523, 408, 1563, 1125, 1021, 367, 1006, 4967, 315, 4046, 63, 4435, 63, 1130, 1041, 421, 199, 533, 16101, 2001, 23656, 547, 8, 547, 304, 523, 408, 8433, 2073, 1561, 2631, 370, 314, 2011, 574, 1041, 421, 199, 4031, 275, 5055, 14, 18921, 480, 4031, 401, 788, 2227, 297, 283, 354, 297, 283, 1080, 1105, 421, 199, 318, 485, 3476, 985, 8, 354, 304, 523, 408, 3407, 314, 2631, 1305, 367, 282, 536, 14, 819, 3033, 26, 272, 536, 26, 710, 536, 370, 2631, 14, 819, 1803, 26, 272, 1626, 1109, 626, 365, 737, 4750, 4337, 5821, 14, 523, 408, 523, 6128, 21, 2227, 275, 8337, 14, 1064, 21, 342, 523, 6128, 21, 2227, 14, 873, 8, 354, 9, 523, 372, 1109, 8, 1064, 21, 2227, 14, 11453, 20523, 24, 467, 3193, 9, 421, 199, 318, 485, 21266, 2681, 12882, 83, 3315, 8, 875, 63, 475, 63, 6282, 304, 523, 408, 14426, 376, 6122, 402, 314, 2073, 536, 436, 1478, 6342, 402, 314, 1627, 1059, 14, 819, 13916, 796, 314, 1324, 1059, 367, 2385, 402, 314, 1824, 5426, 4640, 13637, 17055, 2, 436, 2529, 523, 376, 6122, 1806, 1006, 4877, 334, 2339, 12, 17055, 9, 6342, 14, 819, 3033, 26, 272, 1059, 63, 475, 63, 6282, 26, 710, 1324, 1059, 370, 8000, 14, 819, 23771, 83, 26, 272, 437, 2008, 402, 536, 436, 1478, 14, 523, 408, 523, 367, 1336, 315, 30061, 63, 30335, 63, 10710, 14, 19373, 8, 875, 63, 475, 63, 6282, 304, 272, 1995, 1336, 14, 923, 8, 17, 12, 499, 9, 421, 199, 318, 485, 1002, 4031, 1296, 7671, 8, 4435, 63, 1317, 304, 523, 408, 919, 10569, 282, 769, 402, 1204, 4031, 92, 2251, 687, 282, 1059, 14, 819, 710, 1324, 1059, 406, 65, 13141, 2385, 402, 314, 1824, 5426, 4640, 13637, 17055, 1674, 710, 2138, 523, 769, 365, 3355, 1979, 30468, 701, 2631, 12, 2066, 536, 12, 436, 2066, 1478, 14, 819, 3033, 26, 272, 5944, 63, 1317, 26, 710, 1324, 1059, 370, 2112, 12, 3509, 2385, 402, 314, 1824, 267, 5426, 4640, 13637, 17055, 1674, 819, 1803, 26, 272, 437, 3355, 769, 402, 1204, 4031, 92, 2251, 14, 523, 408, 523, 5944, 275, 359, 4031, 1547, 3476, 985, 8, 354, 395, 536, 12, 1478, 9, 367, 536, 12, 1478, 315, 2049, 485, 21266, 2681, 12882, 83, 3315, 8, 4435, 63, 1317, 1874, 819, 327, 710, 849, 1204, 4031, 92, 1865, 7704, 1204, 4435, 92, 3355, 701, 314, 2631, 12, 2066, 523, 327, 536, 12, 2066, 1478, 14, 523, 5944, 14, 3191, 342, 819, 372, 5944, 421, 199, 318, 485, 1799, 1858, 3476, 2001, 317, 1356, 8, 5917, 63, 1927, 63, 513, 304, 523, 408, 11834, 282, 3355, 769, 402, 1204, 4031, 92, 2251, 367, 2631, 30063, 14, 819, 3033, 26, 272, 3355, 63, 1927, 63, 513, 26, 437, 3355, 769, 402, 1204, 4031, 92, 2251, 14, 819, 1803, 26, 272, 437, 663, 402, 1006, 1204, 4031, 92, 2251, 543, 30063, 14, 523, 408, 523, 30063, 275, 663, 342, 523, 367, 284, 315, 4945, 8, 552, 8, 5917, 63, 1927, 63, 513, 9, 446, 413, 304, 272, 2073, 275, 3355, 63, 1927, 63, 513, 59, 73, 61, 272, 2163, 63, 1927, 275, 3355, 63, 1927, 63, 513, 59, 73, 11, 17, 61, 272, 340, 2073, 14, 2227, 508, 2163, 63, 1927, 14, 2227, 26, 489, 30063, 14, 525, 8, 1927, 9, 489, 30063, 14, 525, 8, 2184, 63, 1927, 9, 819, 372, 30063, 421, 199, 318, 485, 8168, 1451, 3836, 8, 272, 5944, 12, 2397, 63, 3401, 12, 1625, 63, 354, 12, 1625, 63, 466, 12, 666, 63, 7416, 304, 523, 408, 20551, 282, 445, 4176, 5164, 12669, 282, 8785, 1625, 3035, 314, 14647, 14, 819, 3033, 26, 272, 5944, 26, 437, 3355, 769, 402, 1204, 4031, 92, 2251, 14, 272, 2397, 63, 3401, 26, 437, 3851, 370, 506, 1202, 370, 3550, 1924, 2397, 315, 314, 1625, 14, 710, 267, 3851, 365, 1420, 370, 1172, 282, 4192, 367, 666, 436, 1373, 367, 282, 3721, 12, 315, 267, 626, 1865, 14, 272, 1625, 63, 354, 26, 710, 536, 402, 314, 1625, 3769, 4046, 14, 272, 1625, 63, 466, 26, 710, 730, 402, 314, 1625, 3769, 4046, 14, 272, 666, 63, 7416, 26, 437, 805, 626, 7545, 314, 1625, 666, 687, 282, 1204, 4031, 92, 909, 14, 819, 1803, 26, 272, 437, 1059, 3035, 282, 445, 4176, 5164, 12669, 314, 376, 1625, 14, 523, 408, 523, 2385, 275, 359, 2373, 63, 3401, 450, 334, 576, 63, 7416, 8, 82, 395, 519, 14, 354, 9, 367, 519, 315, 5944, 61, 523, 3851, 275, 408, 1297, 2818, 466, 9, 83, 2818, 354, 9, 83, 8607, 275, 469, 199, 2840, 1317, 9, 83, 199, 12084, 199, 624, 523, 372, 3851, 450, 791, 466, 356, 1625, 63, 466, 12, 490, 283, 354, 356, 1625, 63, 354, 12, 490, 283, 1317, 356, 1557, 78, 1370, 904, 8, 1278, 6769, 421, 199, 318, 485, 6864, 1173, 2714, 8, 4435, 63, 1317, 304, 523, 408, 20551, 314, 1275, 2055, 1564, 687, 314, 1627, 4046, 63, 4435, 14, 72, 1564, 14, 819, 3033, 26, 272, 5944, 63, 1317, 26, 710, 1324, 1059, 370, 2112, 12, 3509, 2385, 402, 314, 1824, 267, 5426, 4640, 13637, 17055, 1674, 819, 1803, 26, 272, 1275, 2055, 570, 1564, 12669, 314, 1022, 4031, 31660, 436, 1022, 4031, 18488, 6572, 14, 523, 408, 523, 19871, 63, 11760, 275, 485, 1002, 4031, 1296, 7671, 8, 4435, 63, 1317, 9, 819, 30063, 275, 485, 1799, 1858, 3476, 2001, 317, 1356, 8, 26368, 63, 11760, 9, 523, 340, 30063, 26, 272, 1125, 63, 1188, 275, 1867, 78, 1674, 904, 8, 267, 2097, 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 ]
Nitaco/ansible
lib/ansible/plugins/lookup/__init__.py
54
4474
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.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/>. # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type from abc import abstractmethod from ansible.errors import AnsibleFileNotFound from ansible.plugins import AnsiblePlugin try: from __main__ import display except ImportError: from ansible.utils.display import Display display = Display() __all__ = ['LookupBase'] class LookupBase(AnsiblePlugin): def __init__(self, loader=None, templar=None, **kwargs): super(LookupBase, self).__init__() self._loader = loader self._templar = templar # Backwards compat: self._display isn't really needed, just import the global display and use that. self._display = display def get_basedir(self, variables): if 'role_path' in variables: return variables['role_path'] else: return self._loader.get_basedir() @staticmethod def _flatten(terms): ret = [] for term in terms: if isinstance(term, (list, tuple)): ret.extend(term) else: ret.append(term) return ret @staticmethod def _combine(a, b): results = [] for x in a: for y in b: results.append(LookupBase._flatten([x, y])) return results @staticmethod def _flatten_hash_to_list(terms): ret = [] for key in terms: ret.append({'key': key, 'value': terms[key]}) return ret @abstractmethod def run(self, terms, variables=None, **kwargs): """ When the playbook specifies a lookup, this method is run. The arguments to the lookup become the arguments to this method. One additional keyword argument named ``variables`` is added to the method call. It contains the variables available to ansible at the time the lookup is templated. For instance:: "{{ lookup('url', 'https://toshio.fedorapeople.org/one.txt', validate_certs=True) }}" would end up calling the lookup plugin named url's run method like this:: run(['https://toshio.fedorapeople.org/one.txt'], variables=available_variables, validate_certs=True) Lookup plugins can be used within playbooks for looping. When this happens, the first argument is a list containing the terms. Lookup plugins can also be called from within playbooks to return their values into a variable or parameter. If the user passes a string in this case, it is converted into a list. Errors encountered during execution should be returned by raising AnsibleError() with a message describing the error. Any strings returned by this method that could ever contain non-ascii must be converted into python's unicode type as the strings will be run through jinja2 which has this requirement. You can use:: from ansible.module_utils._text import to_text result_string = to_text(result_string) """ pass def find_file_in_search_path(self, myvars, subdir, needle, ignore_missing=False): ''' Return a file (needle) in the task's expected search path. ''' if 'ansible_search_path' in myvars: paths = myvars['ansible_search_path'] else: paths = [self.get_basedir(myvars)] result = None try: result = self._loader.path_dwim_relative_stack(paths, subdir, needle) except AnsibleFileNotFound: if not ignore_missing: self._display.warning("Unable to find '%s' in expected paths (use -vvvvv to see paths)" % needle) return result
gpl-3.0
[ 3, 334, 67, 9, 6029, 13, 7280, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 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, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 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, 504, 13022, 492, 9006, 765, 199, 199, 504, 3242, 14, 2550, 492, 2622, 1173, 4667, 199, 504, 3242, 14, 5265, 492, 2622, 5061, 199, 199, 893, 26, 272, 687, 636, 973, 363, 492, 2929, 199, 2590, 3545, 26, 272, 687, 3242, 14, 1208, 14, 2918, 492, 12175, 272, 2929, 275, 12175, 342, 199, 199, 363, 452, 363, 275, 788, 7521, 1563, 418, 421, 199, 533, 12785, 1563, 8, 10047, 5061, 304, 339, 347, 636, 826, 721, 277, 12, 5077, 29, 403, 12, 28038, 29, 403, 12, 1011, 958, 304, 398, 1613, 8, 7521, 1563, 12, 291, 2843, 826, 4533, 398, 291, 423, 3422, 275, 5077, 267, 291, 423, 26718, 275, 28038, 398, 327, 10257, 4751, 8434, 26, 291, 423, 2918, 5712, 1133, 7710, 4346, 12, 2951, 492, 314, 2288, 2929, 436, 675, 626, 14, 267, 291, 423, 2918, 275, 2929, 339, 347, 664, 63, 12484, 8, 277, 12, 2860, 304, 267, 340, 283, 3756, 63, 515, 7, 315, 2860, 26, 288, 372, 2860, 459, 3756, 63, 515, 418, 267, 587, 26, 288, 372, 291, 423, 3422, 14, 362, 63, 12484, 342, 339, 768, 4639, 272, 347, 485, 8487, 8, 9187, 304, 267, 2203, 275, 942, 267, 367, 6707, 315, 2895, 26, 288, 340, 1228, 8, 5125, 12, 334, 513, 12, 2008, 2298, 355, 2203, 14, 2880, 8, 5125, 9, 288, 587, 26, 355, 2203, 14, 740, 8, 5125, 9, 267, 372, 2203, 339, 768, 4639, 272, 347, 485, 13307, 8, 65, 12, 330, 304, 267, 2058, 275, 942, 267, 367, 671, 315, 282, 26, 288, 367, 612, 315, 330, 26, 355, 2058, 14, 740, 8, 7521, 1563, 423, 8487, 779, 88, 12, 612, 2459, 267, 372, 2058, 339, 768, 4639, 272, 347, 485, 8487, 63, 2227, 63, 475, 63, 513, 8, 9187, 304, 267, 2203, 275, 942, 267, 367, 790, 315, 2895, 26, 288, 2203, 14, 740, 3252, 498, 356, 790, 12, 283, 585, 356, 2895, 59, 498, 13412, 267, 372, 2203, 339, 768, 10315, 272, 347, 1255, 8, 277, 12, 2895, 12, 2860, 29, 403, 12, 1011, 958, 304, 267, 408, 267, 3979, 314, 15695, 9314, 282, 4237, 12, 642, 1083, 365, 1255, 14, 221, 710, 267, 2368, 370, 314, 4237, 8649, 314, 2368, 370, 642, 1083, 14, 221, 7309, 267, 4722, 4252, 1423, 4310, 1124, 3669, 1040, 365, 3483, 370, 314, 1083, 267, 1240, 14, 221, 2779, 3509, 314, 2860, 2808, 370, 3242, 737, 314, 900, 314, 267, 4237, 365, 27960, 14, 221, 2104, 1256, 447, 953, 7370, 4237, 360, 633, 297, 283, 2859, 921, 475, 609, 2308, 14, 15800, 269, 924, 7939, 14, 1308, 15, 368, 14, 2424, 297, 4107, 63, 8356, 29, 549, 9, 7820, 398, 3955, 1284, 1536, 6358, 314, 4237, 3589, 4310, 1166, 1159, 1255, 1083, 2839, 642, 447, 288, 1255, 2941, 2859, 921, 475, 609, 2308, 14, 15800, 269, 924, 7939, 14, 1308, 15, 368, 14, 2424, 995, 2860, 29, 4561, 63, 3669, 12, 4107, 63, 8356, 29, 549, 9, 398, 12785, 8963, 883, 506, 1202, 4453, 5232, 8858, 367, 4438, 316, 14, 221, 3979, 642, 267, 10986, 12, 314, 1642, 1423, 365, 282, 769, 3035, 314, 2895, 14, 221, 12785, 267, 8963, 883, 2597, 506, 2797, 687, 4453, 5232, 8858, 370, 372, 3932, 267, 1338, 1901, 282, 1750, 503, 2725, 14, 221, 982, 314, 922, 14933, 282, 1059, 315, 267, 642, 1930, 12, 652, 365, 6702, 1901, 282, 769, 14, 398, 20456, 14556, 5309, 6451, 1077, 506, 2138, 701, 17026, 267, 13358, 342, 543, 282, 1245, 13660, 314, 1125, 14, 398, 6184, 3326, 2138, 701, 642, 1083, 626, 4293, 14433, 1395, 2222, 13, 4371, 267, 1471, 506, 6702, 1901, 2366, 1159, 2649, 730, 465, 314, 3326, 911, 506, 1255, 267, 4012, 10321, 18, 1314, 965, 642, 10685, 14, 221, 2047, 883, 675, 447, 953, 687, 3242, 14, 578, 63, 1208, 423, 505, 492, 370, 63, 505, 288, 754, 63, 875, 275, 370, 63, 505, 8, 1099, 63, 875, 9, 267, 408, 267, 986, 339, 347, 2342, 63, 493, 63, 262, 63, 1733, 63, 515, 8, 277, 12, 3002, 2936, 12, 15488, 12, 1929, 274, 12, 3686, 63, 4752, 29, 797, 304, 267, 1449, 267, 1432, 282, 570, 334, 9321, 274, 9, 315, 314, 2120, 1159, 1420, 2754, 931, 14, 267, 1449, 398, 340, 283, 4853, 63, 1733, 63, 515, 7, 315, 3002, 2936, 26, 288, 3792, 275, 3002, 2936, 459, 4853, 63, 1733, 63, 515, 418, 267, 587, 26, 288, 3792, 275, 359, 277, 14, 362, 63, 12484, 8, 1662, 2936, 1874, 398, 754, 275, 488, 267, 862, 26, 288, 754, 275, 291, 423, 3422, 14, 515, 63, 10772, 1017, 63, 6188, 63, 2340, 8, 3771, 12, 15488, 12, 1929, 274, 9, 267, 871, 2622, 1173, 4667, 26, 288, 340, 440, 3686, 63, 4752, 26, 355, 291, 423, 2918, 14, 3764, 480, 6005, 370, 2342, 1543, 83, 7, 315, 1420, 3792, 334, 1180, 446, 8958, 24622, 370, 1937, 3792, 2924, 450, 1929, 274, 9 ]
[ 334, 67, 9, 6029, 13, 7280, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 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, 199, 3, 4155, 2803, 1655, 2366, 19, 13, 2453, 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, 504, 13022, 492, 9006, 765, 199, 199, 504, 3242, 14, 2550, 492, 2622, 1173, 4667, 199, 504, 3242, 14, 5265, 492, 2622, 5061, 199, 199, 893, 26, 272, 687, 636, 973, 363, 492, 2929, 199, 2590, 3545, 26, 272, 687, 3242, 14, 1208, 14, 2918, 492, 12175, 272, 2929, 275, 12175, 342, 199, 199, 363, 452, 363, 275, 788, 7521, 1563, 418, 421, 199, 533, 12785, 1563, 8, 10047, 5061, 304, 339, 347, 636, 826, 721, 277, 12, 5077, 29, 403, 12, 28038, 29, 403, 12, 1011, 958, 304, 398, 1613, 8, 7521, 1563, 12, 291, 2843, 826, 4533, 398, 291, 423, 3422, 275, 5077, 267, 291, 423, 26718, 275, 28038, 398, 327, 10257, 4751, 8434, 26, 291, 423, 2918, 5712, 1133, 7710, 4346, 12, 2951, 492, 314, 2288, 2929, 436, 675, 626, 14, 267, 291, 423, 2918, 275, 2929, 339, 347, 664, 63, 12484, 8, 277, 12, 2860, 304, 267, 340, 283, 3756, 63, 515, 7, 315, 2860, 26, 288, 372, 2860, 459, 3756, 63, 515, 418, 267, 587, 26, 288, 372, 291, 423, 3422, 14, 362, 63, 12484, 342, 339, 768, 4639, 272, 347, 485, 8487, 8, 9187, 304, 267, 2203, 275, 942, 267, 367, 6707, 315, 2895, 26, 288, 340, 1228, 8, 5125, 12, 334, 513, 12, 2008, 2298, 355, 2203, 14, 2880, 8, 5125, 9, 288, 587, 26, 355, 2203, 14, 740, 8, 5125, 9, 267, 372, 2203, 339, 768, 4639, 272, 347, 485, 13307, 8, 65, 12, 330, 304, 267, 2058, 275, 942, 267, 367, 671, 315, 282, 26, 288, 367, 612, 315, 330, 26, 355, 2058, 14, 740, 8, 7521, 1563, 423, 8487, 779, 88, 12, 612, 2459, 267, 372, 2058, 339, 768, 4639, 272, 347, 485, 8487, 63, 2227, 63, 475, 63, 513, 8, 9187, 304, 267, 2203, 275, 942, 267, 367, 790, 315, 2895, 26, 288, 2203, 14, 740, 3252, 498, 356, 790, 12, 283, 585, 356, 2895, 59, 498, 13412, 267, 372, 2203, 339, 768, 10315, 272, 347, 1255, 8, 277, 12, 2895, 12, 2860, 29, 403, 12, 1011, 958, 304, 267, 408, 267, 3979, 314, 15695, 9314, 282, 4237, 12, 642, 1083, 365, 1255, 14, 221, 710, 267, 2368, 370, 314, 4237, 8649, 314, 2368, 370, 642, 1083, 14, 221, 7309, 267, 4722, 4252, 1423, 4310, 1124, 3669, 1040, 365, 3483, 370, 314, 1083, 267, 1240, 14, 221, 2779, 3509, 314, 2860, 2808, 370, 3242, 737, 314, 900, 314, 267, 4237, 365, 27960, 14, 221, 2104, 1256, 447, 953, 7370, 4237, 360, 633, 297, 283, 2859, 921, 475, 609, 2308, 14, 15800, 269, 924, 7939, 14, 1308, 15, 368, 14, 2424, 297, 4107, 63, 8356, 29, 549, 9, 7820, 398, 3955, 1284, 1536, 6358, 314, 4237, 3589, 4310, 1166, 1159, 1255, 1083, 2839, 642, 447, 288, 1255, 2941, 2859, 921, 475, 609, 2308, 14, 15800, 269, 924, 7939, 14, 1308, 15, 368, 14, 2424, 995, 2860, 29, 4561, 63, 3669, 12, 4107, 63, 8356, 29, 549, 9, 398, 12785, 8963, 883, 506, 1202, 4453, 5232, 8858, 367, 4438, 316, 14, 221, 3979, 642, 267, 10986, 12, 314, 1642, 1423, 365, 282, 769, 3035, 314, 2895, 14, 221, 12785, 267, 8963, 883, 2597, 506, 2797, 687, 4453, 5232, 8858, 370, 372, 3932, 267, 1338, 1901, 282, 1750, 503, 2725, 14, 221, 982, 314, 922, 14933, 282, 1059, 315, 267, 642, 1930, 12, 652, 365, 6702, 1901, 282, 769, 14, 398, 20456, 14556, 5309, 6451, 1077, 506, 2138, 701, 17026, 267, 13358, 342, 543, 282, 1245, 13660, 314, 1125, 14, 398, 6184, 3326, 2138, 701, 642, 1083, 626, 4293, 14433, 1395, 2222, 13, 4371, 267, 1471, 506, 6702, 1901, 2366, 1159, 2649, 730, 465, 314, 3326, 911, 506, 1255, 267, 4012, 10321, 18, 1314, 965, 642, 10685, 14, 221, 2047, 883, 675, 447, 953, 687, 3242, 14, 578, 63, 1208, 423, 505, 492, 370, 63, 505, 288, 754, 63, 875, 275, 370, 63, 505, 8, 1099, 63, 875, 9, 267, 408, 267, 986, 339, 347, 2342, 63, 493, 63, 262, 63, 1733, 63, 515, 8, 277, 12, 3002, 2936, 12, 15488, 12, 1929, 274, 12, 3686, 63, 4752, 29, 797, 304, 267, 1449, 267, 1432, 282, 570, 334, 9321, 274, 9, 315, 314, 2120, 1159, 1420, 2754, 931, 14, 267, 1449, 398, 340, 283, 4853, 63, 1733, 63, 515, 7, 315, 3002, 2936, 26, 288, 3792, 275, 3002, 2936, 459, 4853, 63, 1733, 63, 515, 418, 267, 587, 26, 288, 3792, 275, 359, 277, 14, 362, 63, 12484, 8, 1662, 2936, 1874, 398, 754, 275, 488, 267, 862, 26, 288, 754, 275, 291, 423, 3422, 14, 515, 63, 10772, 1017, 63, 6188, 63, 2340, 8, 3771, 12, 15488, 12, 1929, 274, 9, 267, 871, 2622, 1173, 4667, 26, 288, 340, 440, 3686, 63, 4752, 26, 355, 291, 423, 2918, 14, 3764, 480, 6005, 370, 2342, 1543, 83, 7, 315, 1420, 3792, 334, 1180, 446, 8958, 24622, 370, 1937, 3792, 2924, 450, 1929, 274, 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,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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 ]
ajayaa/keystone
keystone/credential/schema.py
25
1643
# 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. _credential_properties = { 'blob': { 'type': 'string' }, 'project_id': { 'type': 'string' }, 'type': { 'type': 'string' }, 'user_id': { 'type': 'string' } } credential_create = { 'type': 'object', 'properties': _credential_properties, 'additionalProperties': True, 'oneOf': [ { 'title': 'ec2 credential requires project_id', 'required': ['blob', 'type', 'user_id', 'project_id'], 'properties': { 'type': { 'enum': ['ec2'] } } }, { 'title': 'non-ec2 credential does not require project_id', 'required': ['blob', 'type', 'user_id'], 'properties': { 'type': { 'not': { 'enum': ['ec2'] } } } } ] } credential_update = { 'type': 'object', 'properties': _credential_properties, 'minProperties': 1, 'additionalProperties': True }
apache-2.0
[ 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, 421, 199, 63, 15591, 63, 3282, 275, 469, 272, 283, 6582, 356, 469, 267, 283, 466, 356, 283, 875, 7, 272, 1660, 272, 283, 1715, 63, 344, 356, 469, 267, 283, 466, 356, 283, 875, 7, 272, 1660, 272, 283, 466, 356, 469, 267, 283, 466, 356, 283, 875, 7, 272, 1660, 272, 283, 751, 63, 344, 356, 469, 267, 283, 466, 356, 283, 875, 7, 272, 789, 199, 93, 199, 199, 15591, 63, 981, 275, 469, 272, 283, 466, 356, 283, 785, 297, 272, 283, 3282, 356, 485, 15591, 63, 3282, 12, 272, 283, 8460, 8516, 356, 715, 12, 272, 283, 368, 3466, 356, 359, 267, 469, 288, 283, 1213, 356, 283, 825, 18, 16338, 5074, 2199, 63, 344, 297, 288, 283, 2427, 356, 788, 6582, 297, 283, 466, 297, 283, 751, 63, 344, 297, 283, 1715, 63, 344, 995, 288, 283, 3282, 356, 469, 355, 283, 466, 356, 469, 490, 283, 4869, 356, 788, 825, 18, 418, 355, 789, 288, 789, 267, 1660, 267, 469, 288, 283, 1213, 356, 283, 2865, 13, 825, 18, 16338, 1630, 440, 4409, 2199, 63, 344, 297, 288, 283, 2427, 356, 788, 6582, 297, 283, 466, 297, 283, 751, 63, 344, 995, 288, 283, 3282, 356, 469, 355, 283, 466, 356, 469, 490, 283, 1397, 356, 469, 717, 283, 4869, 356, 788, 825, 18, 418, 490, 789, 355, 789, 288, 789, 267, 789, 272, 1622, 199, 93, 199, 199, 15591, 63, 873, 275, 469, 272, 283, 466, 356, 283, 785, 297, 272, 283, 3282, 356, 485, 15591, 63, 3282, 12, 272, 283, 827, 8516, 356, 413, 12, 272, 283, 8460, 8516, 356, 715, 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 ]
[ 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, 421, 199, 63, 15591, 63, 3282, 275, 469, 272, 283, 6582, 356, 469, 267, 283, 466, 356, 283, 875, 7, 272, 1660, 272, 283, 1715, 63, 344, 356, 469, 267, 283, 466, 356, 283, 875, 7, 272, 1660, 272, 283, 466, 356, 469, 267, 283, 466, 356, 283, 875, 7, 272, 1660, 272, 283, 751, 63, 344, 356, 469, 267, 283, 466, 356, 283, 875, 7, 272, 789, 199, 93, 199, 199, 15591, 63, 981, 275, 469, 272, 283, 466, 356, 283, 785, 297, 272, 283, 3282, 356, 485, 15591, 63, 3282, 12, 272, 283, 8460, 8516, 356, 715, 12, 272, 283, 368, 3466, 356, 359, 267, 469, 288, 283, 1213, 356, 283, 825, 18, 16338, 5074, 2199, 63, 344, 297, 288, 283, 2427, 356, 788, 6582, 297, 283, 466, 297, 283, 751, 63, 344, 297, 283, 1715, 63, 344, 995, 288, 283, 3282, 356, 469, 355, 283, 466, 356, 469, 490, 283, 4869, 356, 788, 825, 18, 418, 355, 789, 288, 789, 267, 1660, 267, 469, 288, 283, 1213, 356, 283, 2865, 13, 825, 18, 16338, 1630, 440, 4409, 2199, 63, 344, 297, 288, 283, 2427, 356, 788, 6582, 297, 283, 466, 297, 283, 751, 63, 344, 995, 288, 283, 3282, 356, 469, 355, 283, 466, 356, 469, 490, 283, 1397, 356, 469, 717, 283, 4869, 356, 788, 825, 18, 418, 490, 789, 355, 789, 288, 789, 267, 789, 272, 1622, 199, 93, 199, 199, 15591, 63, 873, 275, 469, 272, 283, 466, 356, 283, 785, 297, 272, 283, 3282, 356, 485, 15591, 63, 3282, 12, 272, 283, 827, 8516, 356, 413, 12, 272, 283, 8460, 8516, 356, 715, 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, 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, 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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 ]
nwjs/chromium.src
third_party/logilab/logilab/common/ureports/text_writer.py
92
5212
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of logilab-common. # # logilab-common 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 2.1 of the License, or (at your option) any # later version. # # logilab-common 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 logilab-common. If not, see <http://www.gnu.org/licenses/>. """Text formatting drivers for ureports""" from __future__ import print_function __docformat__ = "restructuredtext en" from six.moves import range from logilab.common.textutils import linesep from logilab.common.ureports import BaseWriter TITLE_UNDERLINES = [u'', u'=', u'-', u'`', u'.', u'~', u'^'] BULLETS = [u'*', u'-'] class TextWriter(BaseWriter): """format layouts as text (ReStructured inspiration but not totally handled yet) """ def begin_format(self, layout): super(TextWriter, self).begin_format(layout) self.list_level = 0 self.pending_urls = [] def visit_section(self, layout): """display a section as text """ self.section += 1 self.writeln() self.format_children(layout) if self.pending_urls: self.writeln() for label, url in self.pending_urls: self.writeln(u'.. _`%s`: %s' % (label, url)) self.pending_urls = [] self.section -= 1 self.writeln() def visit_title(self, layout): title = u''.join(list(self.compute_content(layout))) self.writeln(title) try: self.writeln(TITLE_UNDERLINES[self.section] * len(title)) except IndexError: print("FIXME TITLE TOO DEEP. TURNING TITLE INTO TEXT") def visit_paragraph(self, layout): """enter a paragraph""" self.format_children(layout) self.writeln() def visit_span(self, layout): """enter a span""" self.format_children(layout) def visit_table(self, layout): """display a table as text""" table_content = self.get_table_content(layout) # get columns width cols_width = [0]*len(table_content[0]) for row in table_content: for index in range(len(row)): col = row[index] cols_width[index] = max(cols_width[index], len(col)) if layout.klass == 'field': self.field_table(layout, table_content, cols_width) else: self.default_table(layout, table_content, cols_width) self.writeln() def default_table(self, layout, table_content, cols_width): """format a table""" cols_width = [size+1 for size in cols_width] format_strings = u' '.join([u'%%-%ss'] * len(cols_width)) format_strings = format_strings % tuple(cols_width) format_strings = format_strings.split(' ') table_linesep = u'\n+' + u'+'.join([u'-'*w for w in cols_width]) + u'+\n' headsep = u'\n+' + u'+'.join([u'='*w for w in cols_width]) + u'+\n' # FIXME: layout.cheaders self.write(table_linesep) for i in range(len(table_content)): self.write(u'|') line = table_content[i] for j in range(len(line)): self.write(format_strings[j] % line[j]) self.write(u'|') if i == 0 and layout.rheaders: self.write(headsep) else: self.write(table_linesep) def field_table(self, layout, table_content, cols_width): """special case for field table""" assert layout.cols == 2 format_string = u'%s%%-%ss: %%s' % (linesep, cols_width[0]) for field, value in table_content: self.write(format_string % (field, value)) def visit_list(self, layout): """display a list layout as text""" bullet = BULLETS[self.list_level % len(BULLETS)] indent = ' ' * self.list_level self.list_level += 1 for child in layout.children: self.write(u'%s%s%s ' % (linesep, indent, bullet)) child.accept(self) self.list_level -= 1 def visit_link(self, layout): """add a hyperlink""" if layout.label != layout.url: self.write(u'`%s`_' % layout.label) self.pending_urls.append( (layout.label, layout.url) ) else: self.write(layout.url) def visit_verbatimtext(self, layout): """display a verbatim layout as text (so difficult ;) """ self.writeln(u'::\n') for line in layout.data.splitlines(): self.writeln(u' ' + line) self.writeln() def visit_text(self, layout): """add some text""" self.write(u'%s' % layout.data)
bsd-3-clause
[ 3, 4248, 13004, 13, 8128, 5051, 1193, 1217, 428, 14, 33, 14, 334, 1262, 374, 12, 28671, 7140, 395, 1006, 4481, 4644, 14, 199, 3, 8966, 1455, 921, 1544, 14, 793, 24142, 14, 4391, 15, 1553, 6016, 475, 26, 7811, 32, 793, 24142, 14, 4391, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 943, 24142, 13, 2330, 14, 199, 3, 199, 3, 943, 24142, 13, 2330, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 652, 1334, 199, 3, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 844, 465, 3267, 701, 314, 2868, 199, 3, 2290, 2752, 12, 1902, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 199, 3, 2945, 1015, 14, 199, 3, 199, 3, 943, 24142, 13, 2330, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 2428, 199, 3, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 3169, 503, 3092, 199, 3, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 6401, 1696, 1684, 844, 367, 1655, 199, 3, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 3180, 199, 3, 543, 943, 24142, 13, 2330, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 624, 1872, 10803, 19016, 367, 399, 15629, 624, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 363, 21841, 363, 275, 298, 26854, 655, 2, 199, 199, 504, 3816, 14, 4912, 492, 1425, 199, 199, 504, 943, 24142, 14, 2330, 14, 505, 1208, 492, 1004, 4127, 199, 504, 943, 24142, 14, 2330, 14, 608, 5203, 492, 3523, 6261, 421, 199, 19091, 63, 6131, 540, 23023, 275, 359, 85, 6448, 399, 7, 4009, 399, 12418, 297, 399, 7, 30880, 399, 1370, 297, 399, 27547, 297, 399, 4289, 418, 199, 34, 3785, 30416, 275, 359, 85, 7, 7693, 399, 12418, 418, 199, 199, 533, 4516, 6261, 8, 1563, 6261, 304, 272, 408, 908, 7054, 83, 465, 1318, 272, 334, 497, 27486, 315, 8721, 1754, 1325, 440, 12657, 1183, 8860, 5966, 9, 272, 408, 272, 347, 5386, 63, 908, 8, 277, 12, 7054, 304, 267, 1613, 8, 1872, 6261, 12, 291, 680, 5037, 63, 908, 8, 4209, 9, 267, 291, 14, 513, 63, 1896, 275, 378, 267, 291, 14, 6455, 63, 3603, 275, 942, 339, 347, 5684, 63, 2792, 8, 277, 12, 7054, 304, 267, 408, 2918, 282, 3420, 465, 1318, 267, 408, 267, 291, 14, 2792, 847, 413, 267, 291, 14, 21768, 342, 267, 291, 14, 908, 63, 3223, 8, 4209, 9, 267, 340, 291, 14, 6455, 63, 3603, 26, 288, 291, 14, 21768, 342, 288, 367, 1768, 12, 1166, 315, 291, 14, 6455, 63, 3603, 26, 355, 291, 14, 21768, 8, 85, 7, 703, 485, 64, 5, 83, 8340, 450, 83, 7, 450, 334, 1302, 12, 1166, 430, 288, 291, 14, 6455, 63, 3603, 275, 942, 267, 291, 14, 2792, 4862, 413, 267, 291, 14, 21768, 342, 339, 347, 5684, 63, 1213, 8, 277, 12, 7054, 304, 267, 2538, 275, 399, 17067, 904, 8, 513, 8, 277, 14, 3357, 63, 1317, 8, 4209, 1724, 267, 291, 14, 21768, 8, 1213, 9, 267, 862, 26, 288, 291, 14, 21768, 8, 19091, 63, 6131, 540, 23023, 59, 277, 14, 2792, 61, 627, 822, 8, 1213, 430, 267, 871, 7888, 26, 288, 870, 480, 31779, 377, 16507, 2296, 47, 3265, 6102, 14, 377, 1230, 6024, 377, 16507, 12872, 11951, 531, 339, 347, 5684, 63, 12400, 8, 277, 12, 7054, 304, 267, 408, 4200, 282, 13168, 624, 267, 291, 14, 908, 63, 3223, 8, 4209, 9, 267, 291, 14, 21768, 342, 339, 347, 5684, 63, 3751, 8, 277, 12, 7054, 304, 267, 408, 4200, 282, 13598, 624, 267, 291, 14, 908, 63, 3223, 8, 4209, 9, 339, 347, 5684, 63, 1224, 8, 277, 12, 7054, 304, 267, 408, 2918, 282, 1817, 465, 1318, 624, 267, 1817, 63, 1317, 275, 291, 14, 362, 63, 1224, 63, 1317, 8, 4209, 9, 267, 327, 664, 4362, 3462, 267, 8850, 63, 2063, 275, 359, 16, 3672, 552, 8, 1224, 63, 1317, 59, 16, 566, 267, 367, 1962, 315, 1817, 63, 1317, 26, 288, 367, 1478, 315, 1425, 8, 552, 8, 1143, 2298, 355, 1048, 275, 1962, 59, 1080, 61, 355, 8850, 63, 2063, 59, 1080, 61, 275, 1390, 8, 4574, 63, 2063, 59, 1080, 467, 822, 8, 761, 430, 267, 340, 7054, 14, 11645, 508, 283, 698, 356, 288, 291, 14, 698, 63, 1224, 8, 4209, 12, 1817, 63, 1317, 12, 8850, 63, 2063, 9, 267, 587, 26, 288, 291, 14, 885, 63, 1224, 8, 4209, 12, 1817, 63, 1317, 12, 8850, 63, 2063, 9, 267, 291, 14, 21768, 342, 339, 347, 849, 63, 1224, 8, 277, 12, 7054, 12, 1817, 63, 1317, 12, 8850, 63, 2063, 304, 267, 408, 908, 282, 1817, 624, 267, 8850, 63, 2063, 275, 359, 890, 11, 17, 367, 1568, 315, 8850, 63, 2063, 61, 267, 1475, 63, 5465, 275, 399, 7, 1987, 904, 779, 85, 5956, 5, 3295, 385, 418, 627, 822, 8, 4574, 63, 2063, 430, 267, 1475, 63, 5465, 275, 1475, 63, 5465, 450, 2008, 8, 4574, 63, 2063, 9, 267, 1475, 63, 5465, 275, 1475, 63, 5465, 14, 1294, 360, 5320, 267, 1817, 63, 19254, 275, 399, 1154, 78, 4786, 435, 399, 6828, 1370, 904, 779, 85, 12418, 16804, 87, 367, 336, 315, 8850, 63, 2063, 566, 435, 399, 6828, 60, 78, 7, 267, 4854, 4127, 275, 399, 1154, 78, 4786, 435, 399, 6828, 1370, 904, 779, 85, 7, 534, 10, 87, 367, 336, 315, 8850, 63, 2063, 566, 435, 399, 6828, 60, 78, 7, 267, 327, 7600, 26, 7054, 14, 595, 669, 83, 267, 291, 14, 952, 8, 1224, 63, 19254, 9, 267, 367, 284, 315, 1425, 8, 552, 8, 1224, 63, 1317, 2298, 288, 291, 14, 952, 8, 85, 17018, 358, 288, 1004, 275, 1817, 63, 1317, 59, 73, 61, 288, 367, 1335, 315, 1425, 8, 552, 8, 604, 2298, 355, 291, 14, 952, 8, 908, 63, 5465, 59, 74, 61, 450, 1004, 59, 74, 566, 355, 291, 14, 952, 8, 85, 17018, 358, 288, 340, 284 ]
[ 4248, 13004, 13, 8128, 5051, 1193, 1217, 428, 14, 33, 14, 334, 1262, 374, 12, 28671, 7140, 395, 1006, 4481, 4644, 14, 199, 3, 8966, 1455, 921, 1544, 14, 793, 24142, 14, 4391, 15, 1553, 6016, 475, 26, 7811, 32, 793, 24142, 14, 4391, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 943, 24142, 13, 2330, 14, 199, 3, 199, 3, 943, 24142, 13, 2330, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 652, 1334, 199, 3, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 844, 465, 3267, 701, 314, 2868, 199, 3, 2290, 2752, 12, 1902, 1015, 499, 14, 17, 402, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 199, 3, 2945, 1015, 14, 199, 3, 199, 3, 943, 24142, 13, 2330, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 2428, 199, 3, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 3169, 503, 3092, 199, 3, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 6401, 1696, 1684, 844, 367, 1655, 199, 3, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 3180, 199, 3, 543, 943, 24142, 13, 2330, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 624, 1872, 10803, 19016, 367, 399, 15629, 624, 199, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 363, 21841, 363, 275, 298, 26854, 655, 2, 199, 199, 504, 3816, 14, 4912, 492, 1425, 199, 199, 504, 943, 24142, 14, 2330, 14, 505, 1208, 492, 1004, 4127, 199, 504, 943, 24142, 14, 2330, 14, 608, 5203, 492, 3523, 6261, 421, 199, 19091, 63, 6131, 540, 23023, 275, 359, 85, 6448, 399, 7, 4009, 399, 12418, 297, 399, 7, 30880, 399, 1370, 297, 399, 27547, 297, 399, 4289, 418, 199, 34, 3785, 30416, 275, 359, 85, 7, 7693, 399, 12418, 418, 199, 199, 533, 4516, 6261, 8, 1563, 6261, 304, 272, 408, 908, 7054, 83, 465, 1318, 272, 334, 497, 27486, 315, 8721, 1754, 1325, 440, 12657, 1183, 8860, 5966, 9, 272, 408, 272, 347, 5386, 63, 908, 8, 277, 12, 7054, 304, 267, 1613, 8, 1872, 6261, 12, 291, 680, 5037, 63, 908, 8, 4209, 9, 267, 291, 14, 513, 63, 1896, 275, 378, 267, 291, 14, 6455, 63, 3603, 275, 942, 339, 347, 5684, 63, 2792, 8, 277, 12, 7054, 304, 267, 408, 2918, 282, 3420, 465, 1318, 267, 408, 267, 291, 14, 2792, 847, 413, 267, 291, 14, 21768, 342, 267, 291, 14, 908, 63, 3223, 8, 4209, 9, 267, 340, 291, 14, 6455, 63, 3603, 26, 288, 291, 14, 21768, 342, 288, 367, 1768, 12, 1166, 315, 291, 14, 6455, 63, 3603, 26, 355, 291, 14, 21768, 8, 85, 7, 703, 485, 64, 5, 83, 8340, 450, 83, 7, 450, 334, 1302, 12, 1166, 430, 288, 291, 14, 6455, 63, 3603, 275, 942, 267, 291, 14, 2792, 4862, 413, 267, 291, 14, 21768, 342, 339, 347, 5684, 63, 1213, 8, 277, 12, 7054, 304, 267, 2538, 275, 399, 17067, 904, 8, 513, 8, 277, 14, 3357, 63, 1317, 8, 4209, 1724, 267, 291, 14, 21768, 8, 1213, 9, 267, 862, 26, 288, 291, 14, 21768, 8, 19091, 63, 6131, 540, 23023, 59, 277, 14, 2792, 61, 627, 822, 8, 1213, 430, 267, 871, 7888, 26, 288, 870, 480, 31779, 377, 16507, 2296, 47, 3265, 6102, 14, 377, 1230, 6024, 377, 16507, 12872, 11951, 531, 339, 347, 5684, 63, 12400, 8, 277, 12, 7054, 304, 267, 408, 4200, 282, 13168, 624, 267, 291, 14, 908, 63, 3223, 8, 4209, 9, 267, 291, 14, 21768, 342, 339, 347, 5684, 63, 3751, 8, 277, 12, 7054, 304, 267, 408, 4200, 282, 13598, 624, 267, 291, 14, 908, 63, 3223, 8, 4209, 9, 339, 347, 5684, 63, 1224, 8, 277, 12, 7054, 304, 267, 408, 2918, 282, 1817, 465, 1318, 624, 267, 1817, 63, 1317, 275, 291, 14, 362, 63, 1224, 63, 1317, 8, 4209, 9, 267, 327, 664, 4362, 3462, 267, 8850, 63, 2063, 275, 359, 16, 3672, 552, 8, 1224, 63, 1317, 59, 16, 566, 267, 367, 1962, 315, 1817, 63, 1317, 26, 288, 367, 1478, 315, 1425, 8, 552, 8, 1143, 2298, 355, 1048, 275, 1962, 59, 1080, 61, 355, 8850, 63, 2063, 59, 1080, 61, 275, 1390, 8, 4574, 63, 2063, 59, 1080, 467, 822, 8, 761, 430, 267, 340, 7054, 14, 11645, 508, 283, 698, 356, 288, 291, 14, 698, 63, 1224, 8, 4209, 12, 1817, 63, 1317, 12, 8850, 63, 2063, 9, 267, 587, 26, 288, 291, 14, 885, 63, 1224, 8, 4209, 12, 1817, 63, 1317, 12, 8850, 63, 2063, 9, 267, 291, 14, 21768, 342, 339, 347, 849, 63, 1224, 8, 277, 12, 7054, 12, 1817, 63, 1317, 12, 8850, 63, 2063, 304, 267, 408, 908, 282, 1817, 624, 267, 8850, 63, 2063, 275, 359, 890, 11, 17, 367, 1568, 315, 8850, 63, 2063, 61, 267, 1475, 63, 5465, 275, 399, 7, 1987, 904, 779, 85, 5956, 5, 3295, 385, 418, 627, 822, 8, 4574, 63, 2063, 430, 267, 1475, 63, 5465, 275, 1475, 63, 5465, 450, 2008, 8, 4574, 63, 2063, 9, 267, 1475, 63, 5465, 275, 1475, 63, 5465, 14, 1294, 360, 5320, 267, 1817, 63, 19254, 275, 399, 1154, 78, 4786, 435, 399, 6828, 1370, 904, 779, 85, 12418, 16804, 87, 367, 336, 315, 8850, 63, 2063, 566, 435, 399, 6828, 60, 78, 7, 267, 4854, 4127, 275, 399, 1154, 78, 4786, 435, 399, 6828, 1370, 904, 779, 85, 7, 534, 10, 87, 367, 336, 315, 8850, 63, 2063, 566, 435, 399, 6828, 60, 78, 7, 267, 327, 7600, 26, 7054, 14, 595, 669, 83, 267, 291, 14, 952, 8, 1224, 63, 19254, 9, 267, 367, 284, 315, 1425, 8, 552, 8, 1224, 63, 1317, 2298, 288, 291, 14, 952, 8, 85, 17018, 358, 288, 1004, 275, 1817, 63,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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 ]
tombstone/models
research/object_detection/predictors/convolutional_keras_box_predictor_tf2_test.py
2
42980
# 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. # ============================================================================== """Tests for object_detection.predictors.convolutional_keras_box_predictor.""" import unittest import numpy as np import tensorflow.compat.v1 as tf from google.protobuf import text_format from object_detection.builders import box_predictor_builder from object_detection.builders import hyperparams_builder from object_detection.predictors import convolutional_keras_box_predictor as box_predictor from object_detection.predictors.heads import keras_box_head from object_detection.predictors.heads import keras_class_head from object_detection.predictors.heads import keras_mask_head from object_detection.protos import hyperparams_pb2 from object_detection.utils import test_case from object_detection.utils import tf_version @unittest.skipIf(tf_version.is_tf1(), 'Skipping TF2.X only test.') class ConvolutionalKerasBoxPredictorTest(test_case.TestCase): def _build_conv_hyperparams(self): conv_hyperparams = hyperparams_pb2.Hyperparams() conv_hyperparams_text_proto = """ activation: RELU_6 regularizer { l2_regularizer { } } initializer { truncated_normal_initializer { } } """ text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams) return hyperparams_builder.KerasLayerHyperparams(conv_hyperparams) def test_get_boxes_for_five_aspect_ratios_per_location(self): conv_box_predictor = ( box_predictor_builder.build_convolutional_keras_box_predictor( is_training=False, num_classes=0, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5], min_depth=0, max_depth=32, num_layers_before_predictor=1, use_dropout=True, dropout_keep_prob=0.8, kernel_size=1, box_code_size=4 )) def graph_fn(image_features): box_predictions = conv_box_predictor([image_features]) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute(graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 320, 1]) def test_get_boxes_for_one_aspect_ratio_per_location(self): conv_box_predictor = ( box_predictor_builder.build_convolutional_keras_box_predictor( is_training=False, num_classes=0, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[1], min_depth=0, max_depth=32, num_layers_before_predictor=1, use_dropout=True, dropout_keep_prob=0.8, kernel_size=1, box_code_size=4 )) def graph_fn(image_features): box_predictions = conv_box_predictor([image_features]) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute(graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 64, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 64, 1]) def test_get_multi_class_predictions_for_five_aspect_ratios_per_location( self): num_classes_without_background = 6 image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) conv_box_predictor = ( box_predictor_builder.build_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5], min_depth=0, max_depth=32, num_layers_before_predictor=1, use_dropout=True, dropout_keep_prob=0.8, kernel_size=1, box_code_size=4 )) def graph_fn(image_features): box_predictions = conv_box_predictor([image_features]) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) (box_encodings, class_predictions_with_background) = self.execute(graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 320, num_classes_without_background+1]) def test_get_predictions_with_feature_maps_of_dynamic_shape( self): tf.keras.backend.clear_session() conv_box_predictor = ( box_predictor_builder.build_convolutional_keras_box_predictor( is_training=False, num_classes=0, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5], min_depth=0, max_depth=32, num_layers_before_predictor=1, use_dropout=True, dropout_keep_prob=0.8, kernel_size=1, box_code_size=4 )) variables = [] def graph_fn(image_features): box_predictions = conv_box_predictor([image_features]) variables.extend(list(conv_box_predictor.variables)) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return box_encodings, objectness_predictions resolution = 32 expected_num_anchors = resolution*resolution*5 box_encodings, objectness_predictions = self.execute( graph_fn, [np.random.rand(4, resolution, resolution, 64)]) actual_variable_set = set([var.name.split(':')[0] for var in variables]) self.assertAllEqual(box_encodings.shape, [4, expected_num_anchors, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, expected_num_anchors, 1]) expected_variable_set = set([ 'BoxPredictor/SharedConvolutions_0/Conv2d_0_1x1_32/bias', 'BoxPredictor/SharedConvolutions_0/Conv2d_0_1x1_32/kernel', 'BoxPredictor/ConvolutionalBoxHead_0/BoxEncodingPredictor/bias', 'BoxPredictor/ConvolutionalBoxHead_0/BoxEncodingPredictor/kernel', 'BoxPredictor/ConvolutionalClassHead_0/ClassPredictor/bias', 'BoxPredictor/ConvolutionalClassHead_0/ClassPredictor/kernel']) self.assertEqual(expected_variable_set, actual_variable_set) self.assertEqual(conv_box_predictor._sorted_head_names, ['box_encodings', 'class_predictions_with_background']) def test_use_depthwise_convolution(self): tf.keras.backend.clear_session() conv_box_predictor = ( box_predictor_builder.build_convolutional_keras_box_predictor( is_training=False, num_classes=0, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5], min_depth=0, max_depth=32, num_layers_before_predictor=1, use_dropout=True, dropout_keep_prob=0.8, kernel_size=3, box_code_size=4, use_depthwise=True )) variables = [] def graph_fn(image_features): box_predictions = conv_box_predictor([image_features]) variables.extend(list(conv_box_predictor.variables)) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return box_encodings, objectness_predictions resolution = 32 expected_num_anchors = resolution*resolution*5 box_encodings, objectness_predictions = self.execute( graph_fn, [np.random.rand(4, resolution, resolution, 64)]) actual_variable_set = set([var.name.split(':')[0] for var in variables]) self.assertAllEqual(box_encodings.shape, [4, expected_num_anchors, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, expected_num_anchors, 1]) expected_variable_set = set([ 'BoxPredictor/SharedConvolutions_0/Conv2d_0_1x1_32/bias', 'BoxPredictor/SharedConvolutions_0/Conv2d_0_1x1_32/kernel', 'BoxPredictor/ConvolutionalBoxHead_0/BoxEncodingPredictor_depthwise/' 'bias', 'BoxPredictor/ConvolutionalBoxHead_0/BoxEncodingPredictor_depthwise/' 'depthwise_kernel', 'BoxPredictor/ConvolutionalBoxHead_0/BoxEncodingPredictor/bias', 'BoxPredictor/ConvolutionalBoxHead_0/BoxEncodingPredictor/kernel', 'BoxPredictor/ConvolutionalClassHead_0/ClassPredictor_depthwise/bias', 'BoxPredictor/ConvolutionalClassHead_0/ClassPredictor_depthwise/' 'depthwise_kernel', 'BoxPredictor/ConvolutionalClassHead_0/ClassPredictor/bias', 'BoxPredictor/ConvolutionalClassHead_0/ClassPredictor/kernel']) self.assertEqual(expected_variable_set, actual_variable_set) self.assertEqual(conv_box_predictor._sorted_head_names, ['box_encodings', 'class_predictions_with_background']) @unittest.skipIf(tf_version.is_tf1(), 'Skipping TF2.X only test.') class WeightSharedConvolutionalKerasBoxPredictorTest(test_case.TestCase): def _build_conv_hyperparams(self, add_batch_norm=True): conv_hyperparams = hyperparams_pb2.Hyperparams() conv_hyperparams_text_proto = """ activation: RELU_6 regularizer { l2_regularizer { } } initializer { truncated_normal_initializer { stddev: 0.01 mean: 0.0 } } """ if add_batch_norm: batch_norm_proto = """ batch_norm { train: true, } """ conv_hyperparams_text_proto += batch_norm_proto text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams) return hyperparams_builder.KerasLayerHyperparams(conv_hyperparams) # pylint: disable=line-too-long def test_get_boxes_for_five_aspect_ratios_per_location(self): conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=0, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5], depth=32, num_layers_before_predictor=1, box_code_size=4)) def graph_fn(image_features): box_predictions = conv_box_predictor([image_features]) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 320, 1]) def test_bias_predictions_to_background_with_sigmoid_score_conversion(self): conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=True, num_classes=2, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5], depth=32, num_layers_before_predictor=1, class_prediction_bias_init=-4.6, box_code_size=4)) def graph_fn(image_features): box_predictions = conv_box_predictor([image_features]) class_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (tf.nn.sigmoid(class_predictions),) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) class_predictions = self.execute(graph_fn, [image_features]) self.assertAlmostEqual(np.mean(class_predictions), 0.01, places=3) def test_get_multi_class_predictions_for_five_aspect_ratios_per_location( self): num_classes_without_background = 6 conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5], depth=32, num_layers_before_predictor=1, box_code_size=4)) def graph_fn(image_features): box_predictions = conv_box_predictor([image_features]) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 320, num_classes_without_background+1]) def test_get_multi_class_predictions_from_two_feature_maps( self): num_classes_without_background = 6 conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5, 5], depth=32, num_layers_before_predictor=1, box_code_size=4)) def graph_fn(image_features1, image_features2): box_predictions = conv_box_predictor([image_features1, image_features2]) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features1 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features2 = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features1, image_features2]) self.assertAllEqual(box_encodings.shape, [4, 640, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 640, num_classes_without_background+1]) def test_get_multi_class_predictions_from_feature_maps_of_different_depth( self): num_classes_without_background = 6 conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5, 5, 5], depth=32, num_layers_before_predictor=1, box_code_size=4)) def graph_fn(image_features1, image_features2, image_features3): box_predictions = conv_box_predictor( [image_features1, image_features2, image_features3]) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features1 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features2 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features3 = np.random.rand(4, 8, 8, 32).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features1, image_features2, image_features3]) self.assertAllEqual(box_encodings.shape, [4, 960, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 960, num_classes_without_background+1]) def test_predictions_multiple_feature_maps_share_weights_separate_batchnorm( self): tf.keras.backend.clear_session() num_classes_without_background = 6 conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5, 5], depth=32, num_layers_before_predictor=2, box_code_size=4)) variables = [] def graph_fn(image_features1, image_features2): box_predictions = conv_box_predictor([image_features1, image_features2]) variables.extend(list(conv_box_predictor.variables)) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) self.execute(graph_fn, [ np.random.rand(4, 32, 32, 3).astype(np.float32), np.random.rand(4, 16, 16, 3).astype(np.float32) ]) actual_variable_set = set([var.name.split(':')[0] for var in variables]) expected_variable_set = set([ # Box prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/BatchNorm/feature_0/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/BatchNorm/feature_0/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/BatchNorm/feature_0/moving_variance'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/BatchNorm/feature_1/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/BatchNorm/feature_1/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/BatchNorm/feature_1/moving_variance'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/BatchNorm/feature_0/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/BatchNorm/feature_0/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/BatchNorm/feature_0/moving_variance'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/BatchNorm/feature_1/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/BatchNorm/feature_1/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/BatchNorm/feature_1/moving_variance'), # Box prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/bias'), # Class prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/BatchNorm/feature_0/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/BatchNorm/feature_0/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/BatchNorm/feature_0/moving_variance'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/BatchNorm/feature_1/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/BatchNorm/feature_1/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/BatchNorm/feature_1/moving_variance'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/BatchNorm/feature_0/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/BatchNorm/feature_0/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/BatchNorm/feature_0/moving_variance'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/BatchNorm/feature_1/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/BatchNorm/feature_1/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/BatchNorm/feature_1/moving_variance'), # Class prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/bias')]) self.assertEqual(expected_variable_set, actual_variable_set) def test_predictions_multiple_feature_maps_share_weights_without_batchnorm( self): tf.keras.backend.clear_session() num_classes_without_background = 6 conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5, 5], depth=32, num_layers_before_predictor=2, box_code_size=4, apply_batch_norm=False)) variables = [] def graph_fn(image_features1, image_features2): box_predictions = conv_box_predictor([image_features1, image_features2]) variables.extend(list(conv_box_predictor.variables)) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) self.execute(graph_fn, [ np.random.rand(4, 32, 32, 3).astype(np.float32), np.random.rand(4, 16, 16, 3).astype(np.float32) ]) actual_variable_set = set([var.name.split(':')[0] for var in variables]) expected_variable_set = set([ # Box prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/bias'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/bias'), # Box prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/bias'), # Class prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/bias'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/bias'), # Class prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/bias')]) self.assertEqual(expected_variable_set, actual_variable_set) def test_predictions_multiple_feature_maps_share_weights_with_depthwise( self): tf.keras.backend.clear_session() num_classes_without_background = 6 conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(add_batch_norm=False), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5, 5], depth=32, num_layers_before_predictor=2, box_code_size=4, apply_batch_norm=False, use_depthwise=True)) variables = [] def graph_fn(image_features1, image_features2): box_predictions = conv_box_predictor([image_features1, image_features2]) variables.extend(list(conv_box_predictor.variables)) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) self.execute(graph_fn, [ np.random.rand(4, 32, 32, 3).astype(np.float32), np.random.rand(4, 16, 16, 3).astype(np.float32) ]) actual_variable_set = set([var.name.split(':')[0] for var in variables]) expected_variable_set = set([ # Box prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/depthwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/pointwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/bias'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/depthwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/pointwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/bias'), # Box prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/depthwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/pointwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/bias'), # Class prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/depthwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/pointwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/bias'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/depthwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/pointwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/bias'), # Class prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/depthwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/pointwise_kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/bias')]) self.assertEqual(expected_variable_set, actual_variable_set) def test_no_batchnorm_params_when_batchnorm_is_not_configured(self): tf.keras.backend.clear_session() num_classes_without_background = 6 conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(add_batch_norm=False), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5, 5], depth=32, num_layers_before_predictor=2, box_code_size=4, apply_batch_norm=False)) variables = [] def graph_fn(image_features1, image_features2): box_predictions = conv_box_predictor( [image_features1, image_features2]) variables.extend(list(conv_box_predictor.variables)) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) self.execute(graph_fn, [ np.random.rand(4, 32, 32, 3).astype(np.float32), np.random.rand(4, 16, 16, 3).astype(np.float32) ]) actual_variable_set = set([var.name.split(':')[0] for var in variables]) expected_variable_set = set([ # Box prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_0/bias'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'BoxPredictionTower/conv2d_1/bias'), # Box prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/bias'), # Class prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/bias'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/bias'), # Class prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/bias')]) self.assertEqual(expected_variable_set, actual_variable_set) def test_predictions_share_weights_share_tower_separate_batchnorm( self): tf.keras.backend.clear_session() num_classes_without_background = 6 conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5, 5], depth=32, num_layers_before_predictor=2, box_code_size=4, share_prediction_tower=True)) variables = [] def graph_fn(image_features1, image_features2): box_predictions = conv_box_predictor( [image_features1, image_features2]) variables.extend(list(conv_box_predictor.variables)) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) self.execute(graph_fn, [ np.random.rand(4, 32, 32, 3).astype(np.float32), np.random.rand(4, 16, 16, 3).astype(np.float32) ]) actual_variable_set = set([var.name.split(':')[0] for var in variables]) expected_variable_set = set([ # Shared prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_0/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_0/BatchNorm/feature_0/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_0/BatchNorm/feature_1/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_0/BatchNorm/feature_0/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_0/BatchNorm/feature_1/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_0/BatchNorm/feature_0/moving_variance'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_0/BatchNorm/feature_1/moving_variance'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_1/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_1/BatchNorm/feature_0/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_1/BatchNorm/feature_1/beta'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_1/BatchNorm/feature_0/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_1/BatchNorm/feature_1/moving_mean'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_1/BatchNorm/feature_0/moving_variance'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_1/BatchNorm/feature_1/moving_variance'), # Box prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/bias'), # Class prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/bias')]) self.assertEqual(expected_variable_set, actual_variable_set) def test_predictions_share_weights_share_tower_without_batchnorm( self): tf.keras.backend.clear_session() num_classes_without_background = 6 conv_box_predictor = ( box_predictor_builder .build_weight_shared_convolutional_keras_box_predictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(add_batch_norm=False), freeze_batchnorm=False, inplace_batchnorm_update=False, num_predictions_per_location_list=[5, 5], depth=32, num_layers_before_predictor=2, box_code_size=4, share_prediction_tower=True, apply_batch_norm=False)) variables = [] def graph_fn(image_features1, image_features2): box_predictions = conv_box_predictor( [image_features1, image_features2]) variables.extend(list(conv_box_predictor.variables)) box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) self.execute(graph_fn, [ np.random.rand(4, 32, 32, 3).astype(np.float32), np.random.rand(4, 16, 16, 3).astype(np.float32) ]) actual_variable_set = set([var.name.split(':')[0] for var in variables]) expected_variable_set = set([ # Shared prediction tower ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_0/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_0/bias'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_1/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'PredictionTower/conv2d_1/bias'), # Box prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalBoxHead/BoxPredictor/bias'), # Class prediction head ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/kernel'), ('WeightSharedConvolutionalBoxPredictor/' 'WeightSharedConvolutionalClassHead/ClassPredictor/bias')]) self.assertEqual(expected_variable_set, actual_variable_set) def test_other_heads_predictions(self): box_code_size = 4 num_classes_without_background = 3 other_head_name = 'Mask' mask_height = 5 mask_width = 5 num_predictions_per_location = 5 box_prediction_head = keras_box_head.WeightSharedConvolutionalBoxHead( box_code_size=box_code_size, conv_hyperparams=self._build_conv_hyperparams(), num_predictions_per_location=num_predictions_per_location) class_prediction_head = keras_class_head.WeightSharedConvolutionalClassHead( num_class_slots=num_classes_without_background + 1, conv_hyperparams=self._build_conv_hyperparams(), num_predictions_per_location=num_predictions_per_location) other_heads = { other_head_name: keras_mask_head.WeightSharedConvolutionalMaskHead( num_classes=num_classes_without_background, conv_hyperparams=self._build_conv_hyperparams(), num_predictions_per_location=num_predictions_per_location, mask_height=mask_height, mask_width=mask_width) } conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, box_prediction_head=box_prediction_head, class_prediction_head=class_prediction_head, other_heads=other_heads, conv_hyperparams=self._build_conv_hyperparams(), freeze_batchnorm=False, inplace_batchnorm_update=False, depth=32, num_layers_before_predictor=2) def graph_fn(image_features): box_predictions = conv_box_predictor([image_features]) for key, value in box_predictions.items(): box_predictions[key] = tf.concat(value, axis=1) assert len(box_predictions) == 3 return (box_predictions[box_predictor.BOX_ENCODINGS], box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], box_predictions[other_head_name]) batch_size = 4 feature_ht = 8 feature_wt = 8 image_features = np.random.rand(batch_size, feature_ht, feature_wt, 64).astype(np.float32) (box_encodings, class_predictions, other_head_predictions) = self.execute( graph_fn, [image_features]) num_anchors = feature_ht * feature_wt * num_predictions_per_location self.assertAllEqual(box_encodings.shape, [batch_size, num_anchors, box_code_size]) self.assertAllEqual( class_predictions.shape, [batch_size, num_anchors, num_classes_without_background + 1]) self.assertAllEqual(other_head_predictions.shape, [ batch_size, num_anchors, num_classes_without_background, mask_height, mask_width ]) if __name__ == '__main__': tf.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, 199, 624, 2925, 367, 909, 63, 11934, 14, 5790, 13451, 14, 27625, 279, 63, 8811, 63, 1977, 63, 5790, 630, 1041, 199, 646, 2882, 199, 646, 2680, 465, 980, 199, 646, 3228, 14, 5819, 14, 86, 17, 465, 2833, 199, 199, 504, 6233, 14, 7204, 492, 1318, 63, 908, 199, 504, 909, 63, 11934, 14, 20968, 492, 5689, 63, 5790, 630, 63, 5649, 199, 504, 909, 63, 11934, 14, 20968, 492, 10342, 1162, 63, 5649, 199, 504, 909, 63, 11934, 14, 5790, 13451, 492, 17461, 279, 63, 8811, 63, 1977, 63, 5790, 630, 465, 5689, 63, 5790, 630, 199, 504, 909, 63, 11934, 14, 5790, 13451, 14, 17033, 492, 11708, 63, 1977, 63, 2993, 199, 504, 909, 63, 11934, 14, 5790, 13451, 14, 17033, 492, 11708, 63, 533, 63, 2993, 199, 504, 909, 63, 11934, 14, 5790, 13451, 14, 17033, 492, 11708, 63, 2629, 63, 2993, 199, 504, 909, 63, 11934, 14, 27478, 492, 10342, 1162, 63, 3317, 18, 199, 504, 909, 63, 11934, 14, 1208, 492, 511, 63, 2546, 199, 504, 909, 63, 11934, 14, 1208, 492, 2833, 63, 1023, 421, 199, 32, 2796, 14, 15118, 8, 3249, 63, 1023, 14, 374, 63, 3249, 17, 1062, 283, 18297, 21721, 18, 14, 56, 1454, 511, 2659, 199, 533, 19140, 3347, 279, 43, 30037, 3532, 14730, 630, 774, 8, 396, 63, 2546, 14, 1746, 304, 819, 347, 485, 1506, 63, 5598, 63, 9547, 1162, 8, 277, 304, 272, 8260, 63, 9547, 1162, 275, 10342, 1162, 63, 3317, 18, 14, 18727, 1162, 342, 272, 8260, 63, 9547, 1162, 63, 505, 63, 2625, 275, 408, 489, 10361, 26, 820, 2901, 53, 63, 22, 489, 31841, 469, 267, 634, 18, 63, 14044, 469, 267, 789, 489, 789, 489, 11130, 469, 267, 17661, 63, 3302, 63, 6498, 469, 267, 789, 489, 789, 272, 408, 272, 1318, 63, 908, 14, 11359, 8, 5598, 63, 9547, 1162, 63, 505, 63, 2625, 12, 8260, 63, 9547, 1162, 9, 272, 372, 10342, 1162, 63, 5649, 14, 43, 30037, 5003, 18727, 1162, 8, 5598, 63, 9547, 1162, 9, 819, 347, 511, 63, 362, 63, 12922, 63, 509, 63, 23702, 63, 18658, 63, 345, 9636, 63, 529, 63, 1985, 8, 277, 304, 272, 8260, 63, 1977, 63, 5790, 630, 275, 334, 267, 5689, 63, 5790, 630, 63, 5649, 14, 1506, 63, 27625, 279, 63, 8811, 63, 1977, 63, 5790, 630, 8, 288, 365, 63, 7588, 29, 797, 12, 288, 1967, 63, 2888, 29, 16, 12, 288, 8260, 63, 9547, 1162, 29, 277, 423, 1506, 63, 5598, 63, 9547, 1162, 1062, 288, 22778, 63, 2912, 4791, 29, 797, 12, 288, 16304, 63, 2912, 4791, 63, 873, 29, 797, 12, 288, 1967, 63, 9869, 63, 529, 63, 1985, 63, 513, 1524, 21, 467, 288, 1748, 63, 4631, 29, 16, 12, 288, 1390, 63, 4631, 29, 708, 12, 288, 1967, 63, 4359, 63, 5182, 63, 5790, 630, 29, 17, 12, 288, 675, 63, 17953, 29, 549, 12, 288, 19795, 63, 3250, 63, 6101, 29, 16, 14, 24, 12, 288, 5114, 63, 890, 29, 17, 12, 288, 5689, 63, 600, 63, 890, 29, 20, 267, 5082, 272, 347, 3343, 63, 2324, 8, 1569, 63, 3179, 304, 489, 5689, 63, 9869, 275, 8260, 63, 1977, 63, 5790, 630, 779, 1569, 63, 3179, 566, 489, 5689, 63, 21138, 275, 2833, 14, 9419, 8, 881, 5689, 63, 9869, 59, 1977, 63, 5790, 630, 14, 15694, 63, 742, 12592, 3881, 467, 3114, 29, 17, 9, 489, 909, 4171, 63, 9869, 275, 2833, 14, 9419, 8, 881, 5689, 63, 9869, 59, 1977, 63, 5790, 630, 14, 6885, 63, 4225, 12511, 2823, 63, 9139, 63, 7111, 29497, 467, 881, 3114, 29, 17, 9, 489, 372, 334, 1977, 63, 21138, 12, 909, 4171, 63, 9869, 9, 272, 1834, 63, 3179, 275, 980, 14, 2355, 14, 3759, 8, 20, 12, 1695, 12, 1695, 12, 5049, 680, 6041, 8, 1590, 14, 1609, 708, 9, 272, 334, 1977, 63, 21138, 12, 909, 4171, 63, 9869, 9, 275, 291, 14, 2526, 8, 2180, 63, 2324, 12, 15491, 359, 1569, 63, 3179, 566, 272, 291, 14, 7069, 8, 1977, 63, 21138, 14, 1392, 12, 359, 20, 12, 25611, 12, 413, 12, 841, 566, 272, 291, 14, 7069, 8, 785, 4171, 63, 9869, 14, 1392, 12, 359, 20, 12, 25611, 12, 413, 566, 819, 347, 511, 63, 362, 63, 12922, 63, 509, 63, 368, 63, 18658, 63, 6884, 63, 529, 63, 1985, 8, 277, 304, 272, 8260, 63, 1977, 63, 5790, 630, 275, 334, 267, 5689, 63, 5790, 630, 63, 5649, 14, 1506, 63, 27625, 279, 63, 8811, 63, 1977, 63, 5790, 630, 8, 288, 365, 63, 7588, 29, 797, 12, 288, 1967, 63, 2888, 29, 16, 12, 288, 8260, 63, 9547, 1162, 29, 277, 423, 1506, 63, 5598, 63, 9547, 1162, 1062, 288, 22778, 63, 2912, 4791, 29, 797, 12, 288, 16304, 63, 2912, 4791, 63, 873, 29, 797, 12, 288, 1967, 63, 9869, 63, 529, 63, 1985, 63, 513, 1524, 17, 467, 288, 1748, 63, 4631, 29, 16, 12, 288, 1390, 63, 4631, 29, 708, 12, 288, 1967, 63, 4359, 63, 5182, 63, 5790, 630, 29, 17, 12, 288, 675, 63, 17953, 29, 549, 12, 288, 19795, 63, 3250, 63, 6101, 29, 16, 14, 24, 12, 288, 5114, 63, 890, 29, 17, 12, 288, 5689, 63, 600, 63, 890, 29, 20, 267, 5082, 272 ]
[ 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, 199, 624, 2925, 367, 909, 63, 11934, 14, 5790, 13451, 14, 27625, 279, 63, 8811, 63, 1977, 63, 5790, 630, 1041, 199, 646, 2882, 199, 646, 2680, 465, 980, 199, 646, 3228, 14, 5819, 14, 86, 17, 465, 2833, 199, 199, 504, 6233, 14, 7204, 492, 1318, 63, 908, 199, 504, 909, 63, 11934, 14, 20968, 492, 5689, 63, 5790, 630, 63, 5649, 199, 504, 909, 63, 11934, 14, 20968, 492, 10342, 1162, 63, 5649, 199, 504, 909, 63, 11934, 14, 5790, 13451, 492, 17461, 279, 63, 8811, 63, 1977, 63, 5790, 630, 465, 5689, 63, 5790, 630, 199, 504, 909, 63, 11934, 14, 5790, 13451, 14, 17033, 492, 11708, 63, 1977, 63, 2993, 199, 504, 909, 63, 11934, 14, 5790, 13451, 14, 17033, 492, 11708, 63, 533, 63, 2993, 199, 504, 909, 63, 11934, 14, 5790, 13451, 14, 17033, 492, 11708, 63, 2629, 63, 2993, 199, 504, 909, 63, 11934, 14, 27478, 492, 10342, 1162, 63, 3317, 18, 199, 504, 909, 63, 11934, 14, 1208, 492, 511, 63, 2546, 199, 504, 909, 63, 11934, 14, 1208, 492, 2833, 63, 1023, 421, 199, 32, 2796, 14, 15118, 8, 3249, 63, 1023, 14, 374, 63, 3249, 17, 1062, 283, 18297, 21721, 18, 14, 56, 1454, 511, 2659, 199, 533, 19140, 3347, 279, 43, 30037, 3532, 14730, 630, 774, 8, 396, 63, 2546, 14, 1746, 304, 819, 347, 485, 1506, 63, 5598, 63, 9547, 1162, 8, 277, 304, 272, 8260, 63, 9547, 1162, 275, 10342, 1162, 63, 3317, 18, 14, 18727, 1162, 342, 272, 8260, 63, 9547, 1162, 63, 505, 63, 2625, 275, 408, 489, 10361, 26, 820, 2901, 53, 63, 22, 489, 31841, 469, 267, 634, 18, 63, 14044, 469, 267, 789, 489, 789, 489, 11130, 469, 267, 17661, 63, 3302, 63, 6498, 469, 267, 789, 489, 789, 272, 408, 272, 1318, 63, 908, 14, 11359, 8, 5598, 63, 9547, 1162, 63, 505, 63, 2625, 12, 8260, 63, 9547, 1162, 9, 272, 372, 10342, 1162, 63, 5649, 14, 43, 30037, 5003, 18727, 1162, 8, 5598, 63, 9547, 1162, 9, 819, 347, 511, 63, 362, 63, 12922, 63, 509, 63, 23702, 63, 18658, 63, 345, 9636, 63, 529, 63, 1985, 8, 277, 304, 272, 8260, 63, 1977, 63, 5790, 630, 275, 334, 267, 5689, 63, 5790, 630, 63, 5649, 14, 1506, 63, 27625, 279, 63, 8811, 63, 1977, 63, 5790, 630, 8, 288, 365, 63, 7588, 29, 797, 12, 288, 1967, 63, 2888, 29, 16, 12, 288, 8260, 63, 9547, 1162, 29, 277, 423, 1506, 63, 5598, 63, 9547, 1162, 1062, 288, 22778, 63, 2912, 4791, 29, 797, 12, 288, 16304, 63, 2912, 4791, 63, 873, 29, 797, 12, 288, 1967, 63, 9869, 63, 529, 63, 1985, 63, 513, 1524, 21, 467, 288, 1748, 63, 4631, 29, 16, 12, 288, 1390, 63, 4631, 29, 708, 12, 288, 1967, 63, 4359, 63, 5182, 63, 5790, 630, 29, 17, 12, 288, 675, 63, 17953, 29, 549, 12, 288, 19795, 63, 3250, 63, 6101, 29, 16, 14, 24, 12, 288, 5114, 63, 890, 29, 17, 12, 288, 5689, 63, 600, 63, 890, 29, 20, 267, 5082, 272, 347, 3343, 63, 2324, 8, 1569, 63, 3179, 304, 489, 5689, 63, 9869, 275, 8260, 63, 1977, 63, 5790, 630, 779, 1569, 63, 3179, 566, 489, 5689, 63, 21138, 275, 2833, 14, 9419, 8, 881, 5689, 63, 9869, 59, 1977, 63, 5790, 630, 14, 15694, 63, 742, 12592, 3881, 467, 3114, 29, 17, 9, 489, 909, 4171, 63, 9869, 275, 2833, 14, 9419, 8, 881, 5689, 63, 9869, 59, 1977, 63, 5790, 630, 14, 6885, 63, 4225, 12511, 2823, 63, 9139, 63, 7111, 29497, 467, 881, 3114, 29, 17, 9, 489, 372, 334, 1977, 63, 21138, 12, 909, 4171, 63, 9869, 9, 272, 1834, 63, 3179, 275, 980, 14, 2355, 14, 3759, 8, 20, 12, 1695, 12, 1695, 12, 5049, 680, 6041, 8, 1590, 14, 1609, 708, 9, 272, 334, 1977, 63, 21138, 12, 909, 4171, 63, 9869, 9, 275, 291, 14, 2526, 8, 2180, 63, 2324, 12, 15491, 359, 1569, 63, 3179, 566, 272, 291, 14, 7069, 8, 1977, 63, 21138, 14, 1392, 12, 359, 20, 12, 25611, 12, 413, 12, 841, 566, 272, 291, 14, 7069, 8, 785, 4171, 63, 9869, 14, 1392, 12, 359, 20, 12, 25611, 12, 413, 566, 819, 347, 511, 63, 362, 63, 12922, 63, 509, 63, 368, 63, 18658, 63, 6884, 63, 529, 63, 1985, 8, 277, 304, 272, 8260, 63, 1977, 63, 5790, 630, 275, 334, 267, 5689, 63, 5790, 630, 63, 5649, 14, 1506, 63, 27625, 279, 63, 8811, 63, 1977, 63, 5790, 630, 8, 288, 365, 63, 7588, 29, 797, 12, 288, 1967, 63, 2888, 29, 16, 12, 288, 8260, 63, 9547, 1162, 29, 277, 423, 1506, 63, 5598, 63, 9547, 1162, 1062, 288, 22778, 63, 2912, 4791, 29, 797, 12, 288, 16304, 63, 2912, 4791, 63, 873, 29, 797, 12, 288, 1967, 63, 9869, 63, 529, 63, 1985, 63, 513, 1524, 17, 467, 288, 1748, 63, 4631, 29, 16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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 ]
JohnKendrick/PDielec
PDielec/pickled_reader.py
1
1689
#!/usr/bin/env python """Read the contents of a directory containing DFT output and create a csv style file of information""" from __future__ import print_function import sys import dill as pickle import PDielec.__init__ version = PDielec.__init__.__version__ def print_help(): print('pickled_reader filenames', file=sys.stderr) print(' Read in a pickled (actually using dill to pickle the object) reader ', file=sys.stderr) print(' The pickled file should have been created using preader -pickle ', file=sys.stderr) print(' Version ',version,file=sys.stderr) exit() def main(): # # Print out the help file if there is nothing else on the command line # if len(sys.argv) <= 1 : print_help() # # Read in the pickled reader objects from the dump file # picklefile = sys.argv[1] # # store each reader in a list # readers = [] # # Open the pickled file as binary and for reading only # keep reading until we reach an end of file # with open(picklefile,'rb') as f: try: while True: readers.append(pickle.load(f)) except EOFError: pass # print('Read in {} readers'.format(len(readers))) # # Loop over the readers and print out some information - assign a variable # for reader in readers: print('NEW READER type={}, file={}'.format(reader.type,reader.names[0])) reader.print_info() print('LAST CELL') lastcell = reader.unit_cells[-1] lastcell.print_info() # End of for loop over readers # end of def main if __name__ == "__main__": main()
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 624, 3284, 314, 4072, 402, 282, 2082, 3035, 577, 2161, 1072, 436, 1218, 282, 7392, 3449, 570, 402, 2556, 624, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 646, 984, 199, 646, 487, 914, 465, 5927, 199, 646, 510, 1341, 8081, 67, 855, 826, 363, 199, 1023, 275, 510, 1341, 8081, 67, 855, 826, 4914, 1023, 363, 199, 199, 318, 870, 63, 3437, 837, 272, 870, 360, 20428, 63, 5503, 6203, 297, 570, 29, 1274, 14, 3083, 9, 272, 870, 360, 221, 5574, 315, 282, 18731, 334, 2442, 3163, 1808, 487, 914, 370, 5927, 314, 909, 9, 7002, 3322, 1656, 570, 29, 1274, 14, 3083, 9, 272, 870, 360, 221, 710, 18731, 570, 1077, 1172, 2757, 2737, 1808, 876, 669, 446, 8092, 4483, 1656, 570, 29, 1274, 14, 3083, 9, 272, 870, 360, 221, 3394, 1656, 1023, 12, 493, 29, 1274, 14, 3083, 9, 272, 4458, 342, 199, 199, 318, 2446, 837, 272, 327, 272, 327, 9101, 734, 314, 1720, 570, 340, 2337, 365, 6548, 587, 641, 314, 1414, 1004, 272, 327, 272, 340, 822, 8, 1274, 14, 3020, 9, 2695, 413, 520, 267, 870, 63, 3437, 342, 272, 327, 272, 327, 5574, 315, 314, 18731, 7002, 2251, 687, 314, 5461, 570, 272, 327, 272, 5927, 493, 275, 984, 14, 3020, 59, 17, 61, 272, 327, 272, 327, 3877, 1924, 7002, 315, 282, 769, 272, 327, 272, 7002, 83, 275, 942, 272, 327, 272, 327, 3232, 314, 18731, 570, 465, 3366, 436, 367, 7664, 1454, 272, 327, 4215, 7664, 5133, 781, 12276, 376, 1284, 402, 570, 272, 327, 272, 543, 1551, 8, 8092, 493, 2584, 4848, 358, 465, 289, 26, 267, 862, 26, 288, 1830, 715, 26, 355, 7002, 83, 14, 740, 8, 8092, 14, 912, 8, 70, 430, 267, 871, 21157, 26, 288, 986, 272, 327, 272, 870, 360, 3284, 315, 1052, 7002, 83, 1370, 908, 8, 552, 8, 27056, 1724, 272, 327, 272, 327, 18175, 1806, 314, 7002, 83, 436, 870, 734, 2005, 2556, 446, 5090, 282, 1750, 272, 327, 272, 367, 7002, 315, 7002, 83, 26, 267, 870, 360, 11365, 16767, 540, 730, 10324, 570, 27244, 908, 8, 5503, 14, 466, 12, 5503, 14, 1247, 59, 16, 2459, 267, 7002, 14, 1361, 63, 815, 342, 267, 870, 360, 16901, 445, 14952, 358, 267, 2061, 3890, 275, 7002, 14, 3248, 63, 9041, 1988, 17, 61, 267, 2061, 3890, 14, 1361, 63, 815, 342, 272, 327, 9599, 402, 367, 4438, 1806, 7002, 83, 199, 3, 1284, 402, 347, 2446, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 624, 3284, 314, 4072, 402, 282, 2082, 3035, 577, 2161, 1072, 436, 1218, 282, 7392, 3449, 570, 402, 2556, 624, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 646, 984, 199, 646, 487, 914, 465, 5927, 199, 646, 510, 1341, 8081, 67, 855, 826, 363, 199, 1023, 275, 510, 1341, 8081, 67, 855, 826, 4914, 1023, 363, 199, 199, 318, 870, 63, 3437, 837, 272, 870, 360, 20428, 63, 5503, 6203, 297, 570, 29, 1274, 14, 3083, 9, 272, 870, 360, 221, 5574, 315, 282, 18731, 334, 2442, 3163, 1808, 487, 914, 370, 5927, 314, 909, 9, 7002, 3322, 1656, 570, 29, 1274, 14, 3083, 9, 272, 870, 360, 221, 710, 18731, 570, 1077, 1172, 2757, 2737, 1808, 876, 669, 446, 8092, 4483, 1656, 570, 29, 1274, 14, 3083, 9, 272, 870, 360, 221, 3394, 1656, 1023, 12, 493, 29, 1274, 14, 3083, 9, 272, 4458, 342, 199, 199, 318, 2446, 837, 272, 327, 272, 327, 9101, 734, 314, 1720, 570, 340, 2337, 365, 6548, 587, 641, 314, 1414, 1004, 272, 327, 272, 340, 822, 8, 1274, 14, 3020, 9, 2695, 413, 520, 267, 870, 63, 3437, 342, 272, 327, 272, 327, 5574, 315, 314, 18731, 7002, 2251, 687, 314, 5461, 570, 272, 327, 272, 5927, 493, 275, 984, 14, 3020, 59, 17, 61, 272, 327, 272, 327, 3877, 1924, 7002, 315, 282, 769, 272, 327, 272, 7002, 83, 275, 942, 272, 327, 272, 327, 3232, 314, 18731, 570, 465, 3366, 436, 367, 7664, 1454, 272, 327, 4215, 7664, 5133, 781, 12276, 376, 1284, 402, 570, 272, 327, 272, 543, 1551, 8, 8092, 493, 2584, 4848, 358, 465, 289, 26, 267, 862, 26, 288, 1830, 715, 26, 355, 7002, 83, 14, 740, 8, 8092, 14, 912, 8, 70, 430, 267, 871, 21157, 26, 288, 986, 272, 327, 272, 870, 360, 3284, 315, 1052, 7002, 83, 1370, 908, 8, 552, 8, 27056, 1724, 272, 327, 272, 327, 18175, 1806, 314, 7002, 83, 436, 870, 734, 2005, 2556, 446, 5090, 282, 1750, 272, 327, 272, 367, 7002, 315, 7002, 83, 26, 267, 870, 360, 11365, 16767, 540, 730, 10324, 570, 27244, 908, 8, 5503, 14, 466, 12, 5503, 14, 1247, 59, 16, 2459, 267, 7002, 14, 1361, 63, 815, 342, 267, 870, 360, 16901, 445, 14952, 358, 267, 2061, 3890, 275, 7002, 14, 3248, 63, 9041, 1988, 17, 61, 267, 2061, 3890, 14, 1361, 63, 815, 342, 272, 327, 9599, 402, 367, 4438, 1806, 7002, 83, 199, 3, 1284, 402, 347, 2446, 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, 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, 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 ]
panxia6679/ursula
library/keystone_service.py
4
9799
#!/usr/bin/python # -*- coding: utf-8 -*- DOCUMENTATION = ''' --- module: keystone_service short_description: Manage OpenStack Identity (keystone) service endpoints options: name: description: - name of service (e.g., keystone) required: yes type: description: - type of service (e.g., identity) required: yes description: description: - description of service (e.g., Identity Service) required: yes public_url: description: - public url of service. - 'Alias: I(url)' - 'Alias: I(publicurl)' required: yes internal_url: description: - internal url of service. - 'Alias: I(internalurl)' required: no default: value of public_url admin_url: description: - admin url of service. - 'Alias: I(adminurl)' required: no default: value of public_url insecure: description: - allow use of self-signed SSL certificates required: no choices: [ "yes", "no" ] region: description: - region of service required: yes state: description: - Indicate desired state of the resource choices: ['present', 'absent'] default: present requirements: [ python-keystoneclient ] author: Lorin Hochstein ''' EXAMPLES = ''' examples: keystone_service: > name=keystone type=identity description="Keystone Identity Service" publicurl=http://192.168.206.130:5001/v2.0 internalurl=http://192.168.206.130:5001/v2.0 adminurl=http://192.168.206.130:35358/v2.0 keystone_service: > name=glance type=image description="Glance Identity Service" url=http://192.168.206.130:9292 ''' try: from keystoneauth1.identity import v2 from keystoneauth1 import session from keystoneclient.v2_0 import client except ImportError: keystoneclient_found = False else: keystoneclient_found = True import traceback def authenticate(endpoint, token, login_user, login_password, tenant_name, insecure): """Return a keystone client object""" if token: auth = v2.Token(auth_url=endpoint, token=token) else: auth = v2.Password(auth_url=endpoint, username=login_user, password=login_password, tenant_name=tenant_name) if insecure: verify=False else: verify=True sess = session.Session(auth=auth, verify=verify) return client.Client(session=sess) def get_service(keystone, name): """ Retrieve a service by name """ services = [x for x in keystone.services.list() if x.name == name] count = len(services) if count == 0: raise KeyError("No keystone services with name %s" % name) elif count > 1: raise ValueError("%d services with name %s" % (count, name)) else: return services[0] def get_endpoint(keystone, name): """ Retrieve a service endpoint by name """ service = get_service(keystone, name) endpoints = [x for x in keystone.endpoints.list() if x.service_id == service.id] count = len(endpoints) if count == 0: raise KeyError("No keystone endpoints with service name %s" % name) elif count > 1: raise ValueError("%d endpoints with service name %s" % (count, name)) else: return endpoints[0] def ensure_service_present(keystone, name, service_type, description, check_mode): """ Ensure the service is present and has the right values Returns a pair, where the first element is a boolean that indicates a state change, and the second element is the service uuid, or None if running in check mode""" service = None try: service = get_service(keystone, name) except: # Service doesn't exist yet, we'll need to create one pass else: # See if it matches exactly if service.name == name and \ service.type == service_type: # Same, no changes needed return (False, service.id) # At this point, we know we will need to make a change if check_mode: return (True, None) if service is None: service = keystone.services.create(name=name, service_type=service_type, description=description) return (True, service.id) else: msg = "keystone v2 API doesn't support updating services" raise ValueError(msg) def ensure_endpoint_present(keystone, name, public_url, internal_url, admin_url, region, check_mode): """ Ensure the service endpoint is present and have the right values Assumes the service object has already been created at this point""" service = get_service(keystone, name) endpoint = None try: endpoint = get_endpoint(keystone, name) except: # Endpoint doesn't exist yet, we'll need to create one pass else: # endpoints can't be updated with this module (v2 API) return (False, endpoint.id) # At this point, we know we will need to make a change if check_mode: return (True, None) if endpoint is None: endpoint = keystone.endpoints.create(region=region, service_id=service.id, publicurl=public_url, adminurl=admin_url, internalurl=internal_url) return (True, endpoint.id) def ensure_service_absent(keystone, name, check_mode): """ Ensure the service is absent""" raise NotImplementedError() def ensure_endpoint_absent(keystone, name, check_mode): """ Ensure the service endpoint """ raise NotImplementedError() def dispatch(keystone, name, service_type, description, public_url, internal_url, admin_url, region, state, check_mode): if state == 'present': (service_changed, service_id) = ensure_service_present(keystone, name, service_type, description, check_mode) (endpoint_changed, endpoint_id) = ensure_endpoint_present( keystone, name, public_url, internal_url, admin_url, region, check_mode) return dict(changed=service_changed or endpoint_changed, service_id=service_id, endpoint_id=endpoint_id) elif state == 'absent': endpoint_changed = ensure_endpoint_absent(keystone, name, check_mode) service_changed = ensure_service_absent(keystone, name, check_mode) return dict(changed=service_changed or endpoint_changed) else: raise ValueError("Code should never reach here") def main(): module = AnsibleModule( argument_spec=dict( name=dict(required=True), type=dict(required=True), description=dict(required=False), public_url=dict(required=True, aliases=['url', 'publicurl']), internal_url=dict(required=False, aliases=['internalurl']), admin_url=dict(required=False, aliases=['adminurl']), region=dict(required=True), state=dict(default='present', choices=['present', 'absent']), endpoint=dict(required=False, default="http://127.0.0.1:35358/v2.0", aliases=['auth_url']), token=dict(required=False), insecure=dict(required=False, default=False, type='bool'), login_user=dict(required=False), login_password=dict(required=False), tenant_name=dict(required=False, aliases=['tenant']) ), supports_check_mode=True, mutually_exclusive=[['token', 'login_user'], ['token', 'login_password'], ['token', 'tenant_name']] ) endpoint = module.params['endpoint'] token = module.params['token'] login_user = module.params['login_user'] login_password = module.params['login_password'] tenant_name = module.params['tenant_name'] insecure = module.boolean(module.params['insecure']) name = module.params['name'] service_type = module.params['type'] description = module.params['description'] public_url = module.params['public_url'] internal_url = module.params['internal_url'] if internal_url is None: internal_url = public_url admin_url = module.params['admin_url'] if admin_url is None: admin_url = public_url region = module.params['region'] state = module.params['state'] keystone = authenticate(endpoint, token, login_user, login_password, tenant_name, insecure) check_mode = module.check_mode try: d = dispatch(keystone, name, service_type, description, public_url, internal_url, admin_url, region, state, check_mode) except Exception: if check_mode: # If we have a failure in check mode module.exit_json(changed=True, msg="exception: %s" % traceback.format_exc()) else: module.fail_json(msg=traceback.format_exc()) else: module.exit_json(**d) # this is magic, see lib/ansible/module_common.py from ansible.module_utils.basic import * if __name__ == '__main__': main()
mit
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 19395, 63, 1364, 199, 3612, 63, 1802, 26, 14944, 14260, 22034, 334, 19143, 9, 2435, 16173, 199, 1419, 26, 523, 536, 26, 272, 1369, 26, 267, 446, 536, 402, 2435, 334, 69, 14, 71, 2020, 19395, 9, 272, 1415, 26, 9456, 523, 730, 26, 272, 1369, 26, 267, 446, 730, 402, 2435, 334, 69, 14, 71, 2020, 8503, 9, 272, 1415, 26, 9456, 523, 1369, 26, 272, 1369, 26, 267, 446, 1369, 402, 2435, 334, 69, 14, 71, 2020, 22034, 7591, 9, 272, 1415, 26, 9456, 523, 4575, 63, 633, 26, 272, 1369, 26, 267, 446, 4575, 1166, 402, 2435, 14, 267, 446, 283, 14149, 26, 473, 8, 633, 3171, 267, 446, 283, 14149, 26, 473, 8, 3455, 633, 3171, 272, 1415, 26, 9456, 523, 5007, 63, 633, 26, 272, 1369, 26, 267, 446, 5007, 1166, 402, 2435, 14, 267, 446, 283, 14149, 26, 473, 8, 4672, 633, 3171, 272, 1415, 26, 949, 272, 849, 26, 574, 402, 4575, 63, 633, 523, 4628, 63, 633, 26, 272, 1369, 26, 267, 446, 4628, 1166, 402, 2435, 14, 267, 446, 283, 14149, 26, 473, 8, 2113, 633, 3171, 272, 1415, 26, 949, 272, 849, 26, 574, 402, 4575, 63, 633, 523, 26097, 26, 272, 1369, 26, 267, 446, 2040, 675, 402, 291, 13, 1737, 7799, 14512, 272, 1415, 26, 949, 272, 3415, 26, 359, 298, 5066, 401, 298, 889, 2, 1622, 523, 4897, 26, 272, 1369, 26, 267, 446, 4897, 402, 2435, 272, 1415, 26, 9456, 523, 1174, 26, 1362, 1369, 26, 267, 446, 1010, 10188, 6387, 1174, 402, 314, 2073, 1362, 3415, 26, 788, 1881, 297, 283, 5575, 418, 1362, 849, 26, 3451, 4388, 199, 7538, 26, 359, 2366, 13, 19143, 1258, 1622, 199, 2502, 26, 491, 269, 262, 28673, 335, 1597, 262, 199, 2344, 199, 199, 8918, 275, 1449, 199, 8589, 26, 199, 19143, 63, 1364, 26, 690, 272, 536, 29, 19143, 272, 730, 29, 5582, 272, 1369, 628, 1197, 8361, 22034, 7591, 2, 272, 4575, 633, 29, 1014, 921, 5756, 14, 6568, 14, 11089, 14, 9056, 26, 21, 4587, 15, 86, 18, 14, 16, 272, 5007, 633, 29, 1014, 921, 5756, 14, 6568, 14, 11089, 14, 9056, 26, 21, 4587, 15, 86, 18, 14, 16, 272, 4628, 633, 29, 1014, 921, 5756, 14, 6568, 14, 11089, 14, 9056, 26, 1276, 14321, 15, 86, 18, 14, 16, 199, 199, 19143, 63, 1364, 26, 690, 272, 536, 29, 18773, 272, 730, 29, 1569, 272, 1369, 628, 17541, 554, 22034, 7591, 2, 272, 1166, 29, 1014, 921, 5756, 14, 6568, 14, 11089, 14, 9056, 26, 25, 17027, 199, 199, 2344, 199, 199, 893, 26, 272, 687, 19395, 1178, 17, 14, 5582, 492, 373, 18, 272, 687, 19395, 1178, 17, 492, 2351, 272, 687, 19395, 1258, 14, 86, 18, 63, 16, 492, 1890, 199, 2590, 3545, 26, 272, 19395, 1258, 63, 4214, 275, 756, 199, 2836, 26, 272, 19395, 1258, 63, 4214, 275, 715, 199, 199, 646, 5190, 421, 199, 318, 12895, 8, 6520, 12, 1526, 12, 4676, 63, 751, 12, 4676, 63, 2060, 12, 8261, 63, 354, 12, 326, 26097, 304, 272, 408, 1767, 282, 19395, 1890, 909, 624, 339, 340, 1526, 26, 267, 1790, 275, 373, 18, 14, 3264, 8, 1178, 63, 633, 29, 6520, 12, 1526, 29, 1418, 9, 272, 587, 26, 267, 1790, 275, 373, 18, 14, 6139, 8, 1178, 63, 633, 29, 6520, 12, 3434, 29, 2886, 63, 751, 12, 2574, 2505, 29, 2886, 63, 2060, 12, 8261, 63, 354, 29, 4647, 63, 354, 9, 339, 340, 26097, 26, 267, 4911, 29, 797, 272, 587, 26, 267, 4911, 29, 549, 272, 4043, 275, 2351, 14, 4434, 8, 1178, 29, 1178, 12, 4911, 29, 4712, 9, 339, 372, 1890, 14, 3041, 8, 1730, 29, 5480, 9, 199, 199, 318, 664, 63, 1364, 8, 19143, 12, 536, 304, 272, 408, 13939, 282, 2435, 701, 536, 408, 272, 8500, 275, 359, 88, 367, 671, 315, 19395, 14, 5950, 14, 513, 342, 340, 671, 14, 354, 508, 536, 61, 272, 2338, 275, 822, 8, 5950, 9, 272, 340, 2338, 508, 378, 26, 267, 746, 4067, 480, 1944, 19395, 8500, 543, 536, 450, 83, 2, 450, 536, 9, 272, 916, 2338, 690, 413, 26, 267, 746, 1722, 3647, 68, 8500, 543, 536, 450, 83, 2, 450, 334, 835, 12, 536, 430, 272, 587, 26, 267, 372, 8500, 59, 16, 61, 421, 199, 318, 664, 63, 6520, 8, 19143, 12, 536, 304, 272, 408, 13939, 282, 2435, 6037, 701, 536, 408, 272, 2435, 275, 664, 63, 1364, 8, 19143, 12, 536, 9, 272, 16173, 275, 359, 88, 367, 671, 315, 19395, 14, 14461, 14, 513, 342, 673, 340, 671, 14, 1364, 63, 344, 508, 2435, 14, 344, 61, 272, 2338, 275, 822, 8, 14461, 9, 272, 340, 2338, 508, 378, 26, 267, 746, 4067, 480, 1944, 19395, 16173, 543, 2435, 536, 450, 83, 2, 450, 536, 9, 272, 916, 2338, 690, 413, 26, 267, 746, 1722, 3647, 68, 16173, 543, 2435, 536, 450, 83, 2, 450, 334, 835, 12, 536, 430, 272, 587, 26, 267, 372, 16173, 59, 16, 61, 421, 199, 318, 4868, 63, 1364, 63, 1881, 8, 19143, 12, 536, 12, 2435, 63, 466, 12, 1369, 12, 2574, 1104, 63, 632, 304, 272, 408, 7523, 314, 2435, 365, 3451, 436, 965, 314, 2451, 1338, 398, 1803, 282, 4092, 12, 2382, 314, 1642, 1819, 365, 282, 5046, 626, 9126, 267, 282, 1174, 1570, 12, 436, 314, 3499, 1819, 365, 314, 2435, 5377, 12, 503, 488, 267, 340, 3879, 315, 1104, 818, 624, 272, 2435, 275, 488, 272, 862, 26, 267, 2435, 275, 664, 63, 1364, 8, 19143, 12, 536, 9, 272, 871, 26, 267, 327, 7591, 3181, 1133, 2187, 5966, 12, 781, 7171, 1929, 370, 1218, 1373, 267, 986, 272, 587, 26, 267, 327, 1666, 340, 652, 4450, 8840, 267, 340, 2435, 14, 354, 508, 536, 436, 971, 1779, 2435, 14, 466, 508, 2435, 63, 466, 26, 953, 327, 14766, 12, 949, 4493, 4346, 288, 372, 334, 797, 12, 2435, 14, 344, 9, 339, 327, 2854, 642, 2376, 12, 781, 5715, 781 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 19395, 63, 1364, 199, 3612, 63, 1802, 26, 14944, 14260, 22034, 334, 19143, 9, 2435, 16173, 199, 1419, 26, 523, 536, 26, 272, 1369, 26, 267, 446, 536, 402, 2435, 334, 69, 14, 71, 2020, 19395, 9, 272, 1415, 26, 9456, 523, 730, 26, 272, 1369, 26, 267, 446, 730, 402, 2435, 334, 69, 14, 71, 2020, 8503, 9, 272, 1415, 26, 9456, 523, 1369, 26, 272, 1369, 26, 267, 446, 1369, 402, 2435, 334, 69, 14, 71, 2020, 22034, 7591, 9, 272, 1415, 26, 9456, 523, 4575, 63, 633, 26, 272, 1369, 26, 267, 446, 4575, 1166, 402, 2435, 14, 267, 446, 283, 14149, 26, 473, 8, 633, 3171, 267, 446, 283, 14149, 26, 473, 8, 3455, 633, 3171, 272, 1415, 26, 9456, 523, 5007, 63, 633, 26, 272, 1369, 26, 267, 446, 5007, 1166, 402, 2435, 14, 267, 446, 283, 14149, 26, 473, 8, 4672, 633, 3171, 272, 1415, 26, 949, 272, 849, 26, 574, 402, 4575, 63, 633, 523, 4628, 63, 633, 26, 272, 1369, 26, 267, 446, 4628, 1166, 402, 2435, 14, 267, 446, 283, 14149, 26, 473, 8, 2113, 633, 3171, 272, 1415, 26, 949, 272, 849, 26, 574, 402, 4575, 63, 633, 523, 26097, 26, 272, 1369, 26, 267, 446, 2040, 675, 402, 291, 13, 1737, 7799, 14512, 272, 1415, 26, 949, 272, 3415, 26, 359, 298, 5066, 401, 298, 889, 2, 1622, 523, 4897, 26, 272, 1369, 26, 267, 446, 4897, 402, 2435, 272, 1415, 26, 9456, 523, 1174, 26, 1362, 1369, 26, 267, 446, 1010, 10188, 6387, 1174, 402, 314, 2073, 1362, 3415, 26, 788, 1881, 297, 283, 5575, 418, 1362, 849, 26, 3451, 4388, 199, 7538, 26, 359, 2366, 13, 19143, 1258, 1622, 199, 2502, 26, 491, 269, 262, 28673, 335, 1597, 262, 199, 2344, 199, 199, 8918, 275, 1449, 199, 8589, 26, 199, 19143, 63, 1364, 26, 690, 272, 536, 29, 19143, 272, 730, 29, 5582, 272, 1369, 628, 1197, 8361, 22034, 7591, 2, 272, 4575, 633, 29, 1014, 921, 5756, 14, 6568, 14, 11089, 14, 9056, 26, 21, 4587, 15, 86, 18, 14, 16, 272, 5007, 633, 29, 1014, 921, 5756, 14, 6568, 14, 11089, 14, 9056, 26, 21, 4587, 15, 86, 18, 14, 16, 272, 4628, 633, 29, 1014, 921, 5756, 14, 6568, 14, 11089, 14, 9056, 26, 1276, 14321, 15, 86, 18, 14, 16, 199, 199, 19143, 63, 1364, 26, 690, 272, 536, 29, 18773, 272, 730, 29, 1569, 272, 1369, 628, 17541, 554, 22034, 7591, 2, 272, 1166, 29, 1014, 921, 5756, 14, 6568, 14, 11089, 14, 9056, 26, 25, 17027, 199, 199, 2344, 199, 199, 893, 26, 272, 687, 19395, 1178, 17, 14, 5582, 492, 373, 18, 272, 687, 19395, 1178, 17, 492, 2351, 272, 687, 19395, 1258, 14, 86, 18, 63, 16, 492, 1890, 199, 2590, 3545, 26, 272, 19395, 1258, 63, 4214, 275, 756, 199, 2836, 26, 272, 19395, 1258, 63, 4214, 275, 715, 199, 199, 646, 5190, 421, 199, 318, 12895, 8, 6520, 12, 1526, 12, 4676, 63, 751, 12, 4676, 63, 2060, 12, 8261, 63, 354, 12, 326, 26097, 304, 272, 408, 1767, 282, 19395, 1890, 909, 624, 339, 340, 1526, 26, 267, 1790, 275, 373, 18, 14, 3264, 8, 1178, 63, 633, 29, 6520, 12, 1526, 29, 1418, 9, 272, 587, 26, 267, 1790, 275, 373, 18, 14, 6139, 8, 1178, 63, 633, 29, 6520, 12, 3434, 29, 2886, 63, 751, 12, 2574, 2505, 29, 2886, 63, 2060, 12, 8261, 63, 354, 29, 4647, 63, 354, 9, 339, 340, 26097, 26, 267, 4911, 29, 797, 272, 587, 26, 267, 4911, 29, 549, 272, 4043, 275, 2351, 14, 4434, 8, 1178, 29, 1178, 12, 4911, 29, 4712, 9, 339, 372, 1890, 14, 3041, 8, 1730, 29, 5480, 9, 199, 199, 318, 664, 63, 1364, 8, 19143, 12, 536, 304, 272, 408, 13939, 282, 2435, 701, 536, 408, 272, 8500, 275, 359, 88, 367, 671, 315, 19395, 14, 5950, 14, 513, 342, 340, 671, 14, 354, 508, 536, 61, 272, 2338, 275, 822, 8, 5950, 9, 272, 340, 2338, 508, 378, 26, 267, 746, 4067, 480, 1944, 19395, 8500, 543, 536, 450, 83, 2, 450, 536, 9, 272, 916, 2338, 690, 413, 26, 267, 746, 1722, 3647, 68, 8500, 543, 536, 450, 83, 2, 450, 334, 835, 12, 536, 430, 272, 587, 26, 267, 372, 8500, 59, 16, 61, 421, 199, 318, 664, 63, 6520, 8, 19143, 12, 536, 304, 272, 408, 13939, 282, 2435, 6037, 701, 536, 408, 272, 2435, 275, 664, 63, 1364, 8, 19143, 12, 536, 9, 272, 16173, 275, 359, 88, 367, 671, 315, 19395, 14, 14461, 14, 513, 342, 673, 340, 671, 14, 1364, 63, 344, 508, 2435, 14, 344, 61, 272, 2338, 275, 822, 8, 14461, 9, 272, 340, 2338, 508, 378, 26, 267, 746, 4067, 480, 1944, 19395, 16173, 543, 2435, 536, 450, 83, 2, 450, 536, 9, 272, 916, 2338, 690, 413, 26, 267, 746, 1722, 3647, 68, 16173, 543, 2435, 536, 450, 83, 2, 450, 334, 835, 12, 536, 430, 272, 587, 26, 267, 372, 16173, 59, 16, 61, 421, 199, 318, 4868, 63, 1364, 63, 1881, 8, 19143, 12, 536, 12, 2435, 63, 466, 12, 1369, 12, 2574, 1104, 63, 632, 304, 272, 408, 7523, 314, 2435, 365, 3451, 436, 965, 314, 2451, 1338, 398, 1803, 282, 4092, 12, 2382, 314, 1642, 1819, 365, 282, 5046, 626, 9126, 267, 282, 1174, 1570, 12, 436, 314, 3499, 1819, 365, 314, 2435, 5377, 12, 503, 488, 267, 340, 3879, 315, 1104, 818, 624, 272, 2435, 275, 488, 272, 862, 26, 267, 2435, 275, 664, 63, 1364, 8, 19143, 12, 536, 9, 272, 871, 26, 267, 327, 7591, 3181, 1133, 2187, 5966, 12, 781, 7171, 1929, 370, 1218, 1373, 267, 986, 272, 587, 26, 267, 327, 1666, 340, 652, 4450, 8840, 267, 340, 2435, 14, 354, 508, 536, 436, 971, 1779, 2435, 14, 466, 508, 2435, 63, 466, 26, 953, 327, 14766, 12, 949, 4493, 4346, 288, 372, 334, 797, 12, 2435, 14, 344, 9, 339, 327, 2854, 642, 2376, 12, 781, 5715, 781, 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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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 ]
google/tink
python/tink/core/_registry.py
1
9252
# Copyright 2019 Google LLC. # # 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. """Tink Registry.""" from __future__ import absolute_import from __future__ import division # Placeholder for import for type annotations from __future__ import print_function from typing import Any, Text, Tuple, Type, TypeVar from tink.proto import tink_pb2 from tink.core import _key_manager from tink.core import _primitive_set from tink.core import _primitive_wrapper from tink.core import _tink_error P = TypeVar('P') class Registry(object): """A global container of key managers. Registry maps supported key types to a corresponding KeyManager object, which 'understands' the key type (i.e., the KeyManager can instantiate the primitive corresponding to given key, or can generate new keys of the supported key type). Keeping KeyManagers for all primitives in a single Registry (rather than having a separate KeyManager per primitive) enables modular construction of compound primitives from 'simple' ones, e.g., AES-CTR-HMAC AEAD encryption uses IND-CPA encryption and a MAC. Registry is initialized at startup, and is later used to instantiate primitives for given keys or keysets. """ _key_managers = {} # type: dict[Text, Tuple[_key_manager.KeyManager, bool]] _wrappers = {} # type: dict[Type, _primitive_wrapper.PrimitiveWrapper] @classmethod def reset(cls) -> None: """Resets the registry.""" cls._key_managers = {} cls._wrappers = {} @classmethod def _key_manager_internal( cls, type_url: Text) -> Tuple[_key_manager.KeyManager, bool]: """Returns a key manager, new_key_allowed pair for the given type_url.""" if type_url not in cls._key_managers: raise _tink_error.TinkError( 'No manager for type {} has been registered.'.format(type_url)) return cls._key_managers[type_url] @classmethod def key_manager(cls, type_url: Text) -> _key_manager.KeyManager: """Returns a key manager for the given type_url and primitive_class. Args: type_url: Key type string Returns: A KeyManager object """ key_mgr, _ = cls._key_manager_internal(type_url) return key_mgr @classmethod def register_key_manager(cls, key_manager: _key_manager.KeyManager, new_key_allowed: bool = True) -> None: """Tries to register a key_manager for the given key_manager.key_type(). Args: key_manager: A KeyManager object new_key_allowed: If new_key_allowed is true, users can generate new keys with this manager using Registry.new_key() """ key_managers = cls._key_managers type_url = key_manager.key_type() primitive_class = key_manager.primitive_class() if not key_manager.does_support(type_url): raise _tink_error.TinkError( 'The manager does not support its own type {}.'.format(type_url)) if type_url in key_managers: existing, existing_new_key = key_managers[type_url] if (type(existing) != type(key_manager) or # pylint: disable=unidiomatic-typecheck existing.primitive_class() != primitive_class): raise _tink_error.TinkError( 'A manager for type {} has been already registered.'.format( type_url)) else: if not existing_new_key and new_key_allowed: raise _tink_error.TinkError( ('A manager for type {} has been already registered ' 'with forbidden new key operation.').format(type_url)) key_managers[type_url] = (existing, new_key_allowed) else: key_managers[type_url] = (key_manager, new_key_allowed) @classmethod def primitive(cls, key_data: tink_pb2.KeyData, primitive_class: Type[P]) -> P: """Creates a new primitive for the key given in key_data. It looks up a KeyManager identified by key_data.type_url, and calls manager's primitive(key_data) method. Args: key_data: KeyData object primitive_class: The expected primitive class Returns: A primitive for the given key_data Raises: Error if primitive_class does not match the registered primitive class. """ key_mgr = cls.key_manager(key_data.type_url) if key_mgr.primitive_class() != primitive_class: raise _tink_error.TinkError( 'Wrong primitive class: type {} uses primitive {}, and not {}.' .format(key_data.type_url, key_mgr.primitive_class().__name__, primitive_class.__name__)) return key_mgr.primitive(key_data) @classmethod def new_key_data(cls, key_template: tink_pb2.KeyTemplate) -> tink_pb2.KeyData: """Generates a new key for the specified key_template.""" key_mgr, new_key_allowed = cls._key_manager_internal( key_template.type_url) if not new_key_allowed: raise _tink_error.TinkError( 'KeyManager for type {} does not allow for creation of new keys.' .format(key_template.type_url)) return key_mgr.new_key_data(key_template) @classmethod def public_key_data(cls, private_key_data: tink_pb2.KeyData) -> tink_pb2.KeyData: """Generates a new key for the specified key_template.""" if (private_key_data.key_material_type != tink_pb2.KeyData.ASYMMETRIC_PRIVATE): raise _tink_error.TinkError('The keyset contains a non-private key') key_mgr = cls.key_manager(private_key_data.type_url) if not isinstance(key_mgr, _key_manager.PrivateKeyManager): raise _tink_error.TinkError( 'manager for key type {} is not a PrivateKeyManager' .format(private_key_data.type_url)) return key_mgr.public_key_data(private_key_data) @classmethod def register_primitive_wrapper( cls, wrapper: _primitive_wrapper.PrimitiveWrapper) -> None: """Tries to register a PrimitiveWrapper. Args: wrapper: A PrimitiveWrapper object. Raises: TinkError if a different wrapper has already been registered for the same Primitive. """ if (wrapper.primitive_class() in cls._wrappers and type(cls._wrappers[wrapper.primitive_class()]) != type(wrapper)): # pylint: disable=unidiomatic-typecheck raise _tink_error.TinkError( 'A wrapper for primitive {} has already been added.'.format( wrapper.primitive_class().__name__)) wrapped = wrapper.wrap( _primitive_set.PrimitiveSet(wrapper.input_primitive_class())) if not isinstance(wrapped, wrapper.primitive_class()): raise _tink_error.TinkError( 'Wrapper for primitive {} generates incompatible primitive of type {}' .format(wrapper.primitive_class().__name__, type(wrapped).__name__)) cls._wrappers[wrapper.primitive_class()] = wrapper @classmethod def input_primitive_class(cls, primitive_class: Any) -> Any: """Returns the primitive class that gets wrapped into primitive_class. Args: primitive_class: Class of the output primitive of a wrapper. Returns: the primitive class that gets wrapped. This needs to be the type used in the primitive set. Raises: TinkError if no wrapper for this primitive class is registered. """ if primitive_class not in cls._wrappers: raise _tink_error.TinkError( 'No PrimitiveWrapper registered for primitive {}.' .format(primitive_class.__name__)) wrapper = cls._wrappers[primitive_class] return wrapper.input_primitive_class() @classmethod def wrap(cls, primitive_set: _primitive_set.PrimitiveSet, primitive_class: Type[P]) -> P: """Wraps a set of primitives into a single primitive. Args: primitive_set: A PrimitiveSet object. primitive_class: Class of the output primitive. Returns: A primitive of type primitive_class that wraps the primitives in primitive_set. Raises: TinkError if no wrapper for this primitive class is registered or the type of the primitives in primitive_set are don't match the input_primitive_class of the wrapper. """ if primitive_class not in cls._wrappers: raise _tink_error.TinkError( 'No PrimitiveWrapper registered for primitive {}.' .format(primitive_class.__name__)) wrapper = cls._wrappers[primitive_class] if primitive_set.primitive_class() != wrapper.input_primitive_class(): raise _tink_error.TinkError( 'Wrapper for primitive {} wraps type {}, but the primitive_set' 'has type {}' .format(wrapper.primitive_class().__name__, wrapper.input_primitive_class().__name__, primitive_set.primitive_class().__name__)) return wrapper.wrap(primitive_set)
apache-2.0
[ 3, 1898, 20312, 4475, 20376, 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, 52, 2292, 20738, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 3, 10902, 4302, 367, 492, 367, 730, 15538, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 14090, 492, 6184, 12, 4516, 12, 11634, 12, 2434, 12, 2434, 5894, 199, 199, 504, 307, 2292, 14, 2625, 492, 307, 2292, 63, 3317, 18, 199, 504, 307, 2292, 14, 1018, 492, 485, 498, 63, 2609, 199, 504, 307, 2292, 14, 1018, 492, 485, 16161, 63, 409, 199, 504, 307, 2292, 14, 1018, 492, 485, 16161, 63, 5029, 199, 504, 307, 2292, 14, 1018, 492, 485, 1346, 75, 63, 705, 199, 199, 48, 275, 2434, 5894, 360, 48, 358, 421, 199, 533, 20738, 8, 785, 304, 523, 408, 33, 2288, 3970, 402, 790, 19680, 14, 819, 20738, 9033, 3748, 790, 2943, 370, 282, 5226, 2606, 2988, 909, 12, 523, 1314, 283, 7138, 26580, 7, 314, 790, 730, 334, 73, 14, 69, 2020, 314, 2606, 2988, 883, 17321, 314, 523, 18944, 5226, 370, 1627, 790, 12, 503, 883, 3550, 892, 2883, 402, 314, 523, 3748, 790, 730, 680, 1804, 1024, 4073, 2606, 2395, 10246, 367, 1006, 1979, 22337, 315, 282, 2849, 523, 20738, 334, 345, 728, 2419, 9445, 282, 7396, 2606, 2988, 1126, 18944, 9, 22741, 523, 3413, 2238, 14538, 402, 16487, 1979, 22337, 687, 283, 4129, 7, 7869, 12, 523, 325, 14, 71, 2020, 19093, 13, 1028, 50, 13, 23034, 24475, 1554, 14396, 4440, 23632, 13, 2890, 33, 14396, 436, 282, 13347, 14, 819, 20738, 365, 10038, 737, 14210, 12, 436, 365, 2945, 1202, 370, 17321, 523, 1979, 22337, 367, 1627, 2883, 503, 790, 2193, 14, 523, 408, 819, 485, 498, 63, 16259, 275, 1052, 221, 327, 730, 26, 1211, 59, 1872, 12, 11634, 13040, 498, 63, 2609, 14, 1197, 2988, 12, 2155, 2677, 523, 485, 21148, 275, 1052, 221, 327, 730, 26, 1211, 59, 804, 12, 485, 16161, 63, 5029, 14, 22231, 4590, 61, 819, 768, 3744, 523, 347, 5305, 8, 1886, 9, 1035, 488, 26, 272, 408, 497, 2193, 314, 7086, 1041, 272, 843, 423, 498, 63, 16259, 275, 1052, 272, 843, 423, 21148, 275, 1052, 819, 768, 3744, 523, 347, 485, 498, 63, 2609, 63, 4672, 8, 489, 843, 12, 730, 63, 633, 26, 4516, 9, 1035, 11634, 13040, 498, 63, 2609, 14, 1197, 2988, 12, 2155, 2189, 272, 408, 3407, 282, 790, 5256, 12, 892, 63, 498, 63, 6541, 4092, 367, 314, 1627, 730, 63, 633, 1041, 272, 340, 730, 63, 633, 440, 315, 843, 423, 498, 63, 16259, 26, 489, 746, 485, 1346, 75, 63, 705, 14, 52, 2292, 547, 8, 881, 283, 1944, 5256, 367, 730, 1052, 965, 2757, 7264, 17374, 908, 8, 466, 63, 633, 430, 272, 372, 843, 423, 498, 63, 16259, 59, 466, 63, 633, 61, 819, 768, 3744, 523, 347, 790, 63, 2609, 8, 1886, 12, 730, 63, 633, 26, 4516, 9, 1035, 485, 498, 63, 2609, 14, 1197, 2988, 26, 272, 408, 3407, 282, 790, 5256, 367, 314, 1627, 730, 63, 633, 436, 18944, 63, 533, 14, 339, 3033, 26, 489, 730, 63, 633, 26, 2606, 730, 1059, 339, 1803, 26, 489, 437, 2606, 2988, 909, 272, 408, 272, 790, 63, 7755, 12, 485, 275, 843, 423, 498, 63, 2609, 63, 4672, 8, 466, 63, 633, 9, 272, 372, 790, 63, 7755, 819, 768, 3744, 523, 347, 2274, 63, 498, 63, 2609, 8, 1886, 12, 2574, 790, 63, 2609, 26, 485, 498, 63, 2609, 14, 1197, 2988, 12, 2574, 892, 63, 498, 63, 6541, 26, 2155, 275, 715, 9, 1035, 488, 26, 272, 408, 52, 1996, 370, 2274, 282, 790, 63, 2609, 367, 314, 1627, 790, 63, 2609, 14, 498, 63, 466, 1252, 339, 3033, 26, 489, 790, 63, 2609, 26, 437, 2606, 2988, 909, 489, 892, 63, 498, 63, 6541, 26, 982, 892, 63, 498, 63, 6541, 365, 2549, 12, 4390, 883, 3550, 892, 2883, 267, 543, 642, 5256, 1808, 20738, 14, 1222, 63, 498, 342, 272, 408, 272, 790, 63, 16259, 275, 843, 423, 498, 63, 16259, 272, 730, 63, 633, 275, 790, 63, 2609, 14, 498, 63, 466, 342, 272, 18944, 63, 533, 275, 790, 63, 2609, 14, 16161, 63, 533, 342, 339, 340, 440, 790, 63, 2609, 14, 9105, 63, 4058, 8, 466, 63, 633, 304, 489, 746, 485, 1346, 75, 63, 705, 14, 52, 2292, 547, 8, 881, 283, 1918, 5256, 1630, 440, 2291, 2399, 5705, 730, 1052, 17374, 908, 8, 466, 63, 633, 430, 339, 340, 730, 63, 633, 315, 790, 63, 16259, 26, 489, 3411, 12, 3411, 63, 1222, 63, 498, 275, 790, 63, 16259, 59, 466, 63, 633, 61, 489, 340, 334, 466, 8, 5952, 9, 1137, 730, 8, 498, 63, 2609, 9, 503, 221, 327, 4287, 26, 3507, 29, 5411, 3006, 3889, 13, 466, 1074, 881, 3411, 14, 16161, 63, 533, 342, 1137, 18944, 63, 533, 304, 267, 746, 485, 1346, 75, 63, 705, 14, 52, 2292, 547, 8, 288, 283, 33, 5256, 367, 730, 1052, 965, 2757, 2575, 7264, 17374, 908, 8, 355, 730, 63, 633, 430, 489, 587, 26, 267, 340, 440, 3411, 63, 1222, 63, 498, 436, 892, 63, 498, 63, 6541, 26, 881, 746, 485, 1346, 75, 63, 705, 14, 52, 2292, 547, 8, 1598, 661, 33, 5256, 367, 730, 1052, 965, 2757, 2575, 7264, 283, 2049, 283 ]
[ 1898, 20312, 4475, 20376, 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, 52, 2292, 20738, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 3, 10902, 4302, 367, 492, 367, 730, 15538, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 14090, 492, 6184, 12, 4516, 12, 11634, 12, 2434, 12, 2434, 5894, 199, 199, 504, 307, 2292, 14, 2625, 492, 307, 2292, 63, 3317, 18, 199, 504, 307, 2292, 14, 1018, 492, 485, 498, 63, 2609, 199, 504, 307, 2292, 14, 1018, 492, 485, 16161, 63, 409, 199, 504, 307, 2292, 14, 1018, 492, 485, 16161, 63, 5029, 199, 504, 307, 2292, 14, 1018, 492, 485, 1346, 75, 63, 705, 199, 199, 48, 275, 2434, 5894, 360, 48, 358, 421, 199, 533, 20738, 8, 785, 304, 523, 408, 33, 2288, 3970, 402, 790, 19680, 14, 819, 20738, 9033, 3748, 790, 2943, 370, 282, 5226, 2606, 2988, 909, 12, 523, 1314, 283, 7138, 26580, 7, 314, 790, 730, 334, 73, 14, 69, 2020, 314, 2606, 2988, 883, 17321, 314, 523, 18944, 5226, 370, 1627, 790, 12, 503, 883, 3550, 892, 2883, 402, 314, 523, 3748, 790, 730, 680, 1804, 1024, 4073, 2606, 2395, 10246, 367, 1006, 1979, 22337, 315, 282, 2849, 523, 20738, 334, 345, 728, 2419, 9445, 282, 7396, 2606, 2988, 1126, 18944, 9, 22741, 523, 3413, 2238, 14538, 402, 16487, 1979, 22337, 687, 283, 4129, 7, 7869, 12, 523, 325, 14, 71, 2020, 19093, 13, 1028, 50, 13, 23034, 24475, 1554, 14396, 4440, 23632, 13, 2890, 33, 14396, 436, 282, 13347, 14, 819, 20738, 365, 10038, 737, 14210, 12, 436, 365, 2945, 1202, 370, 17321, 523, 1979, 22337, 367, 1627, 2883, 503, 790, 2193, 14, 523, 408, 819, 485, 498, 63, 16259, 275, 1052, 221, 327, 730, 26, 1211, 59, 1872, 12, 11634, 13040, 498, 63, 2609, 14, 1197, 2988, 12, 2155, 2677, 523, 485, 21148, 275, 1052, 221, 327, 730, 26, 1211, 59, 804, 12, 485, 16161, 63, 5029, 14, 22231, 4590, 61, 819, 768, 3744, 523, 347, 5305, 8, 1886, 9, 1035, 488, 26, 272, 408, 497, 2193, 314, 7086, 1041, 272, 843, 423, 498, 63, 16259, 275, 1052, 272, 843, 423, 21148, 275, 1052, 819, 768, 3744, 523, 347, 485, 498, 63, 2609, 63, 4672, 8, 489, 843, 12, 730, 63, 633, 26, 4516, 9, 1035, 11634, 13040, 498, 63, 2609, 14, 1197, 2988, 12, 2155, 2189, 272, 408, 3407, 282, 790, 5256, 12, 892, 63, 498, 63, 6541, 4092, 367, 314, 1627, 730, 63, 633, 1041, 272, 340, 730, 63, 633, 440, 315, 843, 423, 498, 63, 16259, 26, 489, 746, 485, 1346, 75, 63, 705, 14, 52, 2292, 547, 8, 881, 283, 1944, 5256, 367, 730, 1052, 965, 2757, 7264, 17374, 908, 8, 466, 63, 633, 430, 272, 372, 843, 423, 498, 63, 16259, 59, 466, 63, 633, 61, 819, 768, 3744, 523, 347, 790, 63, 2609, 8, 1886, 12, 730, 63, 633, 26, 4516, 9, 1035, 485, 498, 63, 2609, 14, 1197, 2988, 26, 272, 408, 3407, 282, 790, 5256, 367, 314, 1627, 730, 63, 633, 436, 18944, 63, 533, 14, 339, 3033, 26, 489, 730, 63, 633, 26, 2606, 730, 1059, 339, 1803, 26, 489, 437, 2606, 2988, 909, 272, 408, 272, 790, 63, 7755, 12, 485, 275, 843, 423, 498, 63, 2609, 63, 4672, 8, 466, 63, 633, 9, 272, 372, 790, 63, 7755, 819, 768, 3744, 523, 347, 2274, 63, 498, 63, 2609, 8, 1886, 12, 2574, 790, 63, 2609, 26, 485, 498, 63, 2609, 14, 1197, 2988, 12, 2574, 892, 63, 498, 63, 6541, 26, 2155, 275, 715, 9, 1035, 488, 26, 272, 408, 52, 1996, 370, 2274, 282, 790, 63, 2609, 367, 314, 1627, 790, 63, 2609, 14, 498, 63, 466, 1252, 339, 3033, 26, 489, 790, 63, 2609, 26, 437, 2606, 2988, 909, 489, 892, 63, 498, 63, 6541, 26, 982, 892, 63, 498, 63, 6541, 365, 2549, 12, 4390, 883, 3550, 892, 2883, 267, 543, 642, 5256, 1808, 20738, 14, 1222, 63, 498, 342, 272, 408, 272, 790, 63, 16259, 275, 843, 423, 498, 63, 16259, 272, 730, 63, 633, 275, 790, 63, 2609, 14, 498, 63, 466, 342, 272, 18944, 63, 533, 275, 790, 63, 2609, 14, 16161, 63, 533, 342, 339, 340, 440, 790, 63, 2609, 14, 9105, 63, 4058, 8, 466, 63, 633, 304, 489, 746, 485, 1346, 75, 63, 705, 14, 52, 2292, 547, 8, 881, 283, 1918, 5256, 1630, 440, 2291, 2399, 5705, 730, 1052, 17374, 908, 8, 466, 63, 633, 430, 339, 340, 730, 63, 633, 315, 790, 63, 16259, 26, 489, 3411, 12, 3411, 63, 1222, 63, 498, 275, 790, 63, 16259, 59, 466, 63, 633, 61, 489, 340, 334, 466, 8, 5952, 9, 1137, 730, 8, 498, 63, 2609, 9, 503, 221, 327, 4287, 26, 3507, 29, 5411, 3006, 3889, 13, 466, 1074, 881, 3411, 14, 16161, 63, 533, 342, 1137, 18944, 63, 533, 304, 267, 746, 485, 1346, 75, 63, 705, 14, 52, 2292, 547, 8, 288, 283, 33, 5256, 367, 730, 1052, 965, 2757, 2575, 7264, 17374, 908, 8, 355, 730, 63, 633, 430, 489, 587, 26, 267, 340, 440, 3411, 63, 1222, 63, 498, 436, 892, 63, 498, 63, 6541, 26, 881, 746, 485, 1346, 75, 63, 705, 14, 52, 2292, 547, 8, 1598, 661, 33, 5256, 367, 730, 1052, 965, 2757, 2575, 7264, 283, 2049, 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, 1, 1, 1, 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 ]
basicthinker/Sexain-MemController
gem5-stable/src/mem/slicc/ast/StallAndWaitStatementAST.py
34
2361
# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood # Copyright (c) 2009 The Hewlett-Packard Development Company # 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. from slicc.ast.StatementAST import StatementAST class StallAndWaitStatementAST(StatementAST): def __init__(self, slicc, in_port, address): super(StatementAST, self).__init__(slicc) self.in_port = in_port self.address = address def __repr__(self): return "[StallAndWaitStatementAst: %r]" % self.variable def generate(self, code, return_type): self.in_port.assertType("InPort") self.address.assertType("Address") in_port_code = self.in_port.var.code address_code = self.address.var.code code(''' stallBuffer(&($in_port_code), $address_code); $in_port_code.stallMessage($address_code); ''')
apache-2.0
[ 3, 1898, 334, 67, 9, 21300, 13, 9300, 7173, 577, 14, 869, 778, 436, 20232, 437, 14, 644, 23521, 199, 3, 1898, 334, 67, 9, 8937, 710, 27849, 13, 29471, 15290, 15878, 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, 199, 504, 308, 606, 67, 14, 1810, 14, 15173, 11307, 492, 29697, 11307, 199, 199, 533, 1933, 452, 3325, 7536, 15173, 11307, 8, 15173, 11307, 304, 272, 347, 636, 826, 721, 277, 12, 308, 606, 67, 12, 315, 63, 719, 12, 2287, 304, 267, 1613, 8, 15173, 11307, 12, 291, 2843, 826, 721, 83, 606, 67, 9, 267, 291, 14, 262, 63, 719, 275, 315, 63, 719, 267, 291, 14, 1562, 275, 2287, 5493, 347, 636, 2722, 721, 277, 304, 267, 372, 7369, 933, 452, 3325, 7536, 15173, 33, 270, 26, 450, 82, 8480, 450, 291, 14, 1975, 339, 347, 3550, 8, 277, 12, 1233, 12, 372, 63, 466, 304, 267, 291, 14, 262, 63, 719, 14, 479, 804, 480, 607, 4313, 531, 267, 291, 14, 1562, 14, 479, 804, 480, 1476, 531, 398, 315, 63, 719, 63, 600, 275, 291, 14, 262, 63, 719, 14, 1391, 14, 600, 267, 2287, 63, 600, 275, 291, 14, 1562, 14, 1391, 14, 600, 267, 1233, 10505, 267, 410, 452, 3299, 24168, 22187, 262, 63, 719, 63, 600, 395, 2672, 1562, 63, 600, 2736, 267, 2672, 262, 63, 719, 63, 600, 14, 1984, 2209, 22187, 1562, 63, 600, 2736, 267, 21464, 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 ]
[ 1898, 334, 67, 9, 21300, 13, 9300, 7173, 577, 14, 869, 778, 436, 20232, 437, 14, 644, 23521, 199, 3, 1898, 334, 67, 9, 8937, 710, 27849, 13, 29471, 15290, 15878, 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, 199, 504, 308, 606, 67, 14, 1810, 14, 15173, 11307, 492, 29697, 11307, 199, 199, 533, 1933, 452, 3325, 7536, 15173, 11307, 8, 15173, 11307, 304, 272, 347, 636, 826, 721, 277, 12, 308, 606, 67, 12, 315, 63, 719, 12, 2287, 304, 267, 1613, 8, 15173, 11307, 12, 291, 2843, 826, 721, 83, 606, 67, 9, 267, 291, 14, 262, 63, 719, 275, 315, 63, 719, 267, 291, 14, 1562, 275, 2287, 5493, 347, 636, 2722, 721, 277, 304, 267, 372, 7369, 933, 452, 3325, 7536, 15173, 33, 270, 26, 450, 82, 8480, 450, 291, 14, 1975, 339, 347, 3550, 8, 277, 12, 1233, 12, 372, 63, 466, 304, 267, 291, 14, 262, 63, 719, 14, 479, 804, 480, 607, 4313, 531, 267, 291, 14, 1562, 14, 479, 804, 480, 1476, 531, 398, 315, 63, 719, 63, 600, 275, 291, 14, 262, 63, 719, 14, 1391, 14, 600, 267, 2287, 63, 600, 275, 291, 14, 1562, 14, 1391, 14, 600, 267, 1233, 10505, 267, 410, 452, 3299, 24168, 22187, 262, 63, 719, 63, 600, 395, 2672, 1562, 63, 600, 2736, 267, 2672, 262, 63, 719, 63, 600, 14, 1984, 2209, 22187, 1562, 63, 600, 2736, 267, 21464, 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, 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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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 ]
samfpetersen/gnuradio
gr-qtgui/apps/plot_spectrogram_form.py
47
7029
#!/usr/bin/env python # # Copyright 2013 Free Software Foundation, Inc. # # This file is part of GNU Radio # # GNU Radio 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, or (at your option) # any later version. # # GNU Radio 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 GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # import sys from gnuradio import filter try: from PyQt4 import QtGui, QtCore import sip except ImportError: print "Error: Program requires PyQt4." sys.exit(1) try: from gnuradio.qtgui.plot_from import plot_form except ImportError: from plot_form import plot_form class plot_spectrogram_form(plot_form): def __init__(self, top_block, title=''): plot_form.__init__(self, top_block, title) self.right_col_layout = QtGui.QVBoxLayout() self.right_col_form = QtGui.QFormLayout() self.right_col_layout.addLayout(self.right_col_form) self.layout.addLayout(self.right_col_layout, 1,4,1,1) self.psd_size_val = QtGui.QIntValidator(0, 2**18, self) self.psd_size_edit = QtGui.QLineEdit(self) self.psd_size_edit.setMinimumWidth(50) self.psd_size_edit.setMaximumWidth(100) self.psd_size_edit.setText(QtCore.QString("%1").arg(top_block._psd_size)) self.psd_size_edit.setValidator(self.psd_size_val) self.right_col_form.addRow("FFT Size:", self.psd_size_edit) self.connect(self.psd_size_edit, QtCore.SIGNAL("returnPressed()"), self.update_psd_size) self.psd_win_combo = QtGui.QComboBox(self) self.psd_win_combo.addItems(["None", "Hamming", "Hann", "Blackman", "Rectangular", "Kaiser", "Blackman-harris"]) self.psd_win_combo.setCurrentIndex(self.top_block.gui_snk.fft_window()+1) self.right_col_form.addRow("Window:", self.psd_win_combo) self.connect(self.psd_win_combo, QtCore.SIGNAL("currentIndexChanged(int)"), self.update_psd_win) self.psd_avg_val = QtGui.QDoubleValidator(0, 1.0, 4, self) self.psd_avg_edit = QtGui.QLineEdit(self) self.psd_avg_edit.setMinimumWidth(50) self.psd_avg_edit.setMaximumWidth(100) self.psd_avg_edit.setText(QtCore.QString("%1").arg(top_block._avg)) self.psd_avg_edit.setValidator(self.psd_avg_val) self.right_col_form.addRow("Average:", self.psd_avg_edit) self.connect(self.psd_avg_edit, QtCore.SIGNAL("returnPressed()"), self.update_psd_avg) self.autoscale_button = QtGui.QPushButton("Auto Scale", self) self.autoscale_button.setMaximumWidth(100) self.right_col_layout.addWidget(self.autoscale_button) self.connect(self.autoscale_button, QtCore.SIGNAL("clicked()"), self.spectrogram_auto_scale) self.add_spectrogram_control(self.right_col_layout) def update_psd_size(self): newpsdsize = self.psd_size_edit.text().toInt()[0] if(newpsdsize != self.top_block._psd_size): self.top_block.gui_snk.set_fft_size(newpsdsize) self.top_block._psd_size = newpsdsize self.top_block.reset(self.top_block._start, self.top_block._nsamps) def update_psd_win(self, index): self.top_block.gui_snk.set_fft_window(index-1) self.top_block.reset(self.top_block._start, self.top_block._nsamps) def update_psd_avg(self): newpsdavg = self.psd_avg_edit.text().toDouble()[0] if(newpsdavg != self.top_block._avg): self.top_block.gui_snk.set_fft_average(newpsdavg) self.top_block._avg = newpsdavg self.top_block.reset(self.top_block._start, self.top_block._nsamps) def add_spectrogram_control(self, layout): self._line_tabs = QtGui.QTabWidget() self._line_pages = [] self._line_forms = [] self._label_edit = [] self._size_edit = [] self._color_edit = [] self._style_edit = [] self._marker_edit = [] self._alpha_edit = [] for n in xrange(self.top_block._nsigs): self._line_pages.append(QtGui.QDialog()) self._line_forms.append(QtGui.QFormLayout(self._line_pages[-1])) label = self.top_block.gui_snk.line_label(n) self._label_edit.append(QtGui.QLineEdit(self)) self._label_edit[-1].setMinimumWidth(125) self._label_edit[-1].setMaximumWidth(125) self._label_edit[-1].setText(QtCore.QString("%1").arg(label)) self._line_forms[-1].addRow("Label:", self._label_edit[-1]) self.connect(self._label_edit[-1], QtCore.SIGNAL("returnPressed()"), self.update_line_label) self._qtcolormaps = ["Multi Color", "White Hot", "Black Hot", "Incandescent"] self._color_edit.append(QtGui.QComboBox(self)) self._color_edit[-1].addItems(self._qtcolormaps) self._line_forms[-1].addRow("Color Map:", self._color_edit[-1]) self.connect(self._color_edit[-1], QtCore.SIGNAL("currentIndexChanged(int)"), self.update_color_map) alpha_val = QtGui.QDoubleValidator(0, 1.0, 2, self) alpha_val.setTop(1.0) alpha = self.top_block.gui_snk.line_alpha(n) self._alpha_edit.append(QtGui.QLineEdit(self)) self._alpha_edit[-1].setMinimumWidth(50) self._alpha_edit[-1].setMaximumWidth(100) self._alpha_edit[-1].setText(QtCore.QString("%1").arg(alpha)) self._alpha_edit[-1].setValidator(alpha_val) self._line_forms[-1].addRow("Alpha:", self._alpha_edit[-1]) self.connect(self._alpha_edit[-1], QtCore.SIGNAL("returnPressed()"), self.update_line_alpha) self._line_tabs.addTab(self._line_pages[-1], "{0}".format(label)) layout.addWidget(self._line_tabs) def update_color_map(self, c_index): index = self._line_tabs.currentIndex() self.top_block.gui_snk.set_color_map(index, c_index) self.update_line_alpha() def spectrogram_auto_scale(self): self.top_block.gui_snk.auto_scale() _min = self.top_block.gui_snk.min_intensity(0) _max = self.top_block.gui_snk.max_intensity(0) if(self.gui_y_axis): self.gui_y_axis(_min, _max)
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 6171, 2868, 2290, 2752, 12, 3277, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 1664, 13514, 199, 3, 199, 3, 1664, 13514, 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, 650, 12, 503, 334, 292, 2195, 945, 9, 199, 3, 1263, 2945, 1015, 14, 199, 3, 199, 3, 1664, 13514, 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, 1664, 13514, 27, 1937, 314, 570, 9685, 14, 221, 982, 440, 12, 2218, 370, 199, 3, 314, 2868, 2290, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 199, 3, 8226, 12, 4828, 11315, 13, 10067, 12, 8217, 14, 199, 3, 199, 199, 646, 984, 199, 504, 24526, 492, 2457, 199, 199, 893, 26, 272, 687, 14084, 20, 492, 5928, 12, 10565, 272, 492, 25342, 199, 2590, 3545, 26, 272, 870, 298, 547, 26, 18841, 5074, 14084, 20, 2122, 272, 984, 14, 2224, 8, 17, 9, 199, 199, 893, 26, 272, 687, 24526, 14, 8440, 5885, 14, 2798, 63, 504, 492, 5137, 63, 964, 199, 2590, 3545, 26, 272, 687, 5137, 63, 964, 492, 5137, 63, 964, 199, 199, 533, 5137, 63, 20865, 293, 1679, 63, 964, 8, 2798, 63, 964, 304, 272, 347, 636, 826, 721, 277, 12, 2746, 63, 1457, 12, 2538, 9280, 267, 5137, 63, 964, 855, 826, 721, 277, 12, 2746, 63, 1457, 12, 2538, 9, 398, 291, 14, 1019, 63, 761, 63, 4209, 275, 5928, 14, 25527, 18536, 342, 267, 291, 14, 1019, 63, 761, 63, 964, 275, 5928, 14, 49, 2821, 4798, 342, 267, 291, 14, 1019, 63, 761, 63, 4209, 14, 30571, 8, 277, 14, 1019, 63, 761, 63, 964, 9, 267, 291, 14, 4209, 14, 30571, 8, 277, 14, 1019, 63, 761, 63, 4209, 12, 413, 12, 20, 12, 17, 12, 17, 9, 398, 291, 14, 31600, 63, 890, 63, 637, 275, 5928, 14, 49, 3241, 8640, 8, 16, 12, 499, 538, 1085, 12, 291, 9, 267, 291, 14, 31600, 63, 890, 63, 3773, 275, 5928, 14, 32141, 4685, 8, 277, 9, 267, 291, 14, 31600, 63, 890, 63, 3773, 14, 32608, 6216, 8, 1400, 9, 267, 291, 14, 31600, 63, 890, 63, 3773, 14, 409, 10915, 6216, 8, 1960, 9, 267, 291, 14, 31600, 63, 890, 63, 3773, 14, 8341, 8, 10901, 14, 49, 1558, 3647, 17, 3471, 1273, 8, 2119, 63, 1457, 423, 31600, 63, 890, 430, 267, 291, 14, 31600, 63, 890, 63, 3773, 14, 409, 8640, 8, 277, 14, 31600, 63, 890, 63, 637, 9, 267, 291, 14, 1019, 63, 761, 63, 964, 14, 525, 5810, 480, 1665, 52, 14579, 6783, 291, 14, 31600, 63, 890, 63, 3773, 9, 267, 291, 14, 2242, 8, 277, 14, 31600, 63, 890, 63, 3773, 12, 10565, 14, 16496, 480, 1107, 32153, 26322, 2151, 291, 14, 873, 63, 31600, 63, 890, 9, 398, 291, 14, 31600, 63, 2676, 63, 12650, 275, 5928, 14, 49, 17491, 8, 277, 9, 267, 291, 14, 31600, 63, 2676, 63, 12650, 14, 525, 7412, 5234, 403, 401, 298, 40, 455, 14566, 401, 298, 40, 1189, 401, 298, 23405, 1237, 401, 3660, 298, 8252, 11572, 401, 298, 43, 5789, 332, 401, 298, 23405, 1237, 13, 8210, 5719, 3135, 267, 291, 14, 31600, 63, 2676, 63, 12650, 14, 31549, 8, 277, 14, 2119, 63, 1457, 14, 5885, 63, 5167, 75, 14, 9996, 63, 3806, 24543, 17, 9, 267, 291, 14, 1019, 63, 761, 63, 964, 14, 525, 5810, 480, 4301, 6783, 291, 14, 31600, 63, 2676, 63, 12650, 9, 267, 291, 14, 2242, 8, 277, 14, 31600, 63, 2676, 63, 12650, 12, 2151, 10565, 14, 16496, 480, 29003, 6970, 8, 442, 13185, 2151, 291, 14, 873, 63, 31600, 63, 2676, 9, 398, 291, 14, 31600, 63, 8595, 63, 637, 275, 5928, 14, 49, 7281, 8640, 8, 16, 12, 413, 14, 16, 12, 841, 12, 291, 9, 267, 291, 14, 31600, 63, 8595, 63, 3773, 275, 5928, 14, 32141, 4685, 8, 277, 9, 267, 291, 14, 31600, 63, 8595, 63, 3773, 14, 32608, 6216, 8, 1400, 9, 267, 291, 14, 31600, 63, 8595, 63, 3773, 14, 409, 10915, 6216, 8, 1960, 9, 267, 291, 14, 31600, 63, 8595, 63, 3773, 14, 8341, 8, 10901, 14, 49, 1558, 3647, 17, 3471, 1273, 8, 2119, 63, 1457, 423, 8595, 430, 267, 291, 14, 31600, 63, 8595, 63, 3773, 14, 409, 8640, 8, 277, 14, 31600, 63, 8595, 63, 637, 9, 267, 291, 14, 1019, 63, 761, 63, 964, 14, 525, 5810, 480, 17400, 6783, 291, 14, 31600, 63, 8595, 63, 3773, 9, 267, 291, 14, 2242, 8, 277, 14, 31600, 63, 8595, 63, 3773, 12, 10565, 14, 16496, 480, 1107, 32153, 26322, 2151, 291, 14, 873, 63, 31600, 63, 8595, 9, 398, 291, 14, 29906, 63, 3887, 275, 5928, 14, 29116, 480, 3358, 22869, 401, 291, 9, 267, 291, 14, 29906, 63, 3887, 14, 409, 10915, 6216, 8, 1960, 9, 267, 291, 14, 1019, 63, 761, 63, 4209, 14, 9475, 8, 277, 14, 29906, 63, 3887, 9, 267, 291, 14, 2242, 8, 277, 14, 29906, 63, 3887, 12, 10565, 14, 16496, 480, 11276, 26322, 2151, 291, 14, 20865, 293, 1679, 63, 2495, 63, 3467, 9, 398, 291, 14, 525, 63, 20865, 293, 1679, 63, 2785, 8, 277, 14, 1019, 63, 761, 63, 4209, 9, 339, 347, 1678, 63, 31600, 63, 890, 8, 277, 304, 267, 892, 31600, 890, 275, 291, 14, 31600, 63, 890, 63, 3773, 14, 505, 1252, 475, 3241, 3430, 16, 61, 267, 340, 8, 1222, 31600, 890, 1137, 291, 14, 2119, 63, 1457, 423, 31600, 63, 890, 304, 288, 291, 14, 2119, 63, 1457, 14, 5885, 63, 5167, 75, 14, 409, 63, 9996, 63, 890 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 6171, 2868, 2290, 2752, 12, 3277, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 1664, 13514, 199, 3, 199, 3, 1664, 13514, 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, 650, 12, 503, 334, 292, 2195, 945, 9, 199, 3, 1263, 2945, 1015, 14, 199, 3, 199, 3, 1664, 13514, 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, 1664, 13514, 27, 1937, 314, 570, 9685, 14, 221, 982, 440, 12, 2218, 370, 199, 3, 314, 2868, 2290, 2752, 12, 3277, 2020, 8026, 11236, 14259, 12, 199, 3, 8226, 12, 4828, 11315, 13, 10067, 12, 8217, 14, 199, 3, 199, 199, 646, 984, 199, 504, 24526, 492, 2457, 199, 199, 893, 26, 272, 687, 14084, 20, 492, 5928, 12, 10565, 272, 492, 25342, 199, 2590, 3545, 26, 272, 870, 298, 547, 26, 18841, 5074, 14084, 20, 2122, 272, 984, 14, 2224, 8, 17, 9, 199, 199, 893, 26, 272, 687, 24526, 14, 8440, 5885, 14, 2798, 63, 504, 492, 5137, 63, 964, 199, 2590, 3545, 26, 272, 687, 5137, 63, 964, 492, 5137, 63, 964, 199, 199, 533, 5137, 63, 20865, 293, 1679, 63, 964, 8, 2798, 63, 964, 304, 272, 347, 636, 826, 721, 277, 12, 2746, 63, 1457, 12, 2538, 9280, 267, 5137, 63, 964, 855, 826, 721, 277, 12, 2746, 63, 1457, 12, 2538, 9, 398, 291, 14, 1019, 63, 761, 63, 4209, 275, 5928, 14, 25527, 18536, 342, 267, 291, 14, 1019, 63, 761, 63, 964, 275, 5928, 14, 49, 2821, 4798, 342, 267, 291, 14, 1019, 63, 761, 63, 4209, 14, 30571, 8, 277, 14, 1019, 63, 761, 63, 964, 9, 267, 291, 14, 4209, 14, 30571, 8, 277, 14, 1019, 63, 761, 63, 4209, 12, 413, 12, 20, 12, 17, 12, 17, 9, 398, 291, 14, 31600, 63, 890, 63, 637, 275, 5928, 14, 49, 3241, 8640, 8, 16, 12, 499, 538, 1085, 12, 291, 9, 267, 291, 14, 31600, 63, 890, 63, 3773, 275, 5928, 14, 32141, 4685, 8, 277, 9, 267, 291, 14, 31600, 63, 890, 63, 3773, 14, 32608, 6216, 8, 1400, 9, 267, 291, 14, 31600, 63, 890, 63, 3773, 14, 409, 10915, 6216, 8, 1960, 9, 267, 291, 14, 31600, 63, 890, 63, 3773, 14, 8341, 8, 10901, 14, 49, 1558, 3647, 17, 3471, 1273, 8, 2119, 63, 1457, 423, 31600, 63, 890, 430, 267, 291, 14, 31600, 63, 890, 63, 3773, 14, 409, 8640, 8, 277, 14, 31600, 63, 890, 63, 637, 9, 267, 291, 14, 1019, 63, 761, 63, 964, 14, 525, 5810, 480, 1665, 52, 14579, 6783, 291, 14, 31600, 63, 890, 63, 3773, 9, 267, 291, 14, 2242, 8, 277, 14, 31600, 63, 890, 63, 3773, 12, 10565, 14, 16496, 480, 1107, 32153, 26322, 2151, 291, 14, 873, 63, 31600, 63, 890, 9, 398, 291, 14, 31600, 63, 2676, 63, 12650, 275, 5928, 14, 49, 17491, 8, 277, 9, 267, 291, 14, 31600, 63, 2676, 63, 12650, 14, 525, 7412, 5234, 403, 401, 298, 40, 455, 14566, 401, 298, 40, 1189, 401, 298, 23405, 1237, 401, 3660, 298, 8252, 11572, 401, 298, 43, 5789, 332, 401, 298, 23405, 1237, 13, 8210, 5719, 3135, 267, 291, 14, 31600, 63, 2676, 63, 12650, 14, 31549, 8, 277, 14, 2119, 63, 1457, 14, 5885, 63, 5167, 75, 14, 9996, 63, 3806, 24543, 17, 9, 267, 291, 14, 1019, 63, 761, 63, 964, 14, 525, 5810, 480, 4301, 6783, 291, 14, 31600, 63, 2676, 63, 12650, 9, 267, 291, 14, 2242, 8, 277, 14, 31600, 63, 2676, 63, 12650, 12, 2151, 10565, 14, 16496, 480, 29003, 6970, 8, 442, 13185, 2151, 291, 14, 873, 63, 31600, 63, 2676, 9, 398, 291, 14, 31600, 63, 8595, 63, 637, 275, 5928, 14, 49, 7281, 8640, 8, 16, 12, 413, 14, 16, 12, 841, 12, 291, 9, 267, 291, 14, 31600, 63, 8595, 63, 3773, 275, 5928, 14, 32141, 4685, 8, 277, 9, 267, 291, 14, 31600, 63, 8595, 63, 3773, 14, 32608, 6216, 8, 1400, 9, 267, 291, 14, 31600, 63, 8595, 63, 3773, 14, 409, 10915, 6216, 8, 1960, 9, 267, 291, 14, 31600, 63, 8595, 63, 3773, 14, 8341, 8, 10901, 14, 49, 1558, 3647, 17, 3471, 1273, 8, 2119, 63, 1457, 423, 8595, 430, 267, 291, 14, 31600, 63, 8595, 63, 3773, 14, 409, 8640, 8, 277, 14, 31600, 63, 8595, 63, 637, 9, 267, 291, 14, 1019, 63, 761, 63, 964, 14, 525, 5810, 480, 17400, 6783, 291, 14, 31600, 63, 8595, 63, 3773, 9, 267, 291, 14, 2242, 8, 277, 14, 31600, 63, 8595, 63, 3773, 12, 10565, 14, 16496, 480, 1107, 32153, 26322, 2151, 291, 14, 873, 63, 31600, 63, 8595, 9, 398, 291, 14, 29906, 63, 3887, 275, 5928, 14, 29116, 480, 3358, 22869, 401, 291, 9, 267, 291, 14, 29906, 63, 3887, 14, 409, 10915, 6216, 8, 1960, 9, 267, 291, 14, 1019, 63, 761, 63, 4209, 14, 9475, 8, 277, 14, 29906, 63, 3887, 9, 267, 291, 14, 2242, 8, 277, 14, 29906, 63, 3887, 12, 10565, 14, 16496, 480, 11276, 26322, 2151, 291, 14, 20865, 293, 1679, 63, 2495, 63, 3467, 9, 398, 291, 14, 525, 63, 20865, 293, 1679, 63, 2785, 8, 277, 14, 1019, 63, 761, 63, 4209, 9, 339, 347, 1678, 63, 31600, 63, 890, 8, 277, 304, 267, 892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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 ]
mnahm5/django-estore
Lib/site-packages/PIL/IcnsImagePlugin.py
26
10597
# # The Python Imaging Library. # $Id$ # # Mac OS X icns file decoder, based on icns.py by Bob Ippolito. # # history: # 2004-10-09 fl Turned into a PIL plugin; removed 2.3 dependencies. # # Copyright (c) 2004 by Bob Ippolito. # Copyright (c) 2004 by Secret Labs. # Copyright (c) 2004 by Fredrik Lundh. # Copyright (c) 2014 by Alastair Houghton. # # See the README file for information on usage and redistribution. # from PIL import Image, ImageFile, PngImagePlugin, _binary import io import os import shutil import struct import sys import tempfile enable_jpeg2k = hasattr(Image.core, 'jp2klib_version') if enable_jpeg2k: from PIL import Jpeg2KImagePlugin i8 = _binary.i8 HEADERSIZE = 8 def nextheader(fobj): return struct.unpack('>4sI', fobj.read(HEADERSIZE)) def read_32t(fobj, start_length, size): # The 128x128 icon seems to have an extra header for some reason. (start, length) = start_length fobj.seek(start) sig = fobj.read(4) if sig != b'\x00\x00\x00\x00': raise SyntaxError('Unknown signature, expecting 0x00000000') return read_32(fobj, (start + 4, length - 4), size) def read_32(fobj, start_length, size): """ Read a 32bit RGB icon resource. Seems to be either uncompressed or an RLE packbits-like scheme. """ (start, length) = start_length fobj.seek(start) pixel_size = (size[0] * size[2], size[1] * size[2]) sizesq = pixel_size[0] * pixel_size[1] if length == sizesq * 3: # uncompressed ("RGBRGBGB") indata = fobj.read(length) im = Image.frombuffer("RGB", pixel_size, indata, "raw", "RGB", 0, 1) else: # decode image im = Image.new("RGB", pixel_size, None) for band_ix in range(3): data = [] bytesleft = sizesq while bytesleft > 0: byte = fobj.read(1) if not byte: break byte = i8(byte) if byte & 0x80: blocksize = byte - 125 byte = fobj.read(1) for i in range(blocksize): data.append(byte) else: blocksize = byte + 1 data.append(fobj.read(blocksize)) bytesleft -= blocksize if bytesleft <= 0: break if bytesleft != 0: raise SyntaxError( "Error reading channel [%r left]" % bytesleft ) band = Image.frombuffer( "L", pixel_size, b"".join(data), "raw", "L", 0, 1 ) im.im.putband(band.im, band_ix) return {"RGB": im} def read_mk(fobj, start_length, size): # Alpha masks seem to be uncompressed start = start_length[0] fobj.seek(start) pixel_size = (size[0] * size[2], size[1] * size[2]) sizesq = pixel_size[0] * pixel_size[1] band = Image.frombuffer( "L", pixel_size, fobj.read(sizesq), "raw", "L", 0, 1 ) return {"A": band} def read_png_or_jpeg2000(fobj, start_length, size): (start, length) = start_length fobj.seek(start) sig = fobj.read(12) if sig[:8] == b'\x89PNG\x0d\x0a\x1a\x0a': fobj.seek(start) im = PngImagePlugin.PngImageFile(fobj) return {"RGBA": im} elif sig[:4] == b'\xff\x4f\xff\x51' \ or sig[:4] == b'\x0d\x0a\x87\x0a' \ or sig == b'\x00\x00\x00\x0cjP \x0d\x0a\x87\x0a': if not enable_jpeg2k: raise ValueError('Unsupported icon subimage format (rebuild PIL ' 'with JPEG 2000 support to fix this)') # j2k, jpc or j2c fobj.seek(start) jp2kstream = fobj.read(length) f = io.BytesIO(jp2kstream) im = Jpeg2KImagePlugin.Jpeg2KImageFile(f) if im.mode != 'RGBA': im = im.convert('RGBA') return {"RGBA": im} else: raise ValueError('Unsupported icon subimage format') class IcnsFile(object): SIZES = { (512, 512, 2): [ (b'ic10', read_png_or_jpeg2000), ], (512, 512, 1): [ (b'ic09', read_png_or_jpeg2000), ], (256, 256, 2): [ (b'ic14', read_png_or_jpeg2000), ], (256, 256, 1): [ (b'ic08', read_png_or_jpeg2000), ], (128, 128, 2): [ (b'ic13', read_png_or_jpeg2000), ], (128, 128, 1): [ (b'ic07', read_png_or_jpeg2000), (b'it32', read_32t), (b't8mk', read_mk), ], (64, 64, 1): [ (b'icp6', read_png_or_jpeg2000), ], (32, 32, 2): [ (b'ic12', read_png_or_jpeg2000), ], (48, 48, 1): [ (b'ih32', read_32), (b'h8mk', read_mk), ], (32, 32, 1): [ (b'icp5', read_png_or_jpeg2000), (b'il32', read_32), (b'l8mk', read_mk), ], (16, 16, 2): [ (b'ic11', read_png_or_jpeg2000), ], (16, 16, 1): [ (b'icp4', read_png_or_jpeg2000), (b'is32', read_32), (b's8mk', read_mk), ], } def __init__(self, fobj): """ fobj is a file-like object as an icns resource """ # signature : (start, length) self.dct = dct = {} self.fobj = fobj sig, filesize = nextheader(fobj) if sig != b'icns': raise SyntaxError('not an icns file') i = HEADERSIZE while i < filesize: sig, blocksize = nextheader(fobj) if blocksize <= 0: raise SyntaxError('invalid block header') i += HEADERSIZE blocksize -= HEADERSIZE dct[sig] = (i, blocksize) fobj.seek(blocksize, 1) i += blocksize def itersizes(self): sizes = [] for size, fmts in self.SIZES.items(): for (fmt, reader) in fmts: if fmt in self.dct: sizes.append(size) break return sizes def bestsize(self): sizes = self.itersizes() if not sizes: raise SyntaxError("No 32bit icon resources found") return max(sizes) def dataforsize(self, size): """ Get an icon resource as {channel: array}. Note that the arrays are bottom-up like windows bitmaps and will likely need to be flipped or transposed in some way. """ dct = {} for code, reader in self.SIZES[size]: desc = self.dct.get(code) if desc is not None: dct.update(reader(self.fobj, desc, size)) return dct def getimage(self, size=None): if size is None: size = self.bestsize() if len(size) == 2: size = (size[0], size[1], 1) channels = self.dataforsize(size) im = channels.get('RGBA', None) if im: return im im = channels.get("RGB").copy() try: im.putalpha(channels["A"]) except KeyError: pass return im ## # Image plugin for Mac OS icons. class IcnsImageFile(ImageFile.ImageFile): """ PIL image support for Mac OS .icns files. Chooses the best resolution, but will possibly load a different size image if you mutate the size attribute before calling 'load'. The info dictionary has a key 'sizes' that is a list of sizes that the icns file has. """ format = "ICNS" format_description = "Mac OS icns resource" def _open(self): self.icns = IcnsFile(self.fp) self.mode = 'RGBA' self.best_size = self.icns.bestsize() self.size = (self.best_size[0] * self.best_size[2], self.best_size[1] * self.best_size[2]) self.info['sizes'] = self.icns.itersizes() # Just use this to see if it's loaded or not yet. self.tile = ('',) def load(self): if len(self.size) == 3: self.best_size = self.size self.size = (self.best_size[0] * self.best_size[2], self.best_size[1] * self.best_size[2]) Image.Image.load(self) if not self.tile: return self.load_prepare() # This is likely NOT the best way to do it, but whatever. im = self.icns.getimage(self.best_size) # If this is a PNG or JPEG 2000, it won't be loaded yet im.load() self.im = im.im self.mode = im.mode self.size = im.size self.fp = None self.icns = None self.tile = () self.load_end() def _save(im, fp, filename): """ Saves the image as a series of PNG files, that are then converted to a .icns file using the OS X command line utility 'iconutil'. OS X only. """ try: fp.flush() except: pass # create the temporary set of pngs iconset = tempfile.mkdtemp('.iconset') last_w = None last_im = None for w in [16, 32, 128, 256, 512]: prefix = 'icon_{}x{}'.format(w, w) if last_w == w: im_scaled = last_im else: im_scaled = im.resize((w, w), Image.LANCZOS) im_scaled.save(os.path.join(iconset, prefix+'.png')) im_scaled = im.resize((w*2, w*2), Image.LANCZOS) im_scaled.save(os.path.join(iconset, prefix+'@2x.png')) last_im = im_scaled # iconutil -c icns -o {} {} from subprocess import Popen, PIPE, CalledProcessError convert_cmd = ["iconutil", "-c", "icns", "-o", filename, iconset] stderr = tempfile.TemporaryFile() convert_proc = Popen(convert_cmd, stdout=PIPE, stderr=stderr) convert_proc.stdout.close() retcode = convert_proc.wait() # remove the temporary files shutil.rmtree(iconset) if retcode: raise CalledProcessError(retcode, convert_cmd) Image.register_open("ICNS", IcnsImageFile, lambda x: x[:4] == b'icns') Image.register_extension("ICNS", '.icns') if sys.platform == 'darwin': Image.register_save("ICNS", _save) Image.register_mime("ICNS", "image/icns") if __name__ == '__main__': imf = IcnsImageFile(open(sys.argv[1], 'rb')) for size in imf.info['sizes']: imf.size = size imf.load() im = imf.im im.save('out-%s-%s-%s.png' % size) im = Image.open(open(sys.argv[1], "rb")) im.save("out.png") if sys.platform == 'windows': os.startfile("out.png")
mit
[ 3, 199, 3, 710, 2018, 473, 391, 1540, 11243, 14, 199, 3, 2672, 1304, 4, 199, 3, 199, 3, 10444, 4403, 1323, 284, 67, 561, 570, 10334, 12, 4079, 641, 284, 67, 561, 14, 647, 701, 699, 2873, 31045, 555, 317, 475, 14, 199, 3, 199, 3, 7994, 26, 199, 3, 8353, 13, 709, 13, 1643, 2717, 257, 16147, 379, 1901, 282, 14937, 3589, 27, 4829, 499, 14, 19, 5124, 14, 199, 3, 199, 3, 1898, 334, 67, 9, 8353, 701, 699, 2873, 31045, 555, 317, 475, 14, 199, 3, 1898, 334, 67, 9, 8353, 701, 23580, 491, 2101, 14, 199, 3, 1898, 334, 67, 9, 8353, 701, 481, 581, 25844, 491, 725, 72, 14, 199, 3, 1898, 334, 67, 9, 6927, 701, 437, 416, 1207, 723, 869, 20816, 265, 14, 199, 3, 199, 3, 1666, 314, 27781, 570, 367, 2556, 641, 4503, 436, 295, 4972, 14, 199, 3, 199, 199, 504, 14937, 492, 6047, 12, 6047, 1173, 12, 510, 2753, 3491, 5061, 12, 485, 3008, 199, 646, 5890, 199, 646, 747, 199, 646, 5145, 199, 646, 2702, 199, 646, 984, 199, 646, 5549, 199, 199, 4296, 63, 14230, 18, 75, 275, 2688, 8, 3491, 14, 1018, 12, 283, 11538, 18, 75, 773, 63, 1023, 358, 199, 692, 4756, 63, 14230, 18, 75, 26, 272, 687, 14937, 492, 1603, 11997, 18, 43, 3491, 5061, 199, 199, 73, 24, 275, 485, 3008, 14, 73, 24, 199, 199, 7311, 4305, 275, 1695, 421, 199, 318, 22761, 16946, 8, 32755, 304, 272, 372, 2702, 14, 5301, 16099, 20, 83, 41, 297, 29962, 14, 739, 8, 7311, 4305, 430, 421, 199, 318, 1586, 63, 708, 84, 8, 32755, 12, 1343, 63, 1267, 12, 1568, 304, 272, 327, 710, 7960, 88, 3933, 7016, 12237, 370, 1172, 376, 2402, 1406, 367, 2005, 4499, 14, 272, 334, 928, 12, 2582, 9, 275, 1343, 63, 1267, 272, 29962, 14, 5507, 8, 928, 9, 272, 5259, 275, 29962, 14, 739, 8, 20, 9, 272, 340, 5259, 1137, 330, 1154, 88, 383, 60, 88, 383, 60, 88, 383, 60, 88, 383, 356, 267, 746, 12053, 360, 5912, 4955, 12, 21055, 378, 88, 3607, 358, 272, 372, 1586, 63, 708, 8, 32755, 12, 334, 928, 435, 841, 12, 2582, 446, 841, 395, 1568, 9, 421, 199, 318, 1586, 63, 708, 8, 32755, 12, 1343, 63, 1267, 12, 1568, 304, 272, 408, 272, 5574, 282, 4337, 2075, 19013, 7016, 2073, 14, 221, 1666, 706, 370, 506, 1902, 25904, 503, 272, 376, 820, 906, 1706, 5609, 13, 2930, 5687, 14, 272, 408, 272, 334, 928, 12, 2582, 9, 275, 1343, 63, 1267, 272, 29962, 14, 5507, 8, 928, 9, 272, 7148, 63, 890, 275, 334, 890, 59, 16, 61, 627, 1568, 59, 18, 467, 1568, 59, 17, 61, 627, 1568, 59, 18, 566, 272, 10627, 81, 275, 7148, 63, 890, 59, 16, 61, 627, 7148, 63, 890, 59, 17, 61, 272, 340, 2582, 508, 10627, 81, 627, 650, 26, 267, 327, 25904, 1689, 12067, 12067, 6487, 531, 267, 315, 576, 275, 29962, 14, 739, 8, 1267, 9, 267, 3416, 275, 6047, 14, 504, 2738, 480, 12067, 401, 7148, 63, 890, 12, 315, 576, 12, 298, 1773, 401, 298, 12067, 401, 378, 12, 413, 9, 272, 587, 26, 267, 327, 4849, 1834, 267, 3416, 275, 6047, 14, 1222, 480, 12067, 401, 7148, 63, 890, 12, 488, 9, 267, 367, 10981, 63, 1148, 315, 1425, 8, 19, 304, 288, 666, 275, 942, 288, 2783, 3039, 275, 10627, 81, 288, 1830, 2783, 3039, 690, 378, 26, 355, 3696, 275, 29962, 14, 739, 8, 17, 9, 355, 340, 440, 3696, 26, 490, 2059, 355, 3696, 275, 284, 24, 8, 4414, 9, 355, 340, 3696, 1253, 378, 88, 1257, 26, 490, 27461, 275, 3696, 446, 19163, 490, 3696, 275, 29962, 14, 739, 8, 17, 9, 490, 367, 284, 315, 1425, 8, 25959, 304, 717, 666, 14, 740, 8, 4414, 9, 355, 587, 26, 490, 27461, 275, 3696, 435, 413, 490, 666, 14, 740, 8, 32755, 14, 739, 8, 25959, 430, 355, 2783, 3039, 4862, 27461, 355, 340, 2783, 3039, 2695, 378, 26, 490, 2059, 288, 340, 2783, 3039, 1137, 378, 26, 355, 746, 12053, 8, 490, 298, 547, 7664, 3623, 8978, 82, 3602, 8480, 450, 2783, 3039, 490, 776, 288, 10981, 275, 6047, 14, 504, 2738, 8, 355, 298, 44, 401, 7148, 63, 890, 12, 330, 25148, 904, 8, 576, 395, 298, 1773, 401, 298, 44, 401, 378, 12, 413, 355, 776, 288, 3416, 14, 1017, 14, 524, 7877, 8, 7877, 14, 1017, 12, 10981, 63, 1148, 9, 272, 372, 2420, 12067, 582, 3416, 93, 421, 199, 318, 1586, 63, 3880, 8, 32755, 12, 1343, 63, 1267, 12, 1568, 304, 272, 327, 32657, 27996, 17021, 370, 506, 25904, 272, 1343, 275, 1343, 63, 1267, 59, 16, 61, 272, 29962, 14, 5507, 8, 928, 9, 272, 7148, 63, 890, 275, 334, 890, 59, 16, 61, 627, 1568, 59, 18, 467, 1568, 59, 17, 61, 627, 1568, 59, 18, 566, 272, 10627, 81, 275, 7148, 63, 890, 59, 16, 61, 627, 7148, 63, 890, 59, 17, 61, 272, 10981, 275, 6047, 14, 504, 2738, 8, 267, 298, 44, 401, 7148, 63, 890, 12, 29962, 14, 739, 8, 7723, 81, 395, 298, 1773, 401, 298, 44, 401, 378, 12, 413, 267, 776, 272, 372, 2420, 33, 582, 10981, 93, 421, 199, 318, 1586, 63, 4524, 63, 269, 63, 14230, 8269, 8, 32755, 12, 1343, 63, 1267, 12, 1568, 304, 272, 334, 928, 12, 2582, 9, 275, 1343, 63, 1267, 272, 29962, 14, 5507, 8, 928, 9, 272, 5259, 275, 29962, 14, 739, 8, 713, 9, 272, 340, 5259, 1491, 24, 61, 508, 330, 1154, 88, 1407, 24454, 60, 88, 16, 68, 60, 88, 16, 65, 60, 88, 17, 65, 60, 88, 16, 65, 356, 267, 29962, 14, 5507, 8, 928, 9, 267, 3416, 275, 510, 2753, 3491, 5061, 14, 48, 2753, 30636, 8, 32755, 9, 267, 372, 2420, 21631, 582, 3416, 93, 272, 916, 5259, 1491, 20, 61, 508, 330, 1154, 3581, 60, 88, 20, 70, 60, 3581, 60, 88, 2869, 7, 971, 288, 503, 5259, 1491, 20, 61, 508, 330, 1154, 88, 16, 68, 60, 88, 16, 65, 60, 88, 1555, 60, 88, 16 ]
[ 199, 3, 710, 2018, 473, 391, 1540, 11243, 14, 199, 3, 2672, 1304, 4, 199, 3, 199, 3, 10444, 4403, 1323, 284, 67, 561, 570, 10334, 12, 4079, 641, 284, 67, 561, 14, 647, 701, 699, 2873, 31045, 555, 317, 475, 14, 199, 3, 199, 3, 7994, 26, 199, 3, 8353, 13, 709, 13, 1643, 2717, 257, 16147, 379, 1901, 282, 14937, 3589, 27, 4829, 499, 14, 19, 5124, 14, 199, 3, 199, 3, 1898, 334, 67, 9, 8353, 701, 699, 2873, 31045, 555, 317, 475, 14, 199, 3, 1898, 334, 67, 9, 8353, 701, 23580, 491, 2101, 14, 199, 3, 1898, 334, 67, 9, 8353, 701, 481, 581, 25844, 491, 725, 72, 14, 199, 3, 1898, 334, 67, 9, 6927, 701, 437, 416, 1207, 723, 869, 20816, 265, 14, 199, 3, 199, 3, 1666, 314, 27781, 570, 367, 2556, 641, 4503, 436, 295, 4972, 14, 199, 3, 199, 199, 504, 14937, 492, 6047, 12, 6047, 1173, 12, 510, 2753, 3491, 5061, 12, 485, 3008, 199, 646, 5890, 199, 646, 747, 199, 646, 5145, 199, 646, 2702, 199, 646, 984, 199, 646, 5549, 199, 199, 4296, 63, 14230, 18, 75, 275, 2688, 8, 3491, 14, 1018, 12, 283, 11538, 18, 75, 773, 63, 1023, 358, 199, 692, 4756, 63, 14230, 18, 75, 26, 272, 687, 14937, 492, 1603, 11997, 18, 43, 3491, 5061, 199, 199, 73, 24, 275, 485, 3008, 14, 73, 24, 199, 199, 7311, 4305, 275, 1695, 421, 199, 318, 22761, 16946, 8, 32755, 304, 272, 372, 2702, 14, 5301, 16099, 20, 83, 41, 297, 29962, 14, 739, 8, 7311, 4305, 430, 421, 199, 318, 1586, 63, 708, 84, 8, 32755, 12, 1343, 63, 1267, 12, 1568, 304, 272, 327, 710, 7960, 88, 3933, 7016, 12237, 370, 1172, 376, 2402, 1406, 367, 2005, 4499, 14, 272, 334, 928, 12, 2582, 9, 275, 1343, 63, 1267, 272, 29962, 14, 5507, 8, 928, 9, 272, 5259, 275, 29962, 14, 739, 8, 20, 9, 272, 340, 5259, 1137, 330, 1154, 88, 383, 60, 88, 383, 60, 88, 383, 60, 88, 383, 356, 267, 746, 12053, 360, 5912, 4955, 12, 21055, 378, 88, 3607, 358, 272, 372, 1586, 63, 708, 8, 32755, 12, 334, 928, 435, 841, 12, 2582, 446, 841, 395, 1568, 9, 421, 199, 318, 1586, 63, 708, 8, 32755, 12, 1343, 63, 1267, 12, 1568, 304, 272, 408, 272, 5574, 282, 4337, 2075, 19013, 7016, 2073, 14, 221, 1666, 706, 370, 506, 1902, 25904, 503, 272, 376, 820, 906, 1706, 5609, 13, 2930, 5687, 14, 272, 408, 272, 334, 928, 12, 2582, 9, 275, 1343, 63, 1267, 272, 29962, 14, 5507, 8, 928, 9, 272, 7148, 63, 890, 275, 334, 890, 59, 16, 61, 627, 1568, 59, 18, 467, 1568, 59, 17, 61, 627, 1568, 59, 18, 566, 272, 10627, 81, 275, 7148, 63, 890, 59, 16, 61, 627, 7148, 63, 890, 59, 17, 61, 272, 340, 2582, 508, 10627, 81, 627, 650, 26, 267, 327, 25904, 1689, 12067, 12067, 6487, 531, 267, 315, 576, 275, 29962, 14, 739, 8, 1267, 9, 267, 3416, 275, 6047, 14, 504, 2738, 480, 12067, 401, 7148, 63, 890, 12, 315, 576, 12, 298, 1773, 401, 298, 12067, 401, 378, 12, 413, 9, 272, 587, 26, 267, 327, 4849, 1834, 267, 3416, 275, 6047, 14, 1222, 480, 12067, 401, 7148, 63, 890, 12, 488, 9, 267, 367, 10981, 63, 1148, 315, 1425, 8, 19, 304, 288, 666, 275, 942, 288, 2783, 3039, 275, 10627, 81, 288, 1830, 2783, 3039, 690, 378, 26, 355, 3696, 275, 29962, 14, 739, 8, 17, 9, 355, 340, 440, 3696, 26, 490, 2059, 355, 3696, 275, 284, 24, 8, 4414, 9, 355, 340, 3696, 1253, 378, 88, 1257, 26, 490, 27461, 275, 3696, 446, 19163, 490, 3696, 275, 29962, 14, 739, 8, 17, 9, 490, 367, 284, 315, 1425, 8, 25959, 304, 717, 666, 14, 740, 8, 4414, 9, 355, 587, 26, 490, 27461, 275, 3696, 435, 413, 490, 666, 14, 740, 8, 32755, 14, 739, 8, 25959, 430, 355, 2783, 3039, 4862, 27461, 355, 340, 2783, 3039, 2695, 378, 26, 490, 2059, 288, 340, 2783, 3039, 1137, 378, 26, 355, 746, 12053, 8, 490, 298, 547, 7664, 3623, 8978, 82, 3602, 8480, 450, 2783, 3039, 490, 776, 288, 10981, 275, 6047, 14, 504, 2738, 8, 355, 298, 44, 401, 7148, 63, 890, 12, 330, 25148, 904, 8, 576, 395, 298, 1773, 401, 298, 44, 401, 378, 12, 413, 355, 776, 288, 3416, 14, 1017, 14, 524, 7877, 8, 7877, 14, 1017, 12, 10981, 63, 1148, 9, 272, 372, 2420, 12067, 582, 3416, 93, 421, 199, 318, 1586, 63, 3880, 8, 32755, 12, 1343, 63, 1267, 12, 1568, 304, 272, 327, 32657, 27996, 17021, 370, 506, 25904, 272, 1343, 275, 1343, 63, 1267, 59, 16, 61, 272, 29962, 14, 5507, 8, 928, 9, 272, 7148, 63, 890, 275, 334, 890, 59, 16, 61, 627, 1568, 59, 18, 467, 1568, 59, 17, 61, 627, 1568, 59, 18, 566, 272, 10627, 81, 275, 7148, 63, 890, 59, 16, 61, 627, 7148, 63, 890, 59, 17, 61, 272, 10981, 275, 6047, 14, 504, 2738, 8, 267, 298, 44, 401, 7148, 63, 890, 12, 29962, 14, 739, 8, 7723, 81, 395, 298, 1773, 401, 298, 44, 401, 378, 12, 413, 267, 776, 272, 372, 2420, 33, 582, 10981, 93, 421, 199, 318, 1586, 63, 4524, 63, 269, 63, 14230, 8269, 8, 32755, 12, 1343, 63, 1267, 12, 1568, 304, 272, 334, 928, 12, 2582, 9, 275, 1343, 63, 1267, 272, 29962, 14, 5507, 8, 928, 9, 272, 5259, 275, 29962, 14, 739, 8, 713, 9, 272, 340, 5259, 1491, 24, 61, 508, 330, 1154, 88, 1407, 24454, 60, 88, 16, 68, 60, 88, 16, 65, 60, 88, 17, 65, 60, 88, 16, 65, 356, 267, 29962, 14, 5507, 8, 928, 9, 267, 3416, 275, 510, 2753, 3491, 5061, 14, 48, 2753, 30636, 8, 32755, 9, 267, 372, 2420, 21631, 582, 3416, 93, 272, 916, 5259, 1491, 20, 61, 508, 330, 1154, 3581, 60, 88, 20, 70, 60, 3581, 60, 88, 2869, 7, 971, 288, 503, 5259, 1491, 20, 61, 508, 330, 1154, 88, 16, 68, 60, 88, 16, 65, 60, 88, 1555, 60, 88, 16, 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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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 ]
mikekestemont/ruzicka
code/04latin_test_o2.py
1
3340
from __future__ import print_function import os import time import json import pickle import sys from itertools import product, combinations import matplotlib import matplotlib.pyplot as plt import seaborn as sns import pandas as pd import numpy as np from sklearn.preprocessing import LabelEncoder from ruzicka.utilities import binarize from ruzicka.vectorization import Vectorizer from ruzicka.utilities import load_pan_dataset, train_dev_split, get_vocab_size from sklearn.cross_validation import train_test_split from ruzicka.score_shifting import ScoreShifter from ruzicka.evaluation import pan_metrics from ruzicka.Order2Verifier import Order2Verifier as Verifier import ruzicka.art as art # run script for top-5 metrics ngram_type = 'word' ngram_size = 1 base = 'profile' vector_space = 'tf_std' metric = 'cosine' nb_bootstrap_iter = 100 rnd_prop = 0.5 nb_imposters = 30 mfi = sys.maxint min_df = 2 # get imposter data: train_data, _ = load_pan_dataset('../data/latin/dev') # ignore unknown documents train_labels, train_documents = zip(*train_data) # get test data: test_data, _ = load_pan_dataset('../data/latin/test') # ignore unknown documents test_labels, test_documents = zip(*test_data) # fit encoder for author labels: label_encoder = LabelEncoder() label_encoder.fit(train_labels+test_labels) train_ints = label_encoder.transform(train_labels) test_ints = label_encoder.transform(test_labels) # fit vectorizer: vectorizer = Vectorizer(mfi = mfi, vector_space = vector_space, ngram_type = ngram_type, ngram_size = ngram_size) vectorizer.fit(train_documents+test_documents) train_X = vectorizer.transform(train_documents).toarray() test_X = vectorizer.transform(test_documents).toarray() cols = ['label'] for test_author in sorted(set(test_ints)): auth_label = label_encoder.inverse_transform([test_author])[0] cols.append(auth_label) proba_df = pd.DataFrame(columns=cols) for idx in range(len(test_documents)): target_auth = test_ints[idx] target_docu = test_X[idx] non_target_test_ints = np.array([test_ints[i] for i in range(len(test_ints)) if i != idx]) non_target_test_X = np.array([test_X[i] for i in range(len(test_ints)) if i != idx]) tmp_train_X = np.vstack((train_X, non_target_test_X)) tmp_train_y = np.hstack((train_ints, non_target_test_ints)) tmp_test_X, tmp_test_y = [], [] for t_auth in sorted(set(test_ints)): tmp_test_X.append(target_docu) tmp_test_y.append(t_auth) # fit the verifier: verifier = Verifier(metric = metric, base = base, nb_bootstrap_iter = nb_bootstrap_iter, rnd_prop = rnd_prop) verifier.fit(tmp_train_X, tmp_train_y) probas = verifier.predict_proba(test_X = tmp_test_X, test_y = tmp_test_y, nb_imposters = nb_imposters) row = [label_encoder.inverse_transform([target_auth])[0]] # author label row += list(probas) print(row) proba_df.loc[len(proba_df)] = row proba_df = proba_df.set_index('label') # write away score tables: table_dir = '../output/tables/' if not os.path.isdir(table_dir): os.mkdir(table_dir) proba_df.to_csv(table_dir+'lat_proba_'+metric+'_'+vector_space+'.csv')
mit
[ 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 199, 646, 900, 199, 646, 2022, 199, 646, 5927, 199, 646, 984, 199, 504, 7975, 492, 3336, 12, 15821, 199, 199, 646, 8027, 199, 646, 8027, 14, 13563, 465, 4488, 199, 646, 542, 371, 6161, 465, 308, 561, 199, 646, 10634, 465, 6454, 199, 646, 2680, 465, 980, 199, 199, 504, 6357, 14, 21402, 492, 10354, 6679, 199, 199, 504, 519, 9494, 2000, 65, 14, 16355, 492, 2517, 285, 794, 199, 504, 519, 9494, 2000, 65, 14, 4106, 2072, 492, 11388, 1793, 199, 504, 519, 9494, 2000, 65, 14, 16355, 492, 2248, 63, 10384, 63, 5214, 12, 3560, 63, 2374, 63, 1294, 12, 664, 63, 9953, 63, 890, 199, 504, 6357, 14, 7925, 63, 6136, 492, 3560, 63, 396, 63, 1294, 199, 504, 519, 9494, 2000, 65, 14, 3397, 63, 26063, 1337, 492, 25318, 2662, 692, 351, 199, 504, 519, 9494, 2000, 65, 14, 19154, 492, 21379, 63, 6759, 199, 504, 519, 9494, 2000, 65, 14, 4738, 18, 3673, 9893, 492, 9240, 18, 3673, 9893, 465, 5444, 9893, 199, 646, 519, 9494, 2000, 65, 14, 580, 465, 24701, 199, 199, 3, 1255, 2884, 367, 2746, 13, 21, 7186, 199, 78, 1679, 63, 466, 275, 283, 1027, 7, 199, 78, 1679, 63, 890, 275, 413, 199, 1095, 275, 283, 2913, 7, 199, 4106, 63, 2638, 275, 283, 3249, 63, 1516, 7, 199, 5165, 275, 283, 28485, 7, 199, 4994, 63, 11146, 63, 1661, 275, 2948, 199, 30006, 63, 4469, 275, 378, 14, 21, 199, 4994, 63, 3236, 736, 878, 275, 4233, 199, 77, 329, 275, 984, 14, 21411, 199, 827, 63, 1587, 275, 499, 199, 199, 3, 664, 1742, 29895, 666, 26, 199, 2834, 63, 576, 12, 485, 275, 2248, 63, 10384, 63, 5214, 24592, 576, 15, 10378, 15, 2374, 358, 327, 3686, 5809, 8247, 199, 2834, 63, 3512, 12, 3560, 63, 12233, 275, 3482, 2031, 2834, 63, 576, 9, 199, 199, 3, 664, 511, 666, 26, 199, 396, 63, 576, 12, 485, 275, 2248, 63, 10384, 63, 5214, 24592, 576, 15, 10378, 15, 396, 358, 327, 3686, 5809, 8247, 199, 396, 63, 3512, 12, 511, 63, 12233, 275, 3482, 2031, 396, 63, 576, 9, 199, 199, 3, 5542, 10295, 367, 4132, 3628, 26, 199, 1302, 63, 9347, 275, 10354, 6679, 342, 199, 1302, 63, 9347, 14, 3269, 8, 2834, 63, 3512, 11, 396, 63, 3512, 9, 199, 2834, 63, 13141, 275, 1768, 63, 9347, 14, 4711, 8, 2834, 63, 3512, 9, 199, 396, 63, 13141, 275, 1768, 63, 9347, 14, 4711, 8, 396, 63, 3512, 9, 199, 199, 3, 5542, 5477, 1793, 26, 199, 4106, 1793, 275, 11388, 1793, 8, 77, 329, 275, 333, 329, 12, 717, 5477, 63, 2638, 275, 5477, 63, 2638, 12, 717, 302, 1679, 63, 466, 275, 302, 1679, 63, 466, 12, 717, 302, 1679, 63, 890, 275, 302, 1679, 63, 890, 9, 199, 4106, 1793, 14, 3269, 8, 2834, 63, 12233, 11, 396, 63, 12233, 9, 199, 2834, 63, 56, 275, 5477, 1793, 14, 4711, 8, 2834, 63, 12233, 680, 18993, 342, 199, 396, 63, 56, 275, 5477, 1793, 14, 4711, 8, 396, 63, 12233, 680, 18993, 342, 199, 199, 4574, 275, 788, 1302, 418, 199, 509, 511, 63, 2502, 315, 3355, 8, 409, 8, 396, 63, 13141, 2298, 272, 1790, 63, 1302, 275, 1768, 63, 9347, 14, 11668, 63, 4711, 779, 396, 63, 2502, 11057, 16, 61, 272, 8850, 14, 740, 8, 1178, 63, 1302, 9, 199, 199, 14417, 63, 1587, 275, 6454, 14, 9205, 8, 3406, 29, 4574, 9, 199, 199, 509, 4280, 315, 1425, 8, 552, 8, 396, 63, 12233, 2298, 272, 1347, 63, 1178, 275, 511, 63, 13141, 59, 2996, 61, 272, 1347, 63, 1301, 85, 275, 511, 63, 56, 59, 2996, 61, 272, 2222, 63, 1375, 63, 396, 63, 13141, 275, 980, 14, 1144, 779, 396, 63, 13141, 59, 73, 61, 367, 284, 315, 1425, 8, 552, 8, 396, 63, 13141, 430, 340, 284, 1137, 4280, 566, 272, 2222, 63, 1375, 63, 396, 63, 56, 275, 980, 14, 1144, 779, 396, 63, 56, 59, 73, 61, 367, 284, 315, 1425, 8, 552, 8, 396, 63, 13141, 430, 340, 284, 1137, 4280, 566, 272, 3529, 63, 2834, 63, 56, 275, 980, 14, 20221, 1332, 2834, 63, 56, 12, 2222, 63, 1375, 63, 396, 63, 56, 430, 272, 3529, 63, 2834, 63, 89, 275, 980, 14, 20949, 1332, 2834, 63, 13141, 12, 2222, 63, 1375, 63, 396, 63, 13141, 430, 2286, 3529, 63, 396, 63, 56, 12, 3529, 63, 396, 63, 89, 275, 990, 942, 272, 367, 307, 63, 1178, 315, 3355, 8, 409, 8, 396, 63, 13141, 2298, 267, 3529, 63, 396, 63, 56, 14, 740, 8, 1375, 63, 1301, 85, 9, 267, 3529, 63, 396, 63, 89, 14, 740, 8, 84, 63, 1178, 9, 339, 327, 5542, 314, 25581, 26, 272, 25581, 275, 5444, 9893, 8, 5165, 275, 6370, 12, 717, 1300, 275, 1300, 12, 717, 8526, 63, 11146, 63, 1661, 275, 8526, 63, 11146, 63, 1661, 12, 717, 20665, 63, 4469, 275, 20665, 63, 4469, 9, 272, 25581, 14, 3269, 8, 2791, 63, 2834, 63, 56, 12, 3529, 63, 2834, 63, 89, 9, 272, 5128, 305, 275, 25581, 14, 6892, 63, 14417, 8, 396, 63, 56, 275, 3529, 63, 396, 63, 56, 12, 717, 511, 63, 89, 275, 3529, 63, 396, 63, 89, 12, 717, 8526, 63, 3236, 736, 878, 275, 8526, 63, 3236, 736, 878, 9, 2286, 1962, 275, 359, 1302, 63, 9347, 14, 11668, 63, 4711, 779, 1375, 63, 1178, 11057, 16, 2677, 327, 4132, 1768, 272, 1962, 847, 769, 8, 6101, 305, 9, 272, 870, 8, 1143, 9, 272, 557, 2470, 63, 1587, 14, 2102, 59, 552, 8, 14417, 63, 1587, 1874, 275, 1962, 199, 199, 14417, 63, 1587, 275, 557, 2470, 63, 1587, 14, 409, 63, 1080, 360, 1302, 358, 199, 199, 3, 2218, 13437, 5396, 6716, 26, 199, 1224, 63, 694, 275, 20644, 1199, 15, 5987, 4805, 199, 692, 440, 747, 14, 515, 14, 6027, 8, 1224, 63, 694, 304, 272, 747, 14, 8215, 8, 1224, 63, 694, 9, 199, 14417, 63, 1587, 14, 475, 63, 4737, 8, 1224, 63, 694, 4786, 4452, 63, 14417, 20013 ]
[ 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 199, 646, 900, 199, 646, 2022, 199, 646, 5927, 199, 646, 984, 199, 504, 7975, 492, 3336, 12, 15821, 199, 199, 646, 8027, 199, 646, 8027, 14, 13563, 465, 4488, 199, 646, 542, 371, 6161, 465, 308, 561, 199, 646, 10634, 465, 6454, 199, 646, 2680, 465, 980, 199, 199, 504, 6357, 14, 21402, 492, 10354, 6679, 199, 199, 504, 519, 9494, 2000, 65, 14, 16355, 492, 2517, 285, 794, 199, 504, 519, 9494, 2000, 65, 14, 4106, 2072, 492, 11388, 1793, 199, 504, 519, 9494, 2000, 65, 14, 16355, 492, 2248, 63, 10384, 63, 5214, 12, 3560, 63, 2374, 63, 1294, 12, 664, 63, 9953, 63, 890, 199, 504, 6357, 14, 7925, 63, 6136, 492, 3560, 63, 396, 63, 1294, 199, 504, 519, 9494, 2000, 65, 14, 3397, 63, 26063, 1337, 492, 25318, 2662, 692, 351, 199, 504, 519, 9494, 2000, 65, 14, 19154, 492, 21379, 63, 6759, 199, 504, 519, 9494, 2000, 65, 14, 4738, 18, 3673, 9893, 492, 9240, 18, 3673, 9893, 465, 5444, 9893, 199, 646, 519, 9494, 2000, 65, 14, 580, 465, 24701, 199, 199, 3, 1255, 2884, 367, 2746, 13, 21, 7186, 199, 78, 1679, 63, 466, 275, 283, 1027, 7, 199, 78, 1679, 63, 890, 275, 413, 199, 1095, 275, 283, 2913, 7, 199, 4106, 63, 2638, 275, 283, 3249, 63, 1516, 7, 199, 5165, 275, 283, 28485, 7, 199, 4994, 63, 11146, 63, 1661, 275, 2948, 199, 30006, 63, 4469, 275, 378, 14, 21, 199, 4994, 63, 3236, 736, 878, 275, 4233, 199, 77, 329, 275, 984, 14, 21411, 199, 827, 63, 1587, 275, 499, 199, 199, 3, 664, 1742, 29895, 666, 26, 199, 2834, 63, 576, 12, 485, 275, 2248, 63, 10384, 63, 5214, 24592, 576, 15, 10378, 15, 2374, 358, 327, 3686, 5809, 8247, 199, 2834, 63, 3512, 12, 3560, 63, 12233, 275, 3482, 2031, 2834, 63, 576, 9, 199, 199, 3, 664, 511, 666, 26, 199, 396, 63, 576, 12, 485, 275, 2248, 63, 10384, 63, 5214, 24592, 576, 15, 10378, 15, 396, 358, 327, 3686, 5809, 8247, 199, 396, 63, 3512, 12, 511, 63, 12233, 275, 3482, 2031, 396, 63, 576, 9, 199, 199, 3, 5542, 10295, 367, 4132, 3628, 26, 199, 1302, 63, 9347, 275, 10354, 6679, 342, 199, 1302, 63, 9347, 14, 3269, 8, 2834, 63, 3512, 11, 396, 63, 3512, 9, 199, 2834, 63, 13141, 275, 1768, 63, 9347, 14, 4711, 8, 2834, 63, 3512, 9, 199, 396, 63, 13141, 275, 1768, 63, 9347, 14, 4711, 8, 396, 63, 3512, 9, 199, 199, 3, 5542, 5477, 1793, 26, 199, 4106, 1793, 275, 11388, 1793, 8, 77, 329, 275, 333, 329, 12, 717, 5477, 63, 2638, 275, 5477, 63, 2638, 12, 717, 302, 1679, 63, 466, 275, 302, 1679, 63, 466, 12, 717, 302, 1679, 63, 890, 275, 302, 1679, 63, 890, 9, 199, 4106, 1793, 14, 3269, 8, 2834, 63, 12233, 11, 396, 63, 12233, 9, 199, 2834, 63, 56, 275, 5477, 1793, 14, 4711, 8, 2834, 63, 12233, 680, 18993, 342, 199, 396, 63, 56, 275, 5477, 1793, 14, 4711, 8, 396, 63, 12233, 680, 18993, 342, 199, 199, 4574, 275, 788, 1302, 418, 199, 509, 511, 63, 2502, 315, 3355, 8, 409, 8, 396, 63, 13141, 2298, 272, 1790, 63, 1302, 275, 1768, 63, 9347, 14, 11668, 63, 4711, 779, 396, 63, 2502, 11057, 16, 61, 272, 8850, 14, 740, 8, 1178, 63, 1302, 9, 199, 199, 14417, 63, 1587, 275, 6454, 14, 9205, 8, 3406, 29, 4574, 9, 199, 199, 509, 4280, 315, 1425, 8, 552, 8, 396, 63, 12233, 2298, 272, 1347, 63, 1178, 275, 511, 63, 13141, 59, 2996, 61, 272, 1347, 63, 1301, 85, 275, 511, 63, 56, 59, 2996, 61, 272, 2222, 63, 1375, 63, 396, 63, 13141, 275, 980, 14, 1144, 779, 396, 63, 13141, 59, 73, 61, 367, 284, 315, 1425, 8, 552, 8, 396, 63, 13141, 430, 340, 284, 1137, 4280, 566, 272, 2222, 63, 1375, 63, 396, 63, 56, 275, 980, 14, 1144, 779, 396, 63, 56, 59, 73, 61, 367, 284, 315, 1425, 8, 552, 8, 396, 63, 13141, 430, 340, 284, 1137, 4280, 566, 272, 3529, 63, 2834, 63, 56, 275, 980, 14, 20221, 1332, 2834, 63, 56, 12, 2222, 63, 1375, 63, 396, 63, 56, 430, 272, 3529, 63, 2834, 63, 89, 275, 980, 14, 20949, 1332, 2834, 63, 13141, 12, 2222, 63, 1375, 63, 396, 63, 13141, 430, 2286, 3529, 63, 396, 63, 56, 12, 3529, 63, 396, 63, 89, 275, 990, 942, 272, 367, 307, 63, 1178, 315, 3355, 8, 409, 8, 396, 63, 13141, 2298, 267, 3529, 63, 396, 63, 56, 14, 740, 8, 1375, 63, 1301, 85, 9, 267, 3529, 63, 396, 63, 89, 14, 740, 8, 84, 63, 1178, 9, 339, 327, 5542, 314, 25581, 26, 272, 25581, 275, 5444, 9893, 8, 5165, 275, 6370, 12, 717, 1300, 275, 1300, 12, 717, 8526, 63, 11146, 63, 1661, 275, 8526, 63, 11146, 63, 1661, 12, 717, 20665, 63, 4469, 275, 20665, 63, 4469, 9, 272, 25581, 14, 3269, 8, 2791, 63, 2834, 63, 56, 12, 3529, 63, 2834, 63, 89, 9, 272, 5128, 305, 275, 25581, 14, 6892, 63, 14417, 8, 396, 63, 56, 275, 3529, 63, 396, 63, 56, 12, 717, 511, 63, 89, 275, 3529, 63, 396, 63, 89, 12, 717, 8526, 63, 3236, 736, 878, 275, 8526, 63, 3236, 736, 878, 9, 2286, 1962, 275, 359, 1302, 63, 9347, 14, 11668, 63, 4711, 779, 1375, 63, 1178, 11057, 16, 2677, 327, 4132, 1768, 272, 1962, 847, 769, 8, 6101, 305, 9, 272, 870, 8, 1143, 9, 272, 557, 2470, 63, 1587, 14, 2102, 59, 552, 8, 14417, 63, 1587, 1874, 275, 1962, 199, 199, 14417, 63, 1587, 275, 557, 2470, 63, 1587, 14, 409, 63, 1080, 360, 1302, 358, 199, 199, 3, 2218, 13437, 5396, 6716, 26, 199, 1224, 63, 694, 275, 20644, 1199, 15, 5987, 4805, 199, 692, 440, 747, 14, 515, 14, 6027, 8, 1224, 63, 694, 304, 272, 747, 14, 8215, 8, 1224, 63, 694, 9, 199, 14417, 63, 1587, 14, 475, 63, 4737, 8, 1224, 63, 694, 4786, 4452, 63, 14417, 20013, 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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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 ]
bazzile/THE_BIG_ONE
Main/Tenderplan/participants2excel.py
1
6915
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import TimeoutException from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import StaleElementReferenceException from time import sleep from selenium import webdriver from Main.Tenderplan.password import get_passwd def waiter(expression, method='xpath', delay=7, click=0, event='presence'): try: if method == 'xpath': if event == 'presence': WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.XPATH, expression))) elif event == 'visibility': WebDriverWait(driver, delay).until(EC.visibility_of_element_located((By.XPATH, expression))) elif method == 'css': if event == 'presence': WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.CSS_SELECTOR, expression))) if event == 'visibility': WebDriverWait(driver, delay).until(EC.visibility_of_element_located((By.CSS_SELECTOR, expression))) if click == 1: driver.find_element_by_xpath(expression).click() return True except TimeoutException: # print("Loading took too much time!") return False def get_participants(): global driver # запрашиваем пароль к tenderplan.ru pwd = get_passwd().strip() driver = webdriver.Firefox() driver.get("http://tenderplan.ru/account/logon") username = driver.find_element_by_name("EmailAddress") password = driver.find_element_by_name("Password") username.send_keys("zheleznov@innoter.com") password.send_keys(pwd) driver.find_element_by_xpath("/html/body/div[1]/div/div[1]/section/div/div/form/div[3]/button").click() # Жмём "Лиды отработать" print('Запрашиваем список лидов...') sleep(2) waiter("//*[contains(text(), 'Лиды отработать')]", click=1) # ждём, пока лиды прогрузятся sleep(3) # TODO собрать всех участников в сет и устранить дубликаты # TODO выявить победителя # TODO добавить ссылку на тендер (берётся из адресной строки) # TODO экспорт в Excel counter = 0 seen_companies = set() participants_list = [] while True: counter += 1 try: # Перебираем список лидов, ожидая (visibility), пока прогрузятся новые waiter( "//*[@id='slidepanel-left-wrapper']/div/div/div/div[2]/div[" + str(counter) + "]", click=1, event='visibility') # Название тендера tender_name = driver.find_element_by_xpath( "//*[@id='slidepanel-left-wrapper']/div/div/div/div[2]/div[" + str(counter) + "]/div/div[2]/div[1]").text print('\nЛид {}: {}'.format(counter, tender_name)) except NoSuchElementException: print('Конец списка лидов') break try: if waiter('.col-sm-12.notification-title.notification-header-mark', 'css', event='visibility') is True: # Страница с тендером полностью прогрузилась, можно искать таблицу участников table_presence_tag = waiter('table.participants-table', method='css', delay=0) if table_presence_tag is True: # таблица участников присутствует, обрабатываем # waiter('table.participants-table', method='css') table = driver.find_element_by_css_selector( '.table.table-striped.table-condensed.participants-table>tbody') print('\n') partictpats = table.find_elements_by_css_selector('.deflink-button>span') winner_flag = 0 for x in range(len(partictpats)): if len(partictpats[x].text) > 0: # print('=' * 2000) company = partictpats[x].text.strip() print(company) if x + 1 != len(partictpats) and partictpats[x + 1].size == {'height': 16, 'width': 16}: winner_flag = True print('Winner!') else: winner_flag = False # if x < len(partictpats): # print('Curr x: {}, length: {}, x+1: {}'.format(x, len(partictpats), x + 1)) # # размер значка-кубка (всегда идёт элементом списка после названия компании) # if partictpats[x + 1].size == {'height': 16, 'width': 16}: # print('Winner!') if company not in seen_companies: seen_companies.add(company) if winner_flag is True: participant_dict = {'company': company, 'tender_name': [{tender_name: 'win'}]} elif winner_flag is False: participant_dict = {'company': company, 'tender_name': [{tender_name: 'par'}]} participants_list.append(participant_dict) del participant_dict else: for item in participants_list: if item['company'] == company: if winner_flag is True: item['tender_name'].append({tender_name: 'win'}) elif winner_flag is False: item['tender_name'].append({tender_name: 'par'}) break else: print('Таблицы участников нету, переходим к следующему тендеру...') except (NoSuchElementException, StaleElementReferenceException): print('{}\nОшибка приполучении списка, пробуем заново...'.format(80 * '=')) # del participant_dict counter -= 1 # sleep(1) continue return participants_list
mit
[ 504, 19481, 14, 17946, 14, 4058, 14, 1907, 492, 27104, 7536, 199, 504, 19481, 14, 17946, 14, 4058, 492, 1420, 63, 9855, 465, 15352, 199, 504, 19481, 14, 17946, 14, 2330, 14, 991, 492, 4885, 199, 504, 19481, 14, 2330, 14, 3924, 492, 12878, 1726, 199, 504, 19481, 14, 2330, 14, 3924, 492, 23798, 2162, 1726, 199, 504, 19481, 14, 2330, 14, 3924, 492, 7083, 274, 2162, 5083, 1726, 199, 504, 900, 492, 9435, 199, 504, 19481, 492, 28094, 199, 504, 11298, 14, 52, 13747, 5140, 14, 2060, 492, 664, 63, 12671, 421, 199, 318, 27730, 8, 5599, 12, 1083, 534, 8006, 297, 7339, 29, 23, 12, 8968, 29, 16, 12, 1566, 534, 21566, 735, 272, 862, 26, 267, 340, 1083, 508, 283, 8006, 356, 288, 340, 1566, 508, 283, 21566, 356, 355, 27104, 7536, 8, 3090, 12, 7339, 680, 8111, 8, 4220, 14, 21566, 63, 1618, 63, 2108, 63, 13340, 1332, 2175, 14, 56, 3243, 12, 3965, 1724, 288, 916, 1566, 508, 283, 11269, 356, 355, 27104, 7536, 8, 3090, 12, 7339, 680, 8111, 8, 4220, 14, 11269, 63, 1618, 63, 2108, 63, 13340, 1332, 2175, 14, 56, 3243, 12, 3965, 1724, 267, 916, 1083, 508, 283, 3919, 356, 288, 340, 1566, 508, 283, 21566, 356, 355, 27104, 7536, 8, 3090, 12, 7339, 680, 8111, 8, 4220, 14, 21566, 63, 1618, 63, 2108, 63, 13340, 1332, 2175, 14, 14391, 63, 25691, 12, 3965, 1724, 288, 340, 1566, 508, 283, 11269, 356, 355, 27104, 7536, 8, 3090, 12, 7339, 680, 8111, 8, 4220, 14, 11269, 63, 1618, 63, 2108, 63, 13340, 1332, 2175, 14, 14391, 63, 25691, 12, 3965, 1724, 267, 340, 8968, 508, 413, 26, 288, 5253, 14, 1623, 63, 2108, 63, 991, 63, 8006, 8, 5599, 680, 4891, 342, 267, 372, 715, 272, 871, 12878, 1726, 26, 267, 327, 870, 480, 19236, 27221, 4634, 8298, 900, 9124, 267, 372, 756, 421, 199, 318, 664, 63, 31790, 837, 272, 2288, 5253, 272, 327, 7038, 116, 13111, 124, 7753, 5657, 27202, 16863, 111, 5657, 15578, 121, 19820, 27559, 26927, 16961, 31999, 16685, 424, 5140, 14, 6558, 272, 14374, 275, 664, 63, 12671, 1252, 1913, 342, 272, 5253, 275, 28094, 14, 27983, 342, 272, 5253, 14, 362, 480, 1014, 921, 724, 424, 5140, 14, 6558, 15, 2048, 15, 793, 265, 531, 272, 3434, 275, 5253, 14, 1623, 63, 2108, 63, 991, 63, 354, 480, 7035, 1476, 531, 272, 2505, 275, 5253, 14, 1623, 63, 2108, 63, 991, 63, 354, 480, 6139, 531, 272, 3434, 14, 2254, 63, 1612, 480, 90, 426, 274, 90, 30442, 32, 262, 889, 351, 14, 957, 531, 272, 2505, 14, 2254, 63, 1612, 8, 14258, 9, 272, 5253, 14, 1623, 63, 2108, 63, 991, 63, 8006, 4769, 1360, 15, 2030, 15, 3015, 59, 17, 12978, 3015, 15, 3015, 59, 17, 12978, 2792, 15, 3015, 15, 3015, 15, 964, 15, 3015, 59, 19, 12978, 3887, 3471, 4891, 342, 272, 327, 7038, 245, 23000, 142, 240, 23000, 298, 141, 250, 16863, 113, 17445, 221, 5806, 7413, 7753, 13111, 110, 5806, 7413, 24219, 16961, 2, 272, 870, 360, 141, 246, 13111, 124, 7753, 5657, 27202, 16863, 111, 5657, 15578, 121, 24071, 23645, 6500, 8474, 8381, 119, 7038, 120, 16863, 113, 21267, 15103, 272, 9435, 8, 18, 9, 272, 27730, 21816, 23033, 6134, 8, 505, 1062, 283, 141, 250, 16863, 113, 17445, 221, 5806, 7413, 7753, 13111, 110, 5806, 7413, 24219, 16961, 5440, 401, 8968, 29, 17, 9, 272, 327, 7038, 115, 20497, 142, 240, 23000, 12, 19820, 8381, 119, 5657, 7038, 120, 16863, 113, 17445, 19820, 7753, 8381, 112, 7753, 12195, 31027, 14978, 7413, 8474, 14978, 272, 9435, 8, 19, 9, 339, 327, 3254, 24071, 8381, 110, 7753, 24219, 16961, 22213, 8474, 6286, 25969, 221, 12195, 19277, 5657, 18261, 7592, 6500, 11487, 21267, 22213, 24071, 30160, 221, 6500, 221, 12195, 18261, 7753, 21674, 30019, 16961, 29562, 12195, 141, 110, 10356, 6500, 11487, 24219, 17445, 272, 327, 3254, 22213, 17445, 14978, 19630, 30019, 16961, 19820, 8381, 110, 15578, 113, 30019, 30598, 14978, 272, 327, 3254, 29562, 8381, 110, 13111, 111, 30019, 16961, 24071, 8474, 17445, 10356, 11487, 12195, 24917, 5657, 221, 7413, 18624, 20497, 21273, 334, 141, 110, 21273, 142, 240, 7413, 8474, 14978, 221, 16863, 116, 221, 13111, 113, 7753, 6286, 8474, 7592, 8381, 118, 221, 18261, 7753, 8381, 119, 6500, 9, 272, 327, 3254, 221, 142, 236, 11487, 8474, 23645, 26438, 7413, 22213, 27832, 339, 7055, 275, 378, 339, 6775, 63, 863, 23461, 275, 663, 342, 272, 623, 20989, 63, 513, 275, 942, 339, 1830, 715, 26, 267, 7055, 847, 413, 267, 862, 26, 953, 327, 7038, 254, 21273, 15578, 110, 6500, 7753, 5657, 15578, 121, 24071, 23645, 6500, 8474, 8381, 119, 7038, 120, 16863, 113, 21267, 12, 221, 8381, 115, 16863, 113, 5657, 14978, 334, 11269, 395, 19820, 8381, 119, 5657, 19820, 7753, 8381, 112, 7753, 12195, 31027, 14978, 7413, 8474, 14978, 24917, 21267, 17445, 6286, 288, 27730, 8, 355, 23057, 10, 14251, 344, 534, 23766, 2601, 4822, 13, 3039, 13, 5029, 28178, 3015, 15, 3015, 15, 3015, 15, 3015, 59, 18, 12978, 3015, 905, 435, 620, 8, 5337, 9, 435, 298, 11472, 355, 8968, 29, 17, 12, 1566, 534, 11269, 358, 288, 327, 7038, 252, 13111, 116, 19630, 21674, 6500, 6286, 221, 7413, 18624, 20497, 21273, 5657, 288, 16685, 424, 63, 354, 275, 5253, 14, 1623, 63, 2108, 63, 991, 63, 8006, 8, 355, 23057, 10, 14251, 344, 534, 23766, 2601, 4822, 13, 3039, 13, 5029, 28178, 3015, 15, 3015, 15, 3015, 15, 3015, 59, 18, 12978, 3015, 905, 435, 620, 8, 5337, 9, 435, 298, 12978, 3015, 15, 3015, 59, 18, 12978, 3015, 59, 17, 61, 3471, 505, 288, 870, 2258, 78, 141, 250, 16863, 113, 24702, 9499, 908, 8, 5337, 12, 16685, 424, 63, 354, 430, 267, 871, 23798, 2162, 1726, 26, 288, 870, 360, 141, 249, 5806, 7592, 6286, 25827, 24071, 23645, 6500, 8474, 29352, 7038, 120, 16863, 113, 21267, 358, 288, 2059, 398, 862, 26, 288, 340, 27730, 5175, 761, 13, 3300, 13, 713, 14, 6761, 13, 1213, 14, 6761, 13, 1291, 13, 1657, 297, 283, 3919, 297, 1566, 534, 11269, 358, 365, 715, 26, 355, 327, 7038, 95, 7413, 7753, 21674, 6500, 25827, 5657, 24071, 221 ]
[ 19481, 14, 17946, 14, 4058, 14, 1907, 492, 27104, 7536, 199, 504, 19481, 14, 17946, 14, 4058, 492, 1420, 63, 9855, 465, 15352, 199, 504, 19481, 14, 17946, 14, 2330, 14, 991, 492, 4885, 199, 504, 19481, 14, 2330, 14, 3924, 492, 12878, 1726, 199, 504, 19481, 14, 2330, 14, 3924, 492, 23798, 2162, 1726, 199, 504, 19481, 14, 2330, 14, 3924, 492, 7083, 274, 2162, 5083, 1726, 199, 504, 900, 492, 9435, 199, 504, 19481, 492, 28094, 199, 504, 11298, 14, 52, 13747, 5140, 14, 2060, 492, 664, 63, 12671, 421, 199, 318, 27730, 8, 5599, 12, 1083, 534, 8006, 297, 7339, 29, 23, 12, 8968, 29, 16, 12, 1566, 534, 21566, 735, 272, 862, 26, 267, 340, 1083, 508, 283, 8006, 356, 288, 340, 1566, 508, 283, 21566, 356, 355, 27104, 7536, 8, 3090, 12, 7339, 680, 8111, 8, 4220, 14, 21566, 63, 1618, 63, 2108, 63, 13340, 1332, 2175, 14, 56, 3243, 12, 3965, 1724, 288, 916, 1566, 508, 283, 11269, 356, 355, 27104, 7536, 8, 3090, 12, 7339, 680, 8111, 8, 4220, 14, 11269, 63, 1618, 63, 2108, 63, 13340, 1332, 2175, 14, 56, 3243, 12, 3965, 1724, 267, 916, 1083, 508, 283, 3919, 356, 288, 340, 1566, 508, 283, 21566, 356, 355, 27104, 7536, 8, 3090, 12, 7339, 680, 8111, 8, 4220, 14, 21566, 63, 1618, 63, 2108, 63, 13340, 1332, 2175, 14, 14391, 63, 25691, 12, 3965, 1724, 288, 340, 1566, 508, 283, 11269, 356, 355, 27104, 7536, 8, 3090, 12, 7339, 680, 8111, 8, 4220, 14, 11269, 63, 1618, 63, 2108, 63, 13340, 1332, 2175, 14, 14391, 63, 25691, 12, 3965, 1724, 267, 340, 8968, 508, 413, 26, 288, 5253, 14, 1623, 63, 2108, 63, 991, 63, 8006, 8, 5599, 680, 4891, 342, 267, 372, 715, 272, 871, 12878, 1726, 26, 267, 327, 870, 480, 19236, 27221, 4634, 8298, 900, 9124, 267, 372, 756, 421, 199, 318, 664, 63, 31790, 837, 272, 2288, 5253, 272, 327, 7038, 116, 13111, 124, 7753, 5657, 27202, 16863, 111, 5657, 15578, 121, 19820, 27559, 26927, 16961, 31999, 16685, 424, 5140, 14, 6558, 272, 14374, 275, 664, 63, 12671, 1252, 1913, 342, 272, 5253, 275, 28094, 14, 27983, 342, 272, 5253, 14, 362, 480, 1014, 921, 724, 424, 5140, 14, 6558, 15, 2048, 15, 793, 265, 531, 272, 3434, 275, 5253, 14, 1623, 63, 2108, 63, 991, 63, 354, 480, 7035, 1476, 531, 272, 2505, 275, 5253, 14, 1623, 63, 2108, 63, 991, 63, 354, 480, 6139, 531, 272, 3434, 14, 2254, 63, 1612, 480, 90, 426, 274, 90, 30442, 32, 262, 889, 351, 14, 957, 531, 272, 2505, 14, 2254, 63, 1612, 8, 14258, 9, 272, 5253, 14, 1623, 63, 2108, 63, 991, 63, 8006, 4769, 1360, 15, 2030, 15, 3015, 59, 17, 12978, 3015, 15, 3015, 59, 17, 12978, 2792, 15, 3015, 15, 3015, 15, 964, 15, 3015, 59, 19, 12978, 3887, 3471, 4891, 342, 272, 327, 7038, 245, 23000, 142, 240, 23000, 298, 141, 250, 16863, 113, 17445, 221, 5806, 7413, 7753, 13111, 110, 5806, 7413, 24219, 16961, 2, 272, 870, 360, 141, 246, 13111, 124, 7753, 5657, 27202, 16863, 111, 5657, 15578, 121, 24071, 23645, 6500, 8474, 8381, 119, 7038, 120, 16863, 113, 21267, 15103, 272, 9435, 8, 18, 9, 272, 27730, 21816, 23033, 6134, 8, 505, 1062, 283, 141, 250, 16863, 113, 17445, 221, 5806, 7413, 7753, 13111, 110, 5806, 7413, 24219, 16961, 5440, 401, 8968, 29, 17, 9, 272, 327, 7038, 115, 20497, 142, 240, 23000, 12, 19820, 8381, 119, 5657, 7038, 120, 16863, 113, 17445, 19820, 7753, 8381, 112, 7753, 12195, 31027, 14978, 7413, 8474, 14978, 272, 9435, 8, 19, 9, 339, 327, 3254, 24071, 8381, 110, 7753, 24219, 16961, 22213, 8474, 6286, 25969, 221, 12195, 19277, 5657, 18261, 7592, 6500, 11487, 21267, 22213, 24071, 30160, 221, 6500, 221, 12195, 18261, 7753, 21674, 30019, 16961, 29562, 12195, 141, 110, 10356, 6500, 11487, 24219, 17445, 272, 327, 3254, 22213, 17445, 14978, 19630, 30019, 16961, 19820, 8381, 110, 15578, 113, 30019, 30598, 14978, 272, 327, 3254, 29562, 8381, 110, 13111, 111, 30019, 16961, 24071, 8474, 17445, 10356, 11487, 12195, 24917, 5657, 221, 7413, 18624, 20497, 21273, 334, 141, 110, 21273, 142, 240, 7413, 8474, 14978, 221, 16863, 116, 221, 13111, 113, 7753, 6286, 8474, 7592, 8381, 118, 221, 18261, 7753, 8381, 119, 6500, 9, 272, 327, 3254, 221, 142, 236, 11487, 8474, 23645, 26438, 7413, 22213, 27832, 339, 7055, 275, 378, 339, 6775, 63, 863, 23461, 275, 663, 342, 272, 623, 20989, 63, 513, 275, 942, 339, 1830, 715, 26, 267, 7055, 847, 413, 267, 862, 26, 953, 327, 7038, 254, 21273, 15578, 110, 6500, 7753, 5657, 15578, 121, 24071, 23645, 6500, 8474, 8381, 119, 7038, 120, 16863, 113, 21267, 12, 221, 8381, 115, 16863, 113, 5657, 14978, 334, 11269, 395, 19820, 8381, 119, 5657, 19820, 7753, 8381, 112, 7753, 12195, 31027, 14978, 7413, 8474, 14978, 24917, 21267, 17445, 6286, 288, 27730, 8, 355, 23057, 10, 14251, 344, 534, 23766, 2601, 4822, 13, 3039, 13, 5029, 28178, 3015, 15, 3015, 15, 3015, 15, 3015, 59, 18, 12978, 3015, 905, 435, 620, 8, 5337, 9, 435, 298, 11472, 355, 8968, 29, 17, 12, 1566, 534, 11269, 358, 288, 327, 7038, 252, 13111, 116, 19630, 21674, 6500, 6286, 221, 7413, 18624, 20497, 21273, 5657, 288, 16685, 424, 63, 354, 275, 5253, 14, 1623, 63, 2108, 63, 991, 63, 8006, 8, 355, 23057, 10, 14251, 344, 534, 23766, 2601, 4822, 13, 3039, 13, 5029, 28178, 3015, 15, 3015, 15, 3015, 15, 3015, 59, 18, 12978, 3015, 905, 435, 620, 8, 5337, 9, 435, 298, 12978, 3015, 15, 3015, 59, 18, 12978, 3015, 59, 17, 61, 3471, 505, 288, 870, 2258, 78, 141, 250, 16863, 113, 24702, 9499, 908, 8, 5337, 12, 16685, 424, 63, 354, 430, 267, 871, 23798, 2162, 1726, 26, 288, 870, 360, 141, 249, 5806, 7592, 6286, 25827, 24071, 23645, 6500, 8474, 29352, 7038, 120, 16863, 113, 21267, 358, 288, 2059, 398, 862, 26, 288, 340, 27730, 5175, 761, 13, 3300, 13, 713, 14, 6761, 13, 1213, 14, 6761, 13, 1291, 13, 1657, 297, 283, 3919, 297, 1566, 534, 11269, 358, 365, 715, 26, 355, 327, 7038, 95, 7413, 7753, 21674, 6500, 25827, 5657, 24071, 221, 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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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 ]
yoer/hue
desktop/core/ext-py/httplib2-0.8/python3/httplib2test.py
61
74045
#!/usr/bin/env python3 """ httplib2test A set of unit tests for httplib2.py. Requires Python 3.0 or later """ __author__ = "Joe Gregorio (joe@bitworking.org)" __copyright__ = "Copyright 2006, Joe Gregorio" __contributors__ = ["Mark Pilgrim"] __license__ = "MIT" __history__ = """ """ __version__ = "0.2 ($Rev: 118 $)" import base64 import http.client import httplib2 import io import os import pickle import socket import ssl import sys import time import unittest import urllib.parse # The test resources base uri base = 'http://bitworking.org/projects/httplib2/test/' #base = 'http://localhost/projects/httplib2/test/' cacheDirName = ".cache" class CredentialsTest(unittest.TestCase): def test(self): c = httplib2.Credentials() c.add("joe", "password") self.assertEqual(("joe", "password"), list(c.iter("bitworking.org"))[0]) self.assertEqual(("joe", "password"), list(c.iter(""))[0]) c.add("fred", "password2", "wellformedweb.org") self.assertEqual(("joe", "password"), list(c.iter("bitworking.org"))[0]) self.assertEqual(1, len(list(c.iter("bitworking.org")))) self.assertEqual(2, len(list(c.iter("wellformedweb.org")))) self.assertTrue(("fred", "password2") in list(c.iter("wellformedweb.org"))) c.clear() self.assertEqual(0, len(list(c.iter("bitworking.org")))) c.add("fred", "password2", "wellformedweb.org") self.assertTrue(("fred", "password2") in list(c.iter("wellformedweb.org"))) self.assertEqual(0, len(list(c.iter("bitworking.org")))) self.assertEqual(0, len(list(c.iter("")))) class ParserTest(unittest.TestCase): def testFromStd66(self): self.assertEqual( ('http', 'example.com', '', None, None ), httplib2.parse_uri("http://example.com")) self.assertEqual( ('https', 'example.com', '', None, None ), httplib2.parse_uri("https://example.com")) self.assertEqual( ('https', 'example.com:8080', '', None, None ), httplib2.parse_uri("https://example.com:8080")) self.assertEqual( ('http', 'example.com', '/', None, None ), httplib2.parse_uri("http://example.com/")) self.assertEqual( ('http', 'example.com', '/path', None, None ), httplib2.parse_uri("http://example.com/path")) self.assertEqual( ('http', 'example.com', '/path', 'a=1&b=2', None ), httplib2.parse_uri("http://example.com/path?a=1&b=2")) self.assertEqual( ('http', 'example.com', '/path', 'a=1&b=2', 'fred' ), httplib2.parse_uri("http://example.com/path?a=1&b=2#fred")) self.assertEqual( ('http', 'example.com', '/path', 'a=1&b=2', 'fred' ), httplib2.parse_uri("http://example.com/path?a=1&b=2#fred")) class UrlNormTest(unittest.TestCase): def test(self): self.assertEqual( "http://example.org/", httplib2.urlnorm("http://example.org")[-1]) self.assertEqual( "http://example.org/", httplib2.urlnorm("http://EXAMple.org")[-1]) self.assertEqual( "http://example.org/?=b", httplib2.urlnorm("http://EXAMple.org?=b")[-1]) self.assertEqual( "http://example.org/mypath?a=b", httplib2.urlnorm("http://EXAMple.org/mypath?a=b")[-1]) self.assertEqual( "http://localhost:80/", httplib2.urlnorm("http://localhost:80")[-1]) self.assertEqual( httplib2.urlnorm("http://localhost:80/"), httplib2.urlnorm("HTTP://LOCALHOST:80")) try: httplib2.urlnorm("/") self.fail("Non-absolute URIs should raise an exception") except httplib2.RelativeURIError: pass class UrlSafenameTest(unittest.TestCase): def test(self): # Test that different URIs end up generating different safe names self.assertEqual( "example.org,fred,a=b,58489f63a7a83c3b7794a6a398ee8b1f", httplib2.safename("http://example.org/fred/?a=b")) self.assertEqual( "example.org,fred,a=b,8c5946d56fec453071f43329ff0be46b", httplib2.safename("http://example.org/fred?/a=b")) self.assertEqual( "www.example.org,fred,a=b,499c44b8d844a011b67ea2c015116968", httplib2.safename("http://www.example.org/fred?/a=b")) self.assertEqual( httplib2.safename(httplib2.urlnorm("http://www")[-1]), httplib2.safename(httplib2.urlnorm("http://WWW")[-1])) self.assertEqual( "www.example.org,fred,a=b,692e843a333484ce0095b070497ab45d", httplib2.safename("https://www.example.org/fred?/a=b")) self.assertNotEqual( httplib2.safename("http://www"), httplib2.safename("https://www")) # Test the max length limits uri = "http://" + ("w" * 200) + ".org" uri2 = "http://" + ("w" * 201) + ".org" self.assertNotEqual( httplib2.safename(uri2), httplib2.safename(uri)) # Max length should be 200 + 1 (",") + 32 self.assertEqual(233, len(httplib2.safename(uri2))) self.assertEqual(233, len(httplib2.safename(uri))) # Unicode if sys.version_info >= (2,3): self.assertEqual( "xn--http,-4y1d.org,fred,a=b,579924c35db315e5a32e3d9963388193", httplib2.safename("http://\u2304.org/fred/?a=b")) class _MyResponse(io.BytesIO): def __init__(self, body, **kwargs): io.BytesIO.__init__(self, body) self.headers = kwargs def items(self): return self.headers.items() def iteritems(self): return iter(self.headers.items()) class _MyHTTPConnection(object): "This class is just a mock of httplib.HTTPConnection used for testing" def __init__(self, host, port=None, key_file=None, cert_file=None, strict=None, timeout=None, proxy_info=None): self.host = host self.port = port self.timeout = timeout self.log = "" self.sock = None def set_debuglevel(self, level): pass def connect(self): "Connect to a host on a given port." pass def close(self): pass def request(self, method, request_uri, body, headers): pass def getresponse(self): return _MyResponse(b"the body", status="200") class HttpTest(unittest.TestCase): def setUp(self): if os.path.exists(cacheDirName): [os.remove(os.path.join(cacheDirName, file)) for file in os.listdir(cacheDirName)] self.http = httplib2.Http(cacheDirName) self.http.clear_credentials() def testIPv6NoSSL(self): try: self.http.request("http://[::1]/") except socket.gaierror: self.fail("should get the address family right for IPv6") except socket.error: # Even if IPv6 isn't installed on a machine it should just raise socket.error pass def testIPv6SSL(self): try: self.http.request("https://[::1]/") except socket.gaierror: self.fail("should get the address family right for IPv6") except socket.error: # Even if IPv6 isn't installed on a machine it should just raise socket.error pass def testConnectionType(self): self.http.force_exception_to_status_code = False response, content = self.http.request("http://bitworking.org", connection_type=_MyHTTPConnection) self.assertEqual(response['content-location'], "http://bitworking.org") self.assertEqual(content, b"the body") def testGetUnknownServer(self): self.http.force_exception_to_status_code = False try: self.http.request("http://fred.bitworking.org/") self.fail("An httplib2.ServerNotFoundError Exception must be thrown on an unresolvable server.") except httplib2.ServerNotFoundError: pass # Now test with exceptions turned off self.http.force_exception_to_status_code = True (response, content) = self.http.request("http://fred.bitworking.org/") self.assertEqual(response['content-type'], 'text/plain') self.assertTrue(content.startswith(b"Unable to find")) self.assertEqual(response.status, 400) def testGetConnectionRefused(self): self.http.force_exception_to_status_code = False try: self.http.request("http://localhost:7777/") self.fail("An socket.error exception must be thrown on Connection Refused.") except socket.error: pass # Now test with exceptions turned off self.http.force_exception_to_status_code = True (response, content) = self.http.request("http://localhost:7777/") self.assertEqual(response['content-type'], 'text/plain') self.assertTrue(b"Connection refused" in content) self.assertEqual(response.status, 400) def testGetIRI(self): if sys.version_info >= (2,3): uri = urllib.parse.urljoin(base, "reflector/reflector.cgi?d=\N{CYRILLIC CAPITAL LETTER DJE}") (response, content) = self.http.request(uri, "GET") d = self.reflector(content) self.assertTrue('QUERY_STRING' in d) self.assertTrue(d['QUERY_STRING'].find('%D0%82') > 0) def testGetIsDefaultMethod(self): # Test that GET is the default method uri = urllib.parse.urljoin(base, "methods/method_reflector.cgi") (response, content) = self.http.request(uri) self.assertEqual(response['x-method'], "GET") def testDifferentMethods(self): # Test that all methods can be used uri = urllib.parse.urljoin(base, "methods/method_reflector.cgi") for method in ["GET", "PUT", "DELETE", "POST"]: (response, content) = self.http.request(uri, method, body=b" ") self.assertEqual(response['x-method'], method) def testHeadRead(self): # Test that we don't try to read the response of a HEAD request # since httplib blocks response.read() for HEAD requests. # Oddly enough this doesn't appear as a problem when doing HEAD requests # against Apache servers. uri = "http://www.google.com/" (response, content) = self.http.request(uri, "HEAD") self.assertEqual(response.status, 200) self.assertEqual(content, b"") def testGetNoCache(self): # Test that can do a GET w/o the cache turned on. http = httplib2.Http() uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.previous, None) def testGetOnlyIfCachedCacheHit(self): # Test that can do a GET with cache and 'only-if-cached' uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = self.http.request(uri, "GET") (response, content) = self.http.request(uri, "GET", headers={'cache-control': 'only-if-cached'}) self.assertEqual(response.fromcache, True) self.assertEqual(response.status, 200) def testGetOnlyIfCachedCacheMiss(self): # Test that can do a GET with no cache with 'only-if-cached' uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = self.http.request(uri, "GET", headers={'cache-control': 'only-if-cached'}) self.assertEqual(response.fromcache, False) self.assertEqual(response.status, 504) def testGetOnlyIfCachedNoCacheAtAll(self): # Test that can do a GET with no cache with 'only-if-cached' # Of course, there might be an intermediary beyond us # that responds to the 'only-if-cached', so this # test can't really be guaranteed to pass. http = httplib2.Http() uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = http.request(uri, "GET", headers={'cache-control': 'only-if-cached'}) self.assertEqual(response.fromcache, False) self.assertEqual(response.status, 504) def testUserAgent(self): # Test that we provide a default user-agent uri = urllib.parse.urljoin(base, "user-agent/test.cgi") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertTrue(content.startswith(b"Python-httplib2/")) def testUserAgentNonDefault(self): # Test that the default user-agent can be over-ridden uri = urllib.parse.urljoin(base, "user-agent/test.cgi") (response, content) = self.http.request(uri, "GET", headers={'User-Agent': 'fred/1.0'}) self.assertEqual(response.status, 200) self.assertTrue(content.startswith(b"fred/1.0")) def testGet300WithLocation(self): # Test the we automatically follow 300 redirects if a Location: header is provided uri = urllib.parse.urljoin(base, "300/with-location-header.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 300) self.assertEqual(response.previous.fromcache, False) # Confirm that the intermediate 300 is not cached (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 300) self.assertEqual(response.previous.fromcache, False) def testGet300WithLocationNoRedirect(self): # Test the we automatically follow 300 redirects if a Location: header is provided self.http.follow_redirects = False uri = urllib.parse.urljoin(base, "300/with-location-header.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 300) def testGet300WithoutLocation(self): # Not giving a Location: header in a 300 response is acceptable # In which case we just return the 300 response uri = urllib.parse.urljoin(base, "300/without-location-header.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 300) self.assertTrue(response['content-type'].startswith("text/html")) self.assertEqual(response.previous, None) def testGet301(self): # Test that we automatically follow 301 redirects # and that we cache the 301 response uri = urllib.parse.urljoin(base, "301/onestep.asis") destination = urllib.parse.urljoin(base, "302/final-destination.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertTrue('content-location' in response) self.assertEqual(response['content-location'], destination) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 301) self.assertEqual(response.previous.fromcache, False) (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response['content-location'], destination) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 301) self.assertEqual(response.previous.fromcache, True) def testHead301(self): # Test that we automatically follow 301 redirects uri = urllib.parse.urljoin(base, "301/onestep.asis") (response, content) = self.http.request(uri, "HEAD") self.assertEqual(response.status, 200) self.assertEqual(response.previous.status, 301) self.assertEqual(response.previous.fromcache, False) def testGet301NoRedirect(self): # Test that we automatically follow 301 redirects # and that we cache the 301 response self.http.follow_redirects = False uri = urllib.parse.urljoin(base, "301/onestep.asis") destination = urllib.parse.urljoin(base, "302/final-destination.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 301) def testGet302(self): # Test that we automatically follow 302 redirects # and that we DO NOT cache the 302 response uri = urllib.parse.urljoin(base, "302/onestep.asis") destination = urllib.parse.urljoin(base, "302/final-destination.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response['content-location'], destination) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 302) self.assertEqual(response.previous.fromcache, False) uri = urllib.parse.urljoin(base, "302/onestep.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) self.assertEqual(response['content-location'], destination) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 302) self.assertEqual(response.previous.fromcache, False) self.assertEqual(response.previous['content-location'], uri) uri = urllib.parse.urljoin(base, "302/twostep.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 302) self.assertEqual(response.previous.fromcache, False) def testGet302RedirectionLimit(self): # Test that we can set a lower redirection limit # and that we raise an exception when we exceed # that limit. self.http.force_exception_to_status_code = False uri = urllib.parse.urljoin(base, "302/twostep.asis") try: (response, content) = self.http.request(uri, "GET", redirections = 1) self.fail("This should not happen") except httplib2.RedirectLimit: pass except Exception as e: self.fail("Threw wrong kind of exception ") # Re-run the test with out the exceptions self.http.force_exception_to_status_code = True (response, content) = self.http.request(uri, "GET", redirections = 1) self.assertEqual(response.status, 500) self.assertTrue(response.reason.startswith("Redirected more")) self.assertEqual("302", response['status']) self.assertTrue(content.startswith(b"<html>")) self.assertTrue(response.previous != None) def testGet302NoLocation(self): # Test that we throw an exception when we get # a 302 with no Location: header. self.http.force_exception_to_status_code = False uri = urllib.parse.urljoin(base, "302/no-location.asis") try: (response, content) = self.http.request(uri, "GET") self.fail("Should never reach here") except httplib2.RedirectMissingLocation: pass except Exception as e: self.fail("Threw wrong kind of exception ") # Re-run the test with out the exceptions self.http.force_exception_to_status_code = True (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 500) self.assertTrue(response.reason.startswith("Redirected but")) self.assertEqual("302", response['status']) self.assertTrue(content.startswith(b"This is content")) def testGet301ViaHttps(self): # Google always redirects to http://google.com (response, content) = self.http.request("https://code.google.com/apis/", "GET") self.assertEqual(200, response.status) self.assertEqual(301, response.previous.status) def testGetViaHttps(self): # Test that we can handle HTTPS (response, content) = self.http.request("https://google.com/adsense/", "GET") self.assertEqual(200, response.status) def testGetViaHttpsSpecViolationOnLocation(self): # Test that we follow redirects through HTTPS # even if they violate the spec by including # a relative Location: header instead of an # absolute one. (response, content) = self.http.request("https://google.com/adsense", "GET") self.assertEqual(200, response.status) self.assertNotEqual(None, response.previous) def testGetViaHttpsKeyCert(self): # At this point I can only test # that the key and cert files are passed in # correctly to httplib. It would be nice to have # a real https endpoint to test against. http = httplib2.Http(timeout=2) http.add_certificate("akeyfile", "acertfile", "bitworking.org") try: (response, content) = http.request("https://bitworking.org", "GET") except AttributeError: self.assertEqual(http.connections["https:bitworking.org"].key_file, "akeyfile") self.assertEqual(http.connections["https:bitworking.org"].cert_file, "acertfile") except IOError: # Skip on 3.2 pass try: (response, content) = http.request("https://notthere.bitworking.org", "GET") except httplib2.ServerNotFoundError: self.assertEqual(http.connections["https:notthere.bitworking.org"].key_file, None) self.assertEqual(http.connections["https:notthere.bitworking.org"].cert_file, None) except IOError: # Skip on 3.2 pass def testSslCertValidation(self): # Test that we get an ssl.SSLError when specifying a non-existent CA # certs file. http = httplib2.Http(ca_certs='/nosuchfile') self.assertRaises(IOError, http.request, "https://www.google.com/", "GET") # Test that we get a SSLHandshakeError if we try to access # https://www.google.com, using a CA cert file that doesn't contain # the CA Gogole uses (i.e., simulating a cert that's not signed by a # trusted CA). other_ca_certs = os.path.join( os.path.dirname(os.path.abspath(httplib2.__file__ )), "test", "other_cacerts.txt") http = httplib2.Http(ca_certs=other_ca_certs) self.assertRaises(ssl.SSLError, http.request,"https://www.google.com/", "GET") def testSniHostnameValidation(self): self.http.request("https://google.com/", method="GET") def testGet303(self): # Do a follow-up GET on a Location: header # returned from a POST that gave a 303. uri = urllib.parse.urljoin(base, "303/303.cgi") (response, content) = self.http.request(uri, "POST", " ") self.assertEqual(response.status, 200) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 303) def testGet303NoRedirect(self): # Do a follow-up GET on a Location: header # returned from a POST that gave a 303. self.http.follow_redirects = False uri = urllib.parse.urljoin(base, "303/303.cgi") (response, content) = self.http.request(uri, "POST", " ") self.assertEqual(response.status, 303) def test303ForDifferentMethods(self): # Test that all methods can be used uri = urllib.parse.urljoin(base, "303/redirect-to-reflector.cgi") for (method, method_on_303) in [("PUT", "GET"), ("DELETE", "GET"), ("POST", "GET"), ("GET", "GET"), ("HEAD", "GET")]: (response, content) = self.http.request(uri, method, body=b" ") self.assertEqual(response['x-method'], method_on_303) def testGet304(self): # Test that we use ETags properly to validate our cache uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = self.http.request(uri, "GET") self.assertNotEqual(response['etag'], "") (response, content) = self.http.request(uri, "GET") (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'must-revalidate'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) cache_file_name = os.path.join(cacheDirName, httplib2.safename(httplib2.urlnorm(uri)[-1])) f = open(cache_file_name, "r") status_line = f.readline() f.close() self.assertTrue(status_line.startswith("status:")) (response, content) = self.http.request(uri, "HEAD") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) (response, content) = self.http.request(uri, "GET", headers = {'range': 'bytes=0-0'}) self.assertEqual(response.status, 206) self.assertEqual(response.fromcache, False) def testGetIgnoreEtag(self): # Test that we can forcibly ignore ETags uri = urllib.parse.urljoin(base, "reflector/reflector.cgi") (response, content) = self.http.request(uri, "GET") self.assertNotEqual(response['etag'], "") (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0'}) d = self.reflector(content) self.assertTrue('HTTP_IF_NONE_MATCH' in d) self.http.ignore_etag = True (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0'}) d = self.reflector(content) self.assertEqual(response.fromcache, False) self.assertFalse('HTTP_IF_NONE_MATCH' in d) def testOverrideEtag(self): # Test that we can forcibly ignore ETags uri = urllib.parse.urljoin(base, "reflector/reflector.cgi") (response, content) = self.http.request(uri, "GET") self.assertNotEqual(response['etag'], "") (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0'}) d = self.reflector(content) self.assertTrue('HTTP_IF_NONE_MATCH' in d) self.assertNotEqual(d['HTTP_IF_NONE_MATCH'], "fred") (response, content) = self.http.request(uri, "GET", headers = {'cache-control': 'max-age=0', 'if-none-match': 'fred'}) d = self.reflector(content) self.assertTrue('HTTP_IF_NONE_MATCH' in d) self.assertEqual(d['HTTP_IF_NONE_MATCH'], "fred") #MAP-commented this out because it consistently fails # def testGet304EndToEnd(self): # # Test that end to end headers get overwritten in the cache # uri = urllib.parse.urljoin(base, "304/end2end.cgi") # (response, content) = self.http.request(uri, "GET") # self.assertNotEqual(response['etag'], "") # old_date = response['date'] # time.sleep(2) # # (response, content) = self.http.request(uri, "GET", headers = {'Cache-Control': 'max-age=0'}) # # The response should be from the cache, but the Date: header should be updated. # new_date = response['date'] # self.assertNotEqual(new_date, old_date) # self.assertEqual(response.status, 200) # self.assertEqual(response.fromcache, True) def testGet304LastModified(self): # Test that we can still handle a 304 # by only using the last-modified cache validator. uri = urllib.parse.urljoin(base, "304/last-modified-only/last-modified-only.txt") (response, content) = self.http.request(uri, "GET") self.assertNotEqual(response['last-modified'], "") (response, content) = self.http.request(uri, "GET") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) def testGet307(self): # Test that we do follow 307 redirects but # do not cache the 307 uri = urllib.parse.urljoin(base, "307/onestep.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 307) self.assertEqual(response.previous.fromcache, False) (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) self.assertEqual(content, b"This is the final destination.\n") self.assertEqual(response.previous.status, 307) self.assertEqual(response.previous.fromcache, False) def testGet410(self): # Test that we pass 410's through uri = urllib.parse.urljoin(base, "410/410.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 410) def testVaryHeaderSimple(self): """ RFC 2616 13.6 When the cache receives a subsequent request whose Request-URI specifies one or more cache entries including a Vary header field, the cache MUST NOT use such a cache entry to construct a response to the new request unless all of the selecting request-headers present in the new request match the corresponding stored request-headers in the original request. """ # test that the vary header is sent uri = urllib.parse.urljoin(base, "vary/accept.asis") (response, content) = self.http.request(uri, "GET", headers={'Accept': 'text/plain'}) self.assertEqual(response.status, 200) self.assertTrue('vary' in response) # get the resource again, from the cache since accept header in this # request is the same as the request (response, content) = self.http.request(uri, "GET", headers={'Accept': 'text/plain'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True, msg="Should be from cache") # get the resource again, not from cache since Accept headers does not match (response, content) = self.http.request(uri, "GET", headers={'Accept': 'text/html'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False, msg="Should not be from cache") # get the resource again, without any Accept header, so again no match (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False, msg="Should not be from cache") def testNoVary(self): pass # when there is no vary, a different Accept header (e.g.) should not # impact if the cache is used # test that the vary header is not sent # uri = urllib.parse.urljoin(base, "vary/no-vary.asis") # (response, content) = self.http.request(uri, "GET", headers={'Accept': 'text/plain'}) # self.assertEqual(response.status, 200) # self.assertFalse('vary' in response) # # (response, content) = self.http.request(uri, "GET", headers={'Accept': 'text/plain'}) # self.assertEqual(response.status, 200) # self.assertEqual(response.fromcache, True, msg="Should be from cache") # # (response, content) = self.http.request(uri, "GET", headers={'Accept': 'text/html'}) # self.assertEqual(response.status, 200) # self.assertEqual(response.fromcache, True, msg="Should be from cache") def testVaryHeaderDouble(self): uri = urllib.parse.urljoin(base, "vary/accept-double.asis") (response, content) = self.http.request(uri, "GET", headers={ 'Accept': 'text/plain', 'Accept-Language': 'da, en-gb;q=0.8, en;q=0.7'}) self.assertEqual(response.status, 200) self.assertTrue('vary' in response) # we are from cache (response, content) = self.http.request(uri, "GET", headers={ 'Accept': 'text/plain', 'Accept-Language': 'da, en-gb;q=0.8, en;q=0.7'}) self.assertEqual(response.fromcache, True, msg="Should be from cache") (response, content) = self.http.request(uri, "GET", headers={'Accept': 'text/plain'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) # get the resource again, not from cache, varied headers don't match exact (response, content) = self.http.request(uri, "GET", headers={'Accept-Language': 'da'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False, msg="Should not be from cache") def testVaryUnusedHeader(self): # A header's value is not considered to vary if it's not used at all. uri = urllib.parse.urljoin(base, "vary/unused-header.asis") (response, content) = self.http.request(uri, "GET", headers={ 'Accept': 'text/plain'}) self.assertEqual(response.status, 200) self.assertTrue('vary' in response) # we are from cache (response, content) = self.http.request(uri, "GET", headers={ 'Accept': 'text/plain',}) self.assertEqual(response.fromcache, True, msg="Should be from cache") def testHeadGZip(self): # Test that we don't try to decompress a HEAD response uri = urllib.parse.urljoin(base, "gzip/final-destination.txt") (response, content) = self.http.request(uri, "HEAD") self.assertEqual(response.status, 200) self.assertNotEqual(int(response['content-length']), 0) self.assertEqual(content, b"") def testGetGZip(self): # Test that we support gzip compression uri = urllib.parse.urljoin(base, "gzip/final-destination.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertFalse('content-encoding' in response) self.assertTrue('-content-encoding' in response) self.assertEqual(int(response['content-length']), len(b"This is the final destination.\n")) self.assertEqual(content, b"This is the final destination.\n") def testPostAndGZipResponse(self): uri = urllib.parse.urljoin(base, "gzip/post.cgi") (response, content) = self.http.request(uri, "POST", body=" ") self.assertEqual(response.status, 200) self.assertFalse('content-encoding' in response) self.assertTrue('-content-encoding' in response) def testGetGZipFailure(self): # Test that we raise a good exception when the gzip fails self.http.force_exception_to_status_code = False uri = urllib.parse.urljoin(base, "gzip/failed-compression.asis") try: (response, content) = self.http.request(uri, "GET") self.fail("Should never reach here") except httplib2.FailedToDecompressContent: pass except Exception: self.fail("Threw wrong kind of exception") # Re-run the test with out the exceptions self.http.force_exception_to_status_code = True (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 500) self.assertTrue(response.reason.startswith("Content purported")) def testIndividualTimeout(self): uri = urllib.parse.urljoin(base, "timeout/timeout.cgi") http = httplib2.Http(timeout=1) http.force_exception_to_status_code = True (response, content) = http.request(uri) self.assertEqual(response.status, 408) self.assertTrue(response.reason.startswith("Request Timeout")) self.assertTrue(content.startswith(b"Request Timeout")) def testGetDeflate(self): # Test that we support deflate compression uri = urllib.parse.urljoin(base, "deflate/deflated.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertFalse('content-encoding' in response) self.assertEqual(int(response['content-length']), len("This is the final destination.")) self.assertEqual(content, b"This is the final destination.") def testGetDeflateFailure(self): # Test that we raise a good exception when the deflate fails self.http.force_exception_to_status_code = False uri = urllib.parse.urljoin(base, "deflate/failed-compression.asis") try: (response, content) = self.http.request(uri, "GET") self.fail("Should never reach here") except httplib2.FailedToDecompressContent: pass except Exception: self.fail("Threw wrong kind of exception") # Re-run the test with out the exceptions self.http.force_exception_to_status_code = True (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 500) self.assertTrue(response.reason.startswith("Content purported")) def testGetDuplicateHeaders(self): # Test that duplicate headers get concatenated via ',' uri = urllib.parse.urljoin(base, "duplicate-headers/multilink.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(content, b"This is content\n") self.assertEqual(response['link'].split(",")[0], '<http://bitworking.org>; rel="home"; title="BitWorking"') def testGetCacheControlNoCache(self): # Test Cache-Control: no-cache on requests uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = self.http.request(uri, "GET") self.assertNotEqual(response['etag'], "") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) (response, content) = self.http.request(uri, "GET", headers={'Cache-Control': 'no-cache'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) def testGetCacheControlPragmaNoCache(self): # Test Pragma: no-cache on requests uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = self.http.request(uri, "GET") self.assertNotEqual(response['etag'], "") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) (response, content) = self.http.request(uri, "GET", headers={'Pragma': 'no-cache'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) def testGetCacheControlNoStoreRequest(self): # A no-store request means that the response should not be stored. uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = self.http.request(uri, "GET", headers={'Cache-Control': 'no-store'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) (response, content) = self.http.request(uri, "GET", headers={'Cache-Control': 'no-store'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) def testGetCacheControlNoStoreResponse(self): # A no-store response means that the response should not be stored. uri = urllib.parse.urljoin(base, "no-store/no-store.asis") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) def testGetCacheControlNoCacheNoStoreRequest(self): # Test that a no-store, no-cache clears the entry from the cache # even if it was cached previously. uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = self.http.request(uri, "GET") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.fromcache, True) (response, content) = self.http.request(uri, "GET", headers={'Cache-Control': 'no-store, no-cache'}) (response, content) = self.http.request(uri, "GET", headers={'Cache-Control': 'no-store, no-cache'}) self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) def testUpdateInvalidatesCache(self): # Test that calling PUT or DELETE on a # URI that is cache invalidates that cache. uri = urllib.parse.urljoin(base, "304/test_etag.txt") (response, content) = self.http.request(uri, "GET") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.fromcache, True) (response, content) = self.http.request(uri, "DELETE") self.assertEqual(response.status, 405) (response, content) = self.http.request(uri, "GET") self.assertEqual(response.fromcache, False) def testUpdateUsesCachedETag(self): # Test that we natively support http://www.w3.org/1999/04/Editing/ uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) (response, content) = self.http.request(uri, "PUT", body="foo") self.assertEqual(response.status, 200) (response, content) = self.http.request(uri, "PUT", body="foo") self.assertEqual(response.status, 412) def testUpdatePatchUsesCachedETag(self): # Test that we natively support http://www.w3.org/1999/04/Editing/ uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) (response, content) = self.http.request(uri, "PATCH", body="foo") self.assertEqual(response.status, 200) (response, content) = self.http.request(uri, "PATCH", body="foo") self.assertEqual(response.status, 412) def testUpdateUsesCachedETagAndOCMethod(self): # Test that we natively support http://www.w3.org/1999/04/Editing/ uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) self.http.optimistic_concurrency_methods.append("DELETE") (response, content) = self.http.request(uri, "DELETE") self.assertEqual(response.status, 200) def testUpdateUsesCachedETagOverridden(self): # Test that we natively support http://www.w3.org/1999/04/Editing/ uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, False) (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) self.assertEqual(response.fromcache, True) (response, content) = self.http.request(uri, "PUT", body="foo", headers={'if-match': 'fred'}) self.assertEqual(response.status, 412) def testBasicAuth(self): # Test Basic Authentication uri = urllib.parse.urljoin(base, "basic/file.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) uri = urllib.parse.urljoin(base, "basic/") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) self.http.add_credentials('joe', 'password') (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) uri = urllib.parse.urljoin(base, "basic/file.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) def testBasicAuthWithDomain(self): # Test Basic Authentication uri = urllib.parse.urljoin(base, "basic/file.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) uri = urllib.parse.urljoin(base, "basic/") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) self.http.add_credentials('joe', 'password', "example.org") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) uri = urllib.parse.urljoin(base, "basic/file.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) domain = urllib.parse.urlparse(base)[1] self.http.add_credentials('joe', 'password', domain) (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) uri = urllib.parse.urljoin(base, "basic/file.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) def testBasicAuthTwoDifferentCredentials(self): # Test Basic Authentication with multiple sets of credentials uri = urllib.parse.urljoin(base, "basic2/file.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) uri = urllib.parse.urljoin(base, "basic2/") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) self.http.add_credentials('fred', 'barney') (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) uri = urllib.parse.urljoin(base, "basic2/file.txt") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) def testBasicAuthNested(self): # Test Basic Authentication with resources # that are nested uri = urllib.parse.urljoin(base, "basic-nested/") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) uri = urllib.parse.urljoin(base, "basic-nested/subdir") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) # Now add in credentials one at a time and test. self.http.add_credentials('joe', 'password') uri = urllib.parse.urljoin(base, "basic-nested/") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) uri = urllib.parse.urljoin(base, "basic-nested/subdir") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) self.http.add_credentials('fred', 'barney') uri = urllib.parse.urljoin(base, "basic-nested/") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) uri = urllib.parse.urljoin(base, "basic-nested/subdir") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) def testDigestAuth(self): # Test that we support Digest Authentication uri = urllib.parse.urljoin(base, "digest/") (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 401) self.http.add_credentials('joe', 'password') (response, content) = self.http.request(uri, "GET") self.assertEqual(response.status, 200) uri = urllib.parse.urljoin(base, "digest/file.txt") (response, content) = self.http.request(uri, "GET") def testDigestAuthNextNonceAndNC(self): # Test that if the server sets nextnonce that we reset # the nonce count back to 1 uri = urllib.parse.urljoin(base, "digest/file.txt") self.http.add_credentials('joe', 'password') (response, content) = self.http.request(uri, "GET", headers = {"cache-control":"no-cache"}) info = httplib2._parse_www_authenticate(response, 'authentication-info') self.assertEqual(response.status, 200) (response, content) = self.http.request(uri, "GET", headers = {"cache-control":"no-cache"}) info2 = httplib2._parse_www_authenticate(response, 'authentication-info') self.assertEqual(response.status, 200) if 'nextnonce' in info: self.assertEqual(info2['nc'], 1) def testDigestAuthStale(self): # Test that we can handle a nonce becoming stale uri = urllib.parse.urljoin(base, "digest-expire/file.txt") self.http.add_credentials('joe', 'password') (response, content) = self.http.request(uri, "GET", headers = {"cache-control":"no-cache"}) info = httplib2._parse_www_authenticate(response, 'authentication-info') self.assertEqual(response.status, 200) time.sleep(3) # Sleep long enough that the nonce becomes stale (response, content) = self.http.request(uri, "GET", headers = {"cache-control":"no-cache"}) self.assertFalse(response.fromcache) self.assertTrue(response._stale_digest) info3 = httplib2._parse_www_authenticate(response, 'authentication-info') self.assertEqual(response.status, 200) def reflector(self, content): return dict( [tuple(x.split("=", 1)) for x in content.decode('utf-8').strip().split("\n")] ) def testReflector(self): uri = urllib.parse.urljoin(base, "reflector/reflector.cgi") (response, content) = self.http.request(uri, "GET") d = self.reflector(content) self.assertTrue('HTTP_USER_AGENT' in d) def testConnectionClose(self): uri = "http://www.google.com/" (response, content) = self.http.request(uri, "GET") for c in self.http.connections.values(): self.assertNotEqual(None, c.sock) (response, content) = self.http.request(uri, "GET", headers={"connection": "close"}) for c in self.http.connections.values(): self.assertEqual(None, c.sock) def testPickleHttp(self): pickled_http = pickle.dumps(self.http) new_http = pickle.loads(pickled_http) self.assertEqual(sorted(new_http.__dict__.keys()), sorted(self.http.__dict__.keys())) for key in new_http.__dict__: if key in ('certificates', 'credentials'): self.assertEqual(new_http.__dict__[key].credentials, self.http.__dict__[key].credentials) elif key == 'cache': self.assertEqual(new_http.__dict__[key].cache, self.http.__dict__[key].cache) else: self.assertEqual(new_http.__dict__[key], self.http.__dict__[key]) def testPickleHttpWithConnection(self): self.http.request('http://bitworking.org', connection_type=_MyHTTPConnection) pickled_http = pickle.dumps(self.http) new_http = pickle.loads(pickled_http) self.assertEqual(list(self.http.connections.keys()), ['http:bitworking.org']) self.assertEqual(new_http.connections, {}) def testPickleCustomRequestHttp(self): def dummy_request(*args, **kwargs): return new_request(*args, **kwargs) dummy_request.dummy_attr = 'dummy_value' self.http.request = dummy_request pickled_http = pickle.dumps(self.http) self.assertFalse(b"S'request'" in pickled_http) try: import memcache class HttpTestMemCached(HttpTest): def setUp(self): self.cache = memcache.Client(['127.0.0.1:11211'], debug=0) #self.cache = memcache.Client(['10.0.0.4:11211'], debug=1) self.http = httplib2.Http(self.cache) self.cache.flush_all() # Not exactly sure why the sleep is needed here, but # if not present then some unit tests that rely on caching # fail. Memcached seems to lose some sets immediately # after a flush_all if the set is to a value that # was previously cached. (Maybe the flush is handled async?) time.sleep(1) self.http.clear_credentials() except: pass # ------------------------------------------------------------------------ class HttpPrivateTest(unittest.TestCase): def testParseCacheControl(self): # Test that we can parse the Cache-Control header self.assertEqual({}, httplib2._parse_cache_control({})) self.assertEqual({'no-cache': 1}, httplib2._parse_cache_control({'cache-control': ' no-cache'})) cc = httplib2._parse_cache_control({'cache-control': ' no-cache, max-age = 7200'}) self.assertEqual(cc['no-cache'], 1) self.assertEqual(cc['max-age'], '7200') cc = httplib2._parse_cache_control({'cache-control': ' , '}) self.assertEqual(cc[''], 1) try: cc = httplib2._parse_cache_control({'cache-control': 'Max-age=3600;post-check=1800,pre-check=3600'}) self.assertTrue("max-age" in cc) except: self.fail("Should not throw exception") def testNormalizeHeaders(self): # Test that we normalize headers to lowercase h = httplib2._normalize_headers({'Cache-Control': 'no-cache', 'Other': 'Stuff'}) self.assertTrue('cache-control' in h) self.assertTrue('other' in h) self.assertEqual('Stuff', h['other']) def testExpirationModelTransparent(self): # Test that no-cache makes our request TRANSPARENT response_headers = { 'cache-control': 'max-age=7200' } request_headers = { 'cache-control': 'no-cache' } self.assertEqual("TRANSPARENT", httplib2._entry_disposition(response_headers, request_headers)) def testMaxAgeNonNumeric(self): # Test that no-cache makes our request TRANSPARENT response_headers = { 'cache-control': 'max-age=fred, min-fresh=barney' } request_headers = { } self.assertEqual("STALE", httplib2._entry_disposition(response_headers, request_headers)) def testExpirationModelNoCacheResponse(self): # The date and expires point to an entry that should be # FRESH, but the no-cache over-rides that. now = time.time() response_headers = { 'date': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now)), 'expires': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now+4)), 'cache-control': 'no-cache' } request_headers = { } self.assertEqual("STALE", httplib2._entry_disposition(response_headers, request_headers)) def testExpirationModelStaleRequestMustReval(self): # must-revalidate forces STALE self.assertEqual("STALE", httplib2._entry_disposition({}, {'cache-control': 'must-revalidate'})) def testExpirationModelStaleResponseMustReval(self): # must-revalidate forces STALE self.assertEqual("STALE", httplib2._entry_disposition({'cache-control': 'must-revalidate'}, {})) def testExpirationModelFresh(self): response_headers = { 'date': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()), 'cache-control': 'max-age=2' } request_headers = { } self.assertEqual("FRESH", httplib2._entry_disposition(response_headers, request_headers)) time.sleep(3) self.assertEqual("STALE", httplib2._entry_disposition(response_headers, request_headers)) def testExpirationMaxAge0(self): response_headers = { 'date': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()), 'cache-control': 'max-age=0' } request_headers = { } self.assertEqual("STALE", httplib2._entry_disposition(response_headers, request_headers)) def testExpirationModelDateAndExpires(self): now = time.time() response_headers = { 'date': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now)), 'expires': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now+2)), } request_headers = { } self.assertEqual("FRESH", httplib2._entry_disposition(response_headers, request_headers)) time.sleep(3) self.assertEqual("STALE", httplib2._entry_disposition(response_headers, request_headers)) def testExpiresZero(self): now = time.time() response_headers = { 'date': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now)), 'expires': "0", } request_headers = { } self.assertEqual("STALE", httplib2._entry_disposition(response_headers, request_headers)) def testExpirationModelDateOnly(self): now = time.time() response_headers = { 'date': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now+3)), } request_headers = { } self.assertEqual("STALE", httplib2._entry_disposition(response_headers, request_headers)) def testExpirationModelOnlyIfCached(self): response_headers = { } request_headers = { 'cache-control': 'only-if-cached', } self.assertEqual("FRESH", httplib2._entry_disposition(response_headers, request_headers)) def testExpirationModelMaxAgeBoth(self): now = time.time() response_headers = { 'date': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now)), 'cache-control': 'max-age=2' } request_headers = { 'cache-control': 'max-age=0' } self.assertEqual("STALE", httplib2._entry_disposition(response_headers, request_headers)) def testExpirationModelDateAndExpiresMinFresh1(self): now = time.time() response_headers = { 'date': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now)), 'expires': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now+2)), } request_headers = { 'cache-control': 'min-fresh=2' } self.assertEqual("STALE", httplib2._entry_disposition(response_headers, request_headers)) def testExpirationModelDateAndExpiresMinFresh2(self): now = time.time() response_headers = { 'date': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now)), 'expires': time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(now+4)), } request_headers = { 'cache-control': 'min-fresh=2' } self.assertEqual("FRESH", httplib2._entry_disposition(response_headers, request_headers)) def testParseWWWAuthenticateEmpty(self): res = httplib2._parse_www_authenticate({}) self.assertEqual(len(list(res.keys())), 0) def testParseWWWAuthenticate(self): # different uses of spaces around commas res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Test realm="test realm" , foo=foo ,bar="bar", baz=baz,qux=qux'}) self.assertEqual(len(list(res.keys())), 1) self.assertEqual(len(list(res['test'].keys())), 5) # tokens with non-alphanum res = httplib2._parse_www_authenticate({ 'www-authenticate': 'T*!%#st realm=to*!%#en, to*!%#en="quoted string"'}) self.assertEqual(len(list(res.keys())), 1) self.assertEqual(len(list(res['t*!%#st'].keys())), 2) # quoted string with quoted pairs res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Test realm="a \\"test\\" realm"'}) self.assertEqual(len(list(res.keys())), 1) self.assertEqual(res['test']['realm'], 'a "test" realm') def testParseWWWAuthenticateStrict(self): httplib2.USE_WWW_AUTH_STRICT_PARSING = 1; self.testParseWWWAuthenticate(); httplib2.USE_WWW_AUTH_STRICT_PARSING = 0; def testParseWWWAuthenticateBasic(self): res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Basic realm="me"'}) basic = res['basic'] self.assertEqual('me', basic['realm']) res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Basic realm="me", algorithm="MD5"'}) basic = res['basic'] self.assertEqual('me', basic['realm']) self.assertEqual('MD5', basic['algorithm']) res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Basic realm="me", algorithm=MD5'}) basic = res['basic'] self.assertEqual('me', basic['realm']) self.assertEqual('MD5', basic['algorithm']) def testParseWWWAuthenticateBasic2(self): res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Basic realm="me",other="fred" '}) basic = res['basic'] self.assertEqual('me', basic['realm']) self.assertEqual('fred', basic['other']) def testParseWWWAuthenticateBasic3(self): res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Basic REAlm="me" '}) basic = res['basic'] self.assertEqual('me', basic['realm']) def testParseWWWAuthenticateDigest(self): res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"'}) digest = res['digest'] self.assertEqual('testrealm@host.com', digest['realm']) self.assertEqual('auth,auth-int', digest['qop']) def testParseWWWAuthenticateMultiple(self): res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41" Basic REAlm="me" '}) digest = res['digest'] self.assertEqual('testrealm@host.com', digest['realm']) self.assertEqual('auth,auth-int', digest['qop']) self.assertEqual('dcd98b7102dd2f0e8b11d0f600bfb0c093', digest['nonce']) self.assertEqual('5ccc069c403ebaf9f0171e9517f40e41', digest['opaque']) basic = res['basic'] self.assertEqual('me', basic['realm']) def testParseWWWAuthenticateMultiple2(self): # Handle an added comma between challenges, which might get thrown in if the challenges were # originally sent in separate www-authenticate headers. res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41", Basic REAlm="me" '}) digest = res['digest'] self.assertEqual('testrealm@host.com', digest['realm']) self.assertEqual('auth,auth-int', digest['qop']) self.assertEqual('dcd98b7102dd2f0e8b11d0f600bfb0c093', digest['nonce']) self.assertEqual('5ccc069c403ebaf9f0171e9517f40e41', digest['opaque']) basic = res['basic'] self.assertEqual('me', basic['realm']) def testParseWWWAuthenticateMultiple3(self): # Handle an added comma between challenges, which might get thrown in if the challenges were # originally sent in separate www-authenticate headers. res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Digest realm="testrealm@host.com", qop="auth,auth-int", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41", Basic REAlm="me", WSSE realm="foo", profile="UsernameToken"'}) digest = res['digest'] self.assertEqual('testrealm@host.com', digest['realm']) self.assertEqual('auth,auth-int', digest['qop']) self.assertEqual('dcd98b7102dd2f0e8b11d0f600bfb0c093', digest['nonce']) self.assertEqual('5ccc069c403ebaf9f0171e9517f40e41', digest['opaque']) basic = res['basic'] self.assertEqual('me', basic['realm']) wsse = res['wsse'] self.assertEqual('foo', wsse['realm']) self.assertEqual('UsernameToken', wsse['profile']) def testParseWWWAuthenticateMultiple4(self): res = httplib2._parse_www_authenticate({ 'www-authenticate': 'Digest realm="test-real.m@host.com", qop \t=\t"\tauth,auth-int", nonce="(*)&^&$%#",opaque="5ccc069c403ebaf9f0171e9517f40e41", Basic REAlm="me", WSSE realm="foo", profile="UsernameToken"'}) digest = res['digest'] self.assertEqual('test-real.m@host.com', digest['realm']) self.assertEqual('\tauth,auth-int', digest['qop']) self.assertEqual('(*)&^&$%#', digest['nonce']) def testParseWWWAuthenticateMoreQuoteCombos(self): res = httplib2._parse_www_authenticate({'www-authenticate':'Digest realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", algorithm=MD5, qop="auth", stale=true'}) digest = res['digest'] self.assertEqual('myrealm', digest['realm']) def testParseWWWAuthenticateMalformed(self): try: res = httplib2._parse_www_authenticate({'www-authenticate':'OAuth "Facebook Platform" "invalid_token" "Invalid OAuth access token."'}) self.fail("should raise an exception") except httplib2.MalformedHeader: pass def testDigestObject(self): credentials = ('joe', 'password') host = None request_uri = '/projects/httplib2/test/digest/' headers = {} response = { 'www-authenticate': 'Digest realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", algorithm=MD5, qop="auth"' } content = b"" d = httplib2.DigestAuthentication(credentials, host, request_uri, headers, response, content, None) d.request("GET", request_uri, headers, content, cnonce="33033375ec278a46") our_request = "authorization: %s" % headers['authorization'] working_request = 'authorization: Digest username="joe", realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", uri="/projects/httplib2/test/digest/", algorithm=MD5, response="97ed129401f7cdc60e5db58a80f3ea8b", qop=auth, nc=00000001, cnonce="33033375ec278a46"' self.assertEqual(our_request, working_request) def testDigestObjectWithOpaque(self): credentials = ('joe', 'password') host = None request_uri = '/projects/httplib2/test/digest/' headers = {} response = { 'www-authenticate': 'Digest realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", algorithm=MD5, qop="auth", opaque="atestopaque"' } content = "" d = httplib2.DigestAuthentication(credentials, host, request_uri, headers, response, content, None) d.request("GET", request_uri, headers, content, cnonce="33033375ec278a46") our_request = "authorization: %s" % headers['authorization'] working_request = 'authorization: Digest username="joe", realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", uri="/projects/httplib2/test/digest/", algorithm=MD5, response="97ed129401f7cdc60e5db58a80f3ea8b", qop=auth, nc=00000001, cnonce="33033375ec278a46", opaque="atestopaque"' self.assertEqual(our_request, working_request) def testDigestObjectStale(self): credentials = ('joe', 'password') host = None request_uri = '/projects/httplib2/test/digest/' headers = {} response = httplib2.Response({ }) response['www-authenticate'] = 'Digest realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", algorithm=MD5, qop="auth", stale=true' response.status = 401 content = b"" d = httplib2.DigestAuthentication(credentials, host, request_uri, headers, response, content, None) # Returns true to force a retry self.assertTrue( d.response(response, content) ) def testDigestObjectAuthInfo(self): credentials = ('joe', 'password') host = None request_uri = '/projects/httplib2/test/digest/' headers = {} response = httplib2.Response({ }) response['www-authenticate'] = 'Digest realm="myrealm", nonce="Ygk86AsKBAA=3516200d37f9a3230352fde99977bd6d472d4306", algorithm=MD5, qop="auth", stale=true' response['authentication-info'] = 'nextnonce="fred"' content = b"" d = httplib2.DigestAuthentication(credentials, host, request_uri, headers, response, content, None) # Returns true to force a retry self.assertFalse( d.response(response, content) ) self.assertEqual('fred', d.challenge['nonce']) self.assertEqual(1, d.challenge['nc']) def testWsseAlgorithm(self): digest = httplib2._wsse_username_token("d36e316282959a9ed4c89851497a717f", "2003-12-15T14:43:07Z", "taadtaadpstcsm") expected = b"quR/EWLAV4xLf9Zqyw4pDmfV9OY=" self.assertEqual(expected, digest) def testEnd2End(self): # one end to end header response = {'content-type': 'application/atom+xml', 'te': 'deflate'} end2end = httplib2._get_end2end_headers(response) self.assertTrue('content-type' in end2end) self.assertTrue('te' not in end2end) self.assertTrue('connection' not in end2end) # one end to end header that gets eliminated response = {'connection': 'content-type', 'content-type': 'application/atom+xml', 'te': 'deflate'} end2end = httplib2._get_end2end_headers(response) self.assertTrue('content-type' not in end2end) self.assertTrue('te' not in end2end) self.assertTrue('connection' not in end2end) # Degenerate case of no headers response = {} end2end = httplib2._get_end2end_headers(response) self.assertEqual(0, len(end2end)) # Degenerate case of connection referrring to a header not passed in response = {'connection': 'content-type'} end2end = httplib2._get_end2end_headers(response) self.assertEqual(0, len(end2end)) class TestProxyInfo(unittest.TestCase): def setUp(self): self.orig_env = dict(os.environ) def tearDown(self): os.environ.clear() os.environ.update(self.orig_env) def test_from_url(self): pi = httplib2.proxy_info_from_url('http://myproxy.example.com') self.assertEqual(pi.proxy_host, 'myproxy.example.com') self.assertEqual(pi.proxy_port, 80) self.assertEqual(pi.proxy_user, None) def test_from_url_ident(self): pi = httplib2.proxy_info_from_url('http://zoidberg:fish@someproxy:99') self.assertEqual(pi.proxy_host, 'someproxy') self.assertEqual(pi.proxy_port, 99) self.assertEqual(pi.proxy_user, 'zoidberg') self.assertEqual(pi.proxy_pass, 'fish') def test_from_env(self): os.environ['http_proxy'] = 'http://myproxy.example.com:8080' pi = httplib2.proxy_info_from_environment() self.assertEqual(pi.proxy_host, 'myproxy.example.com') self.assertEqual(pi.proxy_port, 8080) def test_from_env_no_proxy(self): os.environ['http_proxy'] = 'http://myproxy.example.com:80' os.environ['https_proxy'] = 'http://myproxy.example.com:81' pi = httplib2.proxy_info_from_environment('https') self.assertEqual(pi.proxy_host, 'myproxy.example.com') self.assertEqual(pi.proxy_port, 81) def test_from_env_none(self): os.environ.clear() pi = httplib2.proxy_info_from_environment() self.assertEqual(pi, None) if __name__ == '__main__': unittest.main()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 202, 199, 624, 202, 199, 12942, 18, 396, 2999, 199, 33, 663, 402, 4137, 2295, 367, 8809, 18, 14, 647, 14, 2999, 199, 18153, 2018, 650, 14, 16, 503, 2945, 202, 199, 624, 2999, 199, 363, 2502, 363, 275, 298, 5691, 69, 29096, 269, 2308, 334, 20241, 32, 2075, 9818, 14, 1308, 2924, 202, 199, 363, 7307, 363, 275, 298, 7384, 8315, 12, 7135, 69, 29096, 269, 2308, 2, 202, 199, 363, 21630, 363, 275, 2097, 6470, 19641, 937, 202, 199, 363, 1682, 363, 275, 298, 13965, 2, 202, 199, 363, 5570, 363, 275, 408, 408, 202, 199, 363, 1023, 363, 275, 298, 16, 14, 18, 334, 4, 26176, 26, 25760, 2672, 2924, 2999, 199, 646, 1300, 772, 202, 199, 646, 1455, 14, 1258, 202, 199, 646, 8809, 18, 202, 199, 646, 5890, 202, 199, 646, 747, 202, 199, 646, 5927, 202, 199, 646, 2838, 202, 199, 646, 6149, 202, 199, 646, 984, 202, 199, 646, 900, 202, 199, 646, 2882, 202, 199, 646, 4011, 14, 1122, 2999, 199, 3, 710, 511, 5944, 1300, 5108, 202, 199, 1095, 275, 283, 1014, 921, 2075, 9818, 14, 1308, 15, 6776, 15, 12942, 18, 15, 396, 4805, 202, 199, 3, 1095, 275, 283, 1014, 921, 5967, 15, 6776, 15, 12942, 18, 15, 396, 4805, 202, 199, 1637, 3567, 985, 275, 3680, 1637, 2, 8065, 199, 533, 23934, 774, 8, 2796, 14, 1746, 304, 1128, 347, 511, 8, 277, 304, 1039, 286, 275, 8809, 18, 14, 13428, 342, 1039, 286, 14, 525, 480, 20241, 401, 298, 2060, 531, 1039, 291, 14, 629, 9313, 20241, 401, 298, 2060, 1288, 769, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 59, 16, 566, 1039, 291, 14, 629, 9313, 20241, 401, 298, 2060, 1288, 769, 8, 67, 14, 1661, 11986, 11515, 16, 566, 1039, 286, 14, 525, 480, 22980, 401, 298, 2060, 18, 401, 298, 87, 352, 17733, 2520, 14, 1308, 531, 1039, 291, 14, 629, 9313, 20241, 401, 298, 2060, 1288, 769, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 59, 16, 566, 1039, 291, 14, 629, 8, 17, 12, 822, 8, 513, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 430, 1039, 291, 14, 629, 8, 18, 12, 822, 8, 513, 8, 67, 14, 1661, 480, 87, 352, 17733, 2520, 14, 1308, 2237, 430, 1039, 291, 14, 1815, 9313, 22980, 401, 298, 2060, 18, 531, 315, 769, 8, 67, 14, 1661, 480, 87, 352, 17733, 2520, 14, 1308, 13324, 1039, 286, 14, 3584, 342, 1039, 291, 14, 629, 8, 16, 12, 822, 8, 513, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 430, 1039, 286, 14, 525, 480, 22980, 401, 298, 2060, 18, 401, 298, 87, 352, 17733, 2520, 14, 1308, 531, 1039, 291, 14, 1815, 9313, 22980, 401, 298, 2060, 18, 531, 315, 769, 8, 67, 14, 1661, 480, 87, 352, 17733, 2520, 14, 1308, 13324, 1039, 291, 14, 629, 8, 16, 12, 822, 8, 513, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 430, 1039, 291, 14, 629, 8, 16, 12, 822, 8, 513, 8, 67, 14, 1661, 11986, 7845, 8065, 199, 533, 10191, 774, 8, 2796, 14, 1746, 304, 1128, 347, 511, 2532, 11976, 1272, 8, 277, 304, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 3260, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 2237, 1039, 291, 14, 629, 8, 661, 2859, 297, 283, 2694, 14, 957, 297, 3260, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 2859, 921, 2694, 14, 957, 2237, 1039, 291, 14, 629, 8, 661, 2859, 297, 283, 2694, 14, 957, 26, 15844, 297, 3260, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 2859, 921, 2694, 14, 957, 26, 15844, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 17220, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 1994, 515, 297, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 515, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 1994, 515, 297, 283, 65, 29, 17, 6, 66, 29, 18, 297, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 515, 31, 65, 29, 17, 6, 66, 29, 18, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 1994, 515, 297, 283, 65, 29, 17, 6, 66, 29, 18, 297, 283, 22980, 7, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 515, 31, 65, 29, 17, 6, 66, 29, 18, 3, 22980, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 1994, 515, 297, 283, 65, 29, 17, 6, 66, 29, 18, 297, 283, 22980, 7, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 515, 31, 65, 29, 17, 6, 66, 29, 18, 3, 22980, 2237, 8065, 199, 533, 20503, 15548, 774, 8, 2796, 14, 1746, 304, 1128, 347, 511, 8, 277, 304, 1039, 291, 14, 629, 8, 298, 1014, 921, 2694, 14, 1308, 10665, 8809, 18, 14, 633, 4791, 480, 1014, 921, 2694, 14, 1308, 531, 1988, 17, 566, 1039, 291, 14, 629, 8, 298, 1014, 921, 2694, 14, 1308, 10665, 8809, 18, 14, 633, 4791, 480, 1014, 921, 1438, 1156, 11045, 14, 1308, 531, 1988, 17, 566, 1039, 291, 14, 629, 8, 298, 1014, 921, 2694, 14, 1308, 10197, 29, 66, 401, 8809, 18, 14, 633, 4791, 480, 1014, 921, 1438, 1156, 11045, 14, 1308, 23295, 66, 531, 1988, 17, 566, 1039, 291, 14, 629, 8, 298, 1014, 921, 2694, 14, 1308, 15, 1662, 515, 31, 65, 29, 66, 401, 8809, 18, 14, 633, 4791, 480, 1014, 921, 1438, 1156, 11045, 14, 1308, 15, 1662, 515, 31, 65, 29, 66, 531, 1988, 17, 566, 1039, 291, 14, 629, 8, 298, 1014, 921, 5967 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 202, 199, 624, 202, 199, 12942, 18, 396, 2999, 199, 33, 663, 402, 4137, 2295, 367, 8809, 18, 14, 647, 14, 2999, 199, 18153, 2018, 650, 14, 16, 503, 2945, 202, 199, 624, 2999, 199, 363, 2502, 363, 275, 298, 5691, 69, 29096, 269, 2308, 334, 20241, 32, 2075, 9818, 14, 1308, 2924, 202, 199, 363, 7307, 363, 275, 298, 7384, 8315, 12, 7135, 69, 29096, 269, 2308, 2, 202, 199, 363, 21630, 363, 275, 2097, 6470, 19641, 937, 202, 199, 363, 1682, 363, 275, 298, 13965, 2, 202, 199, 363, 5570, 363, 275, 408, 408, 202, 199, 363, 1023, 363, 275, 298, 16, 14, 18, 334, 4, 26176, 26, 25760, 2672, 2924, 2999, 199, 646, 1300, 772, 202, 199, 646, 1455, 14, 1258, 202, 199, 646, 8809, 18, 202, 199, 646, 5890, 202, 199, 646, 747, 202, 199, 646, 5927, 202, 199, 646, 2838, 202, 199, 646, 6149, 202, 199, 646, 984, 202, 199, 646, 900, 202, 199, 646, 2882, 202, 199, 646, 4011, 14, 1122, 2999, 199, 3, 710, 511, 5944, 1300, 5108, 202, 199, 1095, 275, 283, 1014, 921, 2075, 9818, 14, 1308, 15, 6776, 15, 12942, 18, 15, 396, 4805, 202, 199, 3, 1095, 275, 283, 1014, 921, 5967, 15, 6776, 15, 12942, 18, 15, 396, 4805, 202, 199, 1637, 3567, 985, 275, 3680, 1637, 2, 8065, 199, 533, 23934, 774, 8, 2796, 14, 1746, 304, 1128, 347, 511, 8, 277, 304, 1039, 286, 275, 8809, 18, 14, 13428, 342, 1039, 286, 14, 525, 480, 20241, 401, 298, 2060, 531, 1039, 291, 14, 629, 9313, 20241, 401, 298, 2060, 1288, 769, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 59, 16, 566, 1039, 291, 14, 629, 9313, 20241, 401, 298, 2060, 1288, 769, 8, 67, 14, 1661, 11986, 11515, 16, 566, 1039, 286, 14, 525, 480, 22980, 401, 298, 2060, 18, 401, 298, 87, 352, 17733, 2520, 14, 1308, 531, 1039, 291, 14, 629, 9313, 20241, 401, 298, 2060, 1288, 769, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 59, 16, 566, 1039, 291, 14, 629, 8, 17, 12, 822, 8, 513, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 430, 1039, 291, 14, 629, 8, 18, 12, 822, 8, 513, 8, 67, 14, 1661, 480, 87, 352, 17733, 2520, 14, 1308, 2237, 430, 1039, 291, 14, 1815, 9313, 22980, 401, 298, 2060, 18, 531, 315, 769, 8, 67, 14, 1661, 480, 87, 352, 17733, 2520, 14, 1308, 13324, 1039, 286, 14, 3584, 342, 1039, 291, 14, 629, 8, 16, 12, 822, 8, 513, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 430, 1039, 286, 14, 525, 480, 22980, 401, 298, 2060, 18, 401, 298, 87, 352, 17733, 2520, 14, 1308, 531, 1039, 291, 14, 1815, 9313, 22980, 401, 298, 2060, 18, 531, 315, 769, 8, 67, 14, 1661, 480, 87, 352, 17733, 2520, 14, 1308, 13324, 1039, 291, 14, 629, 8, 16, 12, 822, 8, 513, 8, 67, 14, 1661, 480, 2075, 9818, 14, 1308, 2237, 430, 1039, 291, 14, 629, 8, 16, 12, 822, 8, 513, 8, 67, 14, 1661, 11986, 7845, 8065, 199, 533, 10191, 774, 8, 2796, 14, 1746, 304, 1128, 347, 511, 2532, 11976, 1272, 8, 277, 304, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 3260, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 2237, 1039, 291, 14, 629, 8, 661, 2859, 297, 283, 2694, 14, 957, 297, 3260, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 2859, 921, 2694, 14, 957, 2237, 1039, 291, 14, 629, 8, 661, 2859, 297, 283, 2694, 14, 957, 26, 15844, 297, 3260, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 2859, 921, 2694, 14, 957, 26, 15844, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 17220, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 1994, 515, 297, 488, 12, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 515, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 1994, 515, 297, 283, 65, 29, 17, 6, 66, 29, 18, 297, 488, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 515, 31, 65, 29, 17, 6, 66, 29, 18, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 1994, 515, 297, 283, 65, 29, 17, 6, 66, 29, 18, 297, 283, 22980, 7, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 515, 31, 65, 29, 17, 6, 66, 29, 18, 3, 22980, 2237, 1039, 291, 14, 629, 8, 661, 1014, 297, 283, 2694, 14, 957, 297, 1994, 515, 297, 283, 65, 29, 17, 6, 66, 29, 18, 297, 283, 22980, 7, 2318, 8809, 18, 14, 1122, 63, 2302, 480, 1014, 921, 2694, 14, 957, 15, 515, 31, 65, 29, 17, 6, 66, 29, 18, 3, 22980, 2237, 8065, 199, 533, 20503, 15548, 774, 8, 2796, 14, 1746, 304, 1128, 347, 511, 8, 277, 304, 1039, 291, 14, 629, 8, 298, 1014, 921, 2694, 14, 1308, 10665, 8809, 18, 14, 633, 4791, 480, 1014, 921, 2694, 14, 1308, 531, 1988, 17, 566, 1039, 291, 14, 629, 8, 298, 1014, 921, 2694, 14, 1308, 10665, 8809, 18, 14, 633, 4791, 480, 1014, 921, 1438, 1156, 11045, 14, 1308, 531, 1988, 17, 566, 1039, 291, 14, 629, 8, 298, 1014, 921, 2694, 14, 1308, 10197, 29, 66, 401, 8809, 18, 14, 633, 4791, 480, 1014, 921, 1438, 1156, 11045, 14, 1308, 23295, 66, 531, 1988, 17, 566, 1039, 291, 14, 629, 8, 298, 1014, 921, 2694, 14, 1308, 15, 1662, 515, 31, 65, 29, 66, 401, 8809, 18, 14, 633, 4791, 480, 1014, 921, 1438, 1156, 11045, 14, 1308, 15, 1662, 515, 31, 65, 29, 66, 531, 1988, 17, 566, 1039, 291, 14, 629, 8, 298, 1014, 921, 5967, 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, 1 ]
sandeepgupta2k4/tensorflow
tensorflow/python/ops/split_benchmark.py
176
4403
# 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. # ============================================================================== """Benchmark for split and grad of split.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy as np from tensorflow.core.protobuf import config_pb2 from tensorflow.python.client import session as session_lib 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 variables from tensorflow.python.platform import benchmark from tensorflow.python.platform import test from tensorflow.python.platform import tf_logging as logging def build_graph(device, input_shape, output_sizes, axis): """Build a graph containing a sequence of split operations. Args: device: string, the device to run on. input_shape: shape of the input tensor. output_sizes: size of each output along axis. axis: axis to be split along. Returns: An array of tensors to run() """ with ops.device("/%s:0" % device): inp = array_ops.zeros(input_shape) outputs = [] for _ in range(100): outputs.extend(array_ops.split(inp, output_sizes, axis)) return control_flow_ops.group(*outputs) class SplitBenchmark(test.Benchmark): """Benchmark split!""" def _run_graph(self, device, output_shape, variable, num_outputs, axis): """Run the graph and print its execution time. Args: device: string, the device to run on. output_shape: shape of each output tensors. variable: whether or not the output shape should be fixed num_outputs: the number of outputs to split the input into axis: axis to be split Returns: The duration of the run in seconds. """ graph = ops.Graph() with graph.as_default(): if not variable: if axis == 0: input_shape = [output_shape[0] * num_outputs, output_shape[1]] sizes = [output_shape[0] for _ in range(num_outputs)] else: input_shape = [output_shape[0], output_shape[1] * num_outputs] sizes = [output_shape[1] for _ in range(num_outputs)] else: sizes = np.random.randint( low=max(1, output_shape[axis] - 2), high=output_shape[axis] + 2, size=num_outputs) total_size = np.sum(sizes) if axis == 0: input_shape = [total_size, output_shape[1]] else: input_shape = [output_shape[0], total_size] outputs = build_graph(device, input_shape, sizes, axis) config = config_pb2.ConfigProto(graph_options=config_pb2.GraphOptions( optimizer_options=config_pb2.OptimizerOptions( opt_level=config_pb2.OptimizerOptions.L0))) with session_lib.Session(graph=graph, config=config) as session: logging.set_verbosity("info") variables.global_variables_initializer().run() bench = benchmark.TensorFlowBenchmark() bench.run_op_benchmark( session, outputs, mbs=input_shape[0] * input_shape[1] * 4 * 2 * 100 / 1e6, extras={ "input_shape": input_shape, "variable": variable, "axis": axis }) def benchmark_split(self): print("Forward vs backward concat") shapes = [[2000, 8], [8, 2000], [100, 18], [1000, 18], [10000, 18], [100, 97], [1000, 97], [10000, 1], [1, 10000]] axis_ = [1] # 0 is very fast because it doesn't actually do any copying num_outputs = 100 variable = [False, True] # fixed input size or not for shape in shapes: for axis in axis_: for v in variable: self._run_graph("gpu", shape, v, num_outputs, axis) if __name__ == "__main__": test.main()
apache-2.0
[ 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, 624, 18644, 367, 3715, 436, 7659, 402, 3715, 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, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 1018, 14, 7204, 492, 1101, 63, 3317, 18, 199, 504, 3228, 14, 1548, 14, 1258, 492, 2351, 465, 2351, 63, 773, 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, 2860, 199, 504, 3228, 14, 1548, 14, 3246, 492, 12338, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 3246, 492, 2833, 63, 4806, 465, 2050, 421, 199, 318, 1900, 63, 2180, 8, 1782, 12, 1324, 63, 1392, 12, 1072, 63, 7723, 12, 3114, 304, 523, 408, 3425, 282, 3343, 3035, 282, 3414, 402, 3715, 5331, 14, 819, 3033, 26, 272, 2243, 26, 1059, 12, 314, 2243, 370, 1255, 641, 14, 272, 1324, 63, 1392, 26, 2215, 402, 314, 1324, 2345, 14, 272, 1072, 63, 7723, 26, 1568, 402, 1924, 1072, 3180, 3114, 14, 272, 3114, 26, 3114, 370, 506, 3715, 3180, 14, 819, 1803, 26, 272, 1626, 1625, 402, 10519, 370, 1255, 342, 523, 408, 523, 543, 4156, 14, 1782, 480, 3149, 83, 26, 16, 2, 450, 2243, 304, 272, 10702, 275, 1625, 63, 1483, 14, 4250, 8, 1210, 63, 1392, 9, 339, 4704, 275, 942, 272, 367, 485, 315, 1425, 8, 1960, 304, 489, 4704, 14, 2880, 8, 1144, 63, 1483, 14, 1294, 8, 11416, 12, 1072, 63, 7723, 12, 3114, 430, 272, 372, 3304, 63, 1659, 63, 1483, 14, 923, 2031, 4467, 9, 421, 199, 533, 11740, 18644, 8, 396, 14, 18644, 304, 523, 408, 18644, 3715, 1, 624, 819, 347, 485, 1065, 63, 2180, 8, 277, 12, 2243, 12, 1072, 63, 1392, 12, 1750, 12, 1967, 63, 4467, 12, 3114, 304, 272, 408, 2540, 314, 3343, 436, 870, 2399, 6451, 900, 14, 339, 3033, 26, 489, 2243, 26, 1059, 12, 314, 2243, 370, 1255, 641, 14, 489, 1072, 63, 1392, 26, 2215, 402, 1924, 1072, 10519, 14, 489, 1750, 26, 3775, 503, 440, 314, 1072, 2215, 1077, 506, 6317, 489, 1967, 63, 4467, 26, 314, 1329, 402, 4704, 370, 3715, 314, 1324, 1901, 489, 3114, 26, 3114, 370, 506, 3715, 339, 1803, 26, 489, 710, 7373, 402, 314, 1255, 315, 4696, 14, 272, 408, 272, 3343, 275, 4156, 14, 4578, 342, 272, 543, 3343, 14, 305, 63, 885, 837, 489, 340, 440, 1750, 26, 267, 340, 3114, 508, 378, 26, 881, 1324, 63, 1392, 275, 359, 1199, 63, 1392, 59, 16, 61, 627, 1967, 63, 4467, 12, 1072, 63, 1392, 59, 17, 2677, 881, 10627, 275, 359, 1199, 63, 1392, 59, 16, 61, 367, 485, 315, 1425, 8, 1507, 63, 4467, 1874, 267, 587, 26, 881, 1324, 63, 1392, 275, 359, 1199, 63, 1392, 59, 16, 467, 1072, 63, 1392, 59, 17, 61, 627, 1967, 63, 4467, 61, 881, 10627, 275, 359, 1199, 63, 1392, 59, 17, 61, 367, 485, 315, 1425, 8, 1507, 63, 4467, 1874, 489, 587, 26, 267, 10627, 275, 980, 14, 2355, 14, 8393, 8, 288, 6465, 29, 988, 8, 17, 12, 1072, 63, 1392, 59, 3127, 61, 446, 499, 395, 288, 4721, 29, 1199, 63, 1392, 59, 3127, 61, 435, 499, 12, 288, 1568, 29, 1507, 63, 4467, 9, 267, 3141, 63, 890, 275, 980, 14, 1838, 8, 7723, 9, 267, 340, 3114, 508, 378, 26, 881, 1324, 63, 1392, 275, 359, 2923, 63, 890, 12, 1072, 63, 1392, 59, 17, 2677, 267, 587, 26, 881, 1324, 63, 1392, 275, 359, 1199, 63, 1392, 59, 16, 467, 3141, 63, 890, 61, 2541, 4704, 275, 1900, 63, 2180, 8, 1782, 12, 1324, 63, 1392, 12, 10627, 12, 3114, 9, 272, 1101, 275, 1101, 63, 3317, 18, 14, 2028, 8548, 8, 2180, 63, 1419, 29, 888, 63, 3317, 18, 14, 4578, 4558, 8, 267, 10736, 63, 1419, 29, 888, 63, 3317, 18, 14, 13946, 4558, 8, 288, 2450, 63, 1896, 29, 888, 63, 3317, 18, 14, 13946, 4558, 14, 44, 16, 1724, 272, 543, 2351, 63, 773, 14, 4434, 8, 2180, 29, 2180, 12, 1101, 29, 888, 9, 465, 2351, 26, 489, 2050, 14, 409, 63, 9833, 480, 815, 531, 489, 2860, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 489, 26456, 275, 12338, 14, 26998, 18644, 342, 489, 26456, 14, 1065, 63, 411, 63, 11861, 8, 881, 2351, 12, 881, 4704, 12, 881, 333, 1533, 29, 1210, 63, 1392, 59, 16, 61, 627, 1324, 63, 1392, 59, 17, 61, 627, 841, 627, 499, 627, 2948, 1182, 413, 69, 22, 12, 881, 13751, 3126, 1598, 298, 1210, 63, 1392, 582, 1324, 63, 1392, 12, 1598, 298, 1975, 582, 1750, 12, 1598, 298, 3127, 582, 3114, 881, 3828, 819, 347, 12338, 63, 1294, 8, 277, 304, 272, 870, 480, 12984, 8118, 13388, 17159, 531, 272, 11751, 275, 3474, 8269, 12, 1695, 467, 359, 24, 12, 12293, 467, 359, 1960, 12, 6155, 467, 359, 5279, 12, 6155, 467, 359, 9943, 12, 6155, 467, 1598, 359, 1960, 12, 15997, 467, 359, 5279, 12, 15997, 467, 359, 9943, 12, 413 ]
[ 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, 624, 18644, 367, 3715, 436, 7659, 402, 3715, 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, 646, 2680, 465, 980, 199, 199, 504, 3228, 14, 1018, 14, 7204, 492, 1101, 63, 3317, 18, 199, 504, 3228, 14, 1548, 14, 1258, 492, 2351, 465, 2351, 63, 773, 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, 2860, 199, 504, 3228, 14, 1548, 14, 3246, 492, 12338, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 3246, 492, 2833, 63, 4806, 465, 2050, 421, 199, 318, 1900, 63, 2180, 8, 1782, 12, 1324, 63, 1392, 12, 1072, 63, 7723, 12, 3114, 304, 523, 408, 3425, 282, 3343, 3035, 282, 3414, 402, 3715, 5331, 14, 819, 3033, 26, 272, 2243, 26, 1059, 12, 314, 2243, 370, 1255, 641, 14, 272, 1324, 63, 1392, 26, 2215, 402, 314, 1324, 2345, 14, 272, 1072, 63, 7723, 26, 1568, 402, 1924, 1072, 3180, 3114, 14, 272, 3114, 26, 3114, 370, 506, 3715, 3180, 14, 819, 1803, 26, 272, 1626, 1625, 402, 10519, 370, 1255, 342, 523, 408, 523, 543, 4156, 14, 1782, 480, 3149, 83, 26, 16, 2, 450, 2243, 304, 272, 10702, 275, 1625, 63, 1483, 14, 4250, 8, 1210, 63, 1392, 9, 339, 4704, 275, 942, 272, 367, 485, 315, 1425, 8, 1960, 304, 489, 4704, 14, 2880, 8, 1144, 63, 1483, 14, 1294, 8, 11416, 12, 1072, 63, 7723, 12, 3114, 430, 272, 372, 3304, 63, 1659, 63, 1483, 14, 923, 2031, 4467, 9, 421, 199, 533, 11740, 18644, 8, 396, 14, 18644, 304, 523, 408, 18644, 3715, 1, 624, 819, 347, 485, 1065, 63, 2180, 8, 277, 12, 2243, 12, 1072, 63, 1392, 12, 1750, 12, 1967, 63, 4467, 12, 3114, 304, 272, 408, 2540, 314, 3343, 436, 870, 2399, 6451, 900, 14, 339, 3033, 26, 489, 2243, 26, 1059, 12, 314, 2243, 370, 1255, 641, 14, 489, 1072, 63, 1392, 26, 2215, 402, 1924, 1072, 10519, 14, 489, 1750, 26, 3775, 503, 440, 314, 1072, 2215, 1077, 506, 6317, 489, 1967, 63, 4467, 26, 314, 1329, 402, 4704, 370, 3715, 314, 1324, 1901, 489, 3114, 26, 3114, 370, 506, 3715, 339, 1803, 26, 489, 710, 7373, 402, 314, 1255, 315, 4696, 14, 272, 408, 272, 3343, 275, 4156, 14, 4578, 342, 272, 543, 3343, 14, 305, 63, 885, 837, 489, 340, 440, 1750, 26, 267, 340, 3114, 508, 378, 26, 881, 1324, 63, 1392, 275, 359, 1199, 63, 1392, 59, 16, 61, 627, 1967, 63, 4467, 12, 1072, 63, 1392, 59, 17, 2677, 881, 10627, 275, 359, 1199, 63, 1392, 59, 16, 61, 367, 485, 315, 1425, 8, 1507, 63, 4467, 1874, 267, 587, 26, 881, 1324, 63, 1392, 275, 359, 1199, 63, 1392, 59, 16, 467, 1072, 63, 1392, 59, 17, 61, 627, 1967, 63, 4467, 61, 881, 10627, 275, 359, 1199, 63, 1392, 59, 17, 61, 367, 485, 315, 1425, 8, 1507, 63, 4467, 1874, 489, 587, 26, 267, 10627, 275, 980, 14, 2355, 14, 8393, 8, 288, 6465, 29, 988, 8, 17, 12, 1072, 63, 1392, 59, 3127, 61, 446, 499, 395, 288, 4721, 29, 1199, 63, 1392, 59, 3127, 61, 435, 499, 12, 288, 1568, 29, 1507, 63, 4467, 9, 267, 3141, 63, 890, 275, 980, 14, 1838, 8, 7723, 9, 267, 340, 3114, 508, 378, 26, 881, 1324, 63, 1392, 275, 359, 2923, 63, 890, 12, 1072, 63, 1392, 59, 17, 2677, 267, 587, 26, 881, 1324, 63, 1392, 275, 359, 1199, 63, 1392, 59, 16, 467, 3141, 63, 890, 61, 2541, 4704, 275, 1900, 63, 2180, 8, 1782, 12, 1324, 63, 1392, 12, 10627, 12, 3114, 9, 272, 1101, 275, 1101, 63, 3317, 18, 14, 2028, 8548, 8, 2180, 63, 1419, 29, 888, 63, 3317, 18, 14, 4578, 4558, 8, 267, 10736, 63, 1419, 29, 888, 63, 3317, 18, 14, 13946, 4558, 8, 288, 2450, 63, 1896, 29, 888, 63, 3317, 18, 14, 13946, 4558, 14, 44, 16, 1724, 272, 543, 2351, 63, 773, 14, 4434, 8, 2180, 29, 2180, 12, 1101, 29, 888, 9, 465, 2351, 26, 489, 2050, 14, 409, 63, 9833, 480, 815, 531, 489, 2860, 14, 2966, 63, 3669, 63, 6498, 1252, 1065, 342, 489, 26456, 275, 12338, 14, 26998, 18644, 342, 489, 26456, 14, 1065, 63, 411, 63, 11861, 8, 881, 2351, 12, 881, 4704, 12, 881, 333, 1533, 29, 1210, 63, 1392, 59, 16, 61, 627, 1324, 63, 1392, 59, 17, 61, 627, 841, 627, 499, 627, 2948, 1182, 413, 69, 22, 12, 881, 13751, 3126, 1598, 298, 1210, 63, 1392, 582, 1324, 63, 1392, 12, 1598, 298, 1975, 582, 1750, 12, 1598, 298, 3127, 582, 3114, 881, 3828, 819, 347, 12338, 63, 1294, 8, 277, 304, 272, 870, 480, 12984, 8118, 13388, 17159, 531, 272, 11751, 275, 3474, 8269, 12, 1695, 467, 359, 24, 12, 12293, 467, 359, 1960, 12, 6155, 467, 359, 5279, 12, 6155, 467, 359, 9943, 12, 6155, 467, 1598, 359, 1960, 12, 15997, 467, 359, 5279, 12, 15997, 467, 359, 9943, 12, 413, 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,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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 ]
lokeshjindal15/pd-gem5
src/mem/slicc/util.py
83
3124
# Copyright (c) 2009 The Hewlett-Packard Development Company # 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. import os import sys class PairContainer(object): def __init__(self, pairs=None): self.pairs = {} if pairs: self.pairs.update(pairs) def __contains__(self, item): return item in self.pairs def __getitem__(self, item): return self.pairs[item] def __setitem__(self, item, value): self.pairs[item] = value def get(self, item, failobj=None): return self.pairs.get(item, failobj) class Location(object): def __init__(self, filename, lineno, no_warning=False): if not isinstance(filename, basestring): raise AttributeError, \ "filename must be a string, found '%s'" % (type(filename), ) if not isinstance(lineno, (int, long)): raise AttributeError, \ "filename must be an integer, found '%s'" % (type(lineno), ) self.filename = filename self.lineno = lineno self.no_warning = no_warning def __str__(self): return '%s:%d' % (os.path.basename(self.filename), self.lineno) def warning(self, message, *args): if self.no_warning: return if args: message = message % args #raise Exception, "%s: Warning: %s" % (self, message) print >>sys.stderr, "%s: Warning: %s" % (self, message) def error(self, message, *args): if args: message = message % args raise Exception, "%s: Error: %s" % (self, message) sys.exit("\n%s: Error: %s" % (self, message)) __all__ = [ 'PairContainer', 'Location' ]
bsd-3-clause
[ 3, 1898, 334, 67, 9, 8937, 710, 27849, 13, 29471, 15290, 15878, 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, 199, 646, 747, 199, 646, 984, 199, 199, 533, 510, 8387, 4076, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 6342, 29, 403, 304, 267, 291, 14, 7322, 275, 1052, 267, 340, 6342, 26, 288, 291, 14, 7322, 14, 873, 8, 7322, 9, 339, 347, 636, 6134, 721, 277, 12, 1242, 304, 267, 372, 1242, 315, 291, 14, 7322, 339, 347, 636, 6095, 721, 277, 12, 1242, 304, 267, 372, 291, 14, 7322, 59, 1053, 61, 339, 347, 636, 8617, 721, 277, 12, 1242, 12, 574, 304, 267, 291, 14, 7322, 59, 1053, 61, 275, 574, 339, 347, 664, 8, 277, 12, 1242, 12, 1433, 11737, 468, 29, 403, 304, 267, 372, 291, 14, 7322, 14, 362, 8, 1053, 12, 1433, 11737, 468, 9, 199, 199, 533, 12625, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 1788, 12, 5874, 12, 949, 63, 3764, 29, 797, 304, 267, 340, 440, 1228, 8, 1501, 12, 7116, 304, 288, 746, 4281, 12, 971, 355, 298, 1501, 1471, 506, 282, 1059, 12, 1911, 1543, 83, 4065, 450, 334, 466, 8, 1501, 395, 776, 267, 340, 440, 1228, 8, 3469, 12, 334, 442, 12, 1846, 2298, 288, 746, 4281, 12, 971, 355, 298, 1501, 1471, 506, 376, 3000, 12, 1911, 1543, 83, 4065, 450, 334, 466, 8, 3469, 395, 776, 267, 291, 14, 1501, 275, 1788, 267, 291, 14, 3469, 275, 5874, 267, 291, 14, 889, 63, 3764, 275, 949, 63, 3764, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 2689, 68, 7, 450, 334, 736, 14, 515, 14, 4846, 8, 277, 14, 1501, 395, 291, 14, 3469, 9, 339, 347, 5721, 8, 277, 12, 1245, 12, 627, 589, 304, 267, 340, 291, 14, 889, 63, 3764, 26, 288, 372, 267, 340, 1249, 26, 288, 1245, 275, 1245, 450, 1249, 267, 327, 3730, 2186, 12, 2071, 83, 26, 15902, 26, 450, 83, 2, 450, 334, 277, 12, 1245, 9, 267, 870, 4331, 1274, 14, 3083, 12, 2071, 83, 26, 15902, 26, 450, 83, 2, 450, 334, 277, 12, 1245, 9, 339, 347, 1125, 8, 277, 12, 1245, 12, 627, 589, 304, 267, 340, 1249, 26, 288, 1245, 275, 1245, 450, 1249, 267, 746, 2186, 12, 2071, 83, 26, 4520, 26, 450, 83, 2, 450, 334, 277, 12, 1245, 9, 267, 984, 14, 2224, 4582, 78, 5, 83, 26, 4520, 26, 450, 83, 2, 450, 334, 277, 12, 1245, 430, 199, 199, 363, 452, 363, 275, 359, 283, 12882, 4076, 297, 283, 6592, 7, 1622, 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 ]
[ 1898, 334, 67, 9, 8937, 710, 27849, 13, 29471, 15290, 15878, 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, 199, 646, 747, 199, 646, 984, 199, 199, 533, 510, 8387, 4076, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 6342, 29, 403, 304, 267, 291, 14, 7322, 275, 1052, 267, 340, 6342, 26, 288, 291, 14, 7322, 14, 873, 8, 7322, 9, 339, 347, 636, 6134, 721, 277, 12, 1242, 304, 267, 372, 1242, 315, 291, 14, 7322, 339, 347, 636, 6095, 721, 277, 12, 1242, 304, 267, 372, 291, 14, 7322, 59, 1053, 61, 339, 347, 636, 8617, 721, 277, 12, 1242, 12, 574, 304, 267, 291, 14, 7322, 59, 1053, 61, 275, 574, 339, 347, 664, 8, 277, 12, 1242, 12, 1433, 11737, 468, 29, 403, 304, 267, 372, 291, 14, 7322, 14, 362, 8, 1053, 12, 1433, 11737, 468, 9, 199, 199, 533, 12625, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 1788, 12, 5874, 12, 949, 63, 3764, 29, 797, 304, 267, 340, 440, 1228, 8, 1501, 12, 7116, 304, 288, 746, 4281, 12, 971, 355, 298, 1501, 1471, 506, 282, 1059, 12, 1911, 1543, 83, 4065, 450, 334, 466, 8, 1501, 395, 776, 267, 340, 440, 1228, 8, 3469, 12, 334, 442, 12, 1846, 2298, 288, 746, 4281, 12, 971, 355, 298, 1501, 1471, 506, 376, 3000, 12, 1911, 1543, 83, 4065, 450, 334, 466, 8, 3469, 395, 776, 267, 291, 14, 1501, 275, 1788, 267, 291, 14, 3469, 275, 5874, 267, 291, 14, 889, 63, 3764, 275, 949, 63, 3764, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 2689, 68, 7, 450, 334, 736, 14, 515, 14, 4846, 8, 277, 14, 1501, 395, 291, 14, 3469, 9, 339, 347, 5721, 8, 277, 12, 1245, 12, 627, 589, 304, 267, 340, 291, 14, 889, 63, 3764, 26, 288, 372, 267, 340, 1249, 26, 288, 1245, 275, 1245, 450, 1249, 267, 327, 3730, 2186, 12, 2071, 83, 26, 15902, 26, 450, 83, 2, 450, 334, 277, 12, 1245, 9, 267, 870, 4331, 1274, 14, 3083, 12, 2071, 83, 26, 15902, 26, 450, 83, 2, 450, 334, 277, 12, 1245, 9, 339, 347, 1125, 8, 277, 12, 1245, 12, 627, 589, 304, 267, 340, 1249, 26, 288, 1245, 275, 1245, 450, 1249, 267, 746, 2186, 12, 2071, 83, 26, 4520, 26, 450, 83, 2, 450, 334, 277, 12, 1245, 9, 267, 984, 14, 2224, 4582, 78, 5, 83, 26, 4520, 26, 450, 83, 2, 450, 334, 277, 12, 1245, 430, 199, 199, 363, 452, 363, 275, 359, 283, 12882, 4076, 297, 283, 6592, 7, 1622, 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,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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
mateoqac/unqTip
language/vgbs/web/base.py
1
1839
"Base classes for services." import web import local def have_role(role_id): "Return True iff the currently logged user has the given role." user_id = local.session.user_id it = local.db.select('role_assignments', where='user_id=$user_id AND role_id=$role_id', vars=locals() ) try: record = it[0] return True except IndexError: return False def have_permissions_for(class_): if not local.session.get('logged_in', False): return False return have_role(class_.role_required) class NoLoginContent(object): "Content that requires not to be logged in." def GET(self, *args, **kwargs): if local.session.get('logged_in', False): raise web.seeother('/') else: return self.request(*args, **kwargs) def POST(self, *args, **kwargs): return self.GET(*args, **kwargs) class CheckRole(object): "Mixin to check that a user has a role." def check_role(self): role_required = getattr(self.__class__, 'role_required', None) if role_required is not None: if not have_permissions_for(self.__class__): raise notfound() class Content(CheckRole): "Content that requires login." def GET(self, *args, **kwargs): self.check_role() if local.session.get('logged_in', False): return self.request(*args, **kwargs) else: raise web.seeother('/login/add_service') def POST(self, *args, **kwargs): return self.GET(*args, **kwargs) class Action(CheckRole): "Action." def GET(self, *args, **kwargs): self.check_role() return self.request(*args, **kwargs) def POST(self, *args, **kwargs): self.check_role() return self.request(*args, **kwargs)
gpl-3.0
[ 2, 1563, 3992, 367, 8500, 2122, 199, 199, 646, 3330, 199, 199, 646, 2257, 199, 199, 318, 1172, 63, 3756, 8, 3756, 63, 344, 304, 272, 298, 1767, 715, 17963, 314, 5544, 10367, 922, 965, 314, 1627, 4719, 2122, 272, 922, 63, 344, 275, 2257, 14, 1730, 14, 751, 63, 344, 272, 652, 275, 2257, 14, 697, 14, 2416, 360, 3756, 63, 18922, 297, 1598, 2382, 534, 751, 63, 344, 28617, 751, 63, 344, 2401, 4719, 63, 344, 28617, 3756, 63, 344, 297, 1598, 6802, 29, 9350, 342, 272, 776, 272, 862, 26, 267, 2777, 275, 652, 59, 16, 61, 267, 372, 715, 272, 871, 7888, 26, 267, 372, 756, 199, 199, 318, 1172, 63, 6060, 63, 509, 8, 533, 7822, 272, 340, 440, 2257, 14, 1730, 14, 362, 360, 12419, 63, 262, 297, 756, 304, 267, 372, 756, 272, 372, 1172, 63, 3756, 8, 533, 3754, 3756, 63, 2427, 9, 199, 199, 533, 3091, 8880, 2714, 8, 785, 304, 272, 298, 2714, 626, 5074, 440, 370, 506, 10367, 315, 2122, 339, 347, 9576, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 340, 2257, 14, 1730, 14, 362, 360, 12419, 63, 262, 297, 756, 304, 288, 746, 3330, 14, 3239, 1848, 7825, 267, 587, 26, 288, 372, 291, 14, 1069, 2031, 589, 12, 1011, 958, 9, 339, 347, 8761, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 372, 291, 14, 2970, 2031, 589, 12, 1011, 958, 9, 199, 199, 533, 2670, 7422, 8, 785, 304, 272, 298, 4256, 370, 1104, 626, 282, 922, 965, 282, 4719, 2122, 339, 347, 1104, 63, 3756, 8, 277, 304, 267, 4719, 63, 2427, 275, 2519, 8, 277, 855, 533, 3108, 283, 3756, 63, 2427, 297, 488, 9, 267, 340, 4719, 63, 2427, 365, 440, 488, 26, 288, 340, 440, 1172, 63, 6060, 63, 509, 8, 277, 855, 533, 18580, 355, 746, 440, 4214, 342, 199, 199, 533, 6646, 8, 1799, 7422, 304, 272, 298, 2714, 626, 5074, 4676, 2122, 339, 347, 9576, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 1074, 63, 3756, 342, 267, 340, 2257, 14, 1730, 14, 362, 360, 12419, 63, 262, 297, 756, 304, 288, 372, 291, 14, 1069, 2031, 589, 12, 1011, 958, 9, 267, 587, 26, 288, 746, 3330, 14, 3239, 1848, 2336, 2886, 15, 525, 63, 1364, 358, 339, 347, 8761, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 372, 291, 14, 2970, 2031, 589, 12, 1011, 958, 9, 199, 199, 533, 10033, 8, 1799, 7422, 304, 272, 298, 3310, 2122, 339, 347, 9576, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 1074, 63, 3756, 342, 267, 372, 291, 14, 1069, 2031, 589, 12, 1011, 958, 9, 339, 347, 8761, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 1074, 63, 3756, 342, 267, 372, 291, 14, 1069, 2031, 589, 12, 1011, 958, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1563, 3992, 367, 8500, 2122, 199, 199, 646, 3330, 199, 199, 646, 2257, 199, 199, 318, 1172, 63, 3756, 8, 3756, 63, 344, 304, 272, 298, 1767, 715, 17963, 314, 5544, 10367, 922, 965, 314, 1627, 4719, 2122, 272, 922, 63, 344, 275, 2257, 14, 1730, 14, 751, 63, 344, 272, 652, 275, 2257, 14, 697, 14, 2416, 360, 3756, 63, 18922, 297, 1598, 2382, 534, 751, 63, 344, 28617, 751, 63, 344, 2401, 4719, 63, 344, 28617, 3756, 63, 344, 297, 1598, 6802, 29, 9350, 342, 272, 776, 272, 862, 26, 267, 2777, 275, 652, 59, 16, 61, 267, 372, 715, 272, 871, 7888, 26, 267, 372, 756, 199, 199, 318, 1172, 63, 6060, 63, 509, 8, 533, 7822, 272, 340, 440, 2257, 14, 1730, 14, 362, 360, 12419, 63, 262, 297, 756, 304, 267, 372, 756, 272, 372, 1172, 63, 3756, 8, 533, 3754, 3756, 63, 2427, 9, 199, 199, 533, 3091, 8880, 2714, 8, 785, 304, 272, 298, 2714, 626, 5074, 440, 370, 506, 10367, 315, 2122, 339, 347, 9576, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 340, 2257, 14, 1730, 14, 362, 360, 12419, 63, 262, 297, 756, 304, 288, 746, 3330, 14, 3239, 1848, 7825, 267, 587, 26, 288, 372, 291, 14, 1069, 2031, 589, 12, 1011, 958, 9, 339, 347, 8761, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 372, 291, 14, 2970, 2031, 589, 12, 1011, 958, 9, 199, 199, 533, 2670, 7422, 8, 785, 304, 272, 298, 4256, 370, 1104, 626, 282, 922, 965, 282, 4719, 2122, 339, 347, 1104, 63, 3756, 8, 277, 304, 267, 4719, 63, 2427, 275, 2519, 8, 277, 855, 533, 3108, 283, 3756, 63, 2427, 297, 488, 9, 267, 340, 4719, 63, 2427, 365, 440, 488, 26, 288, 340, 440, 1172, 63, 6060, 63, 509, 8, 277, 855, 533, 18580, 355, 746, 440, 4214, 342, 199, 199, 533, 6646, 8, 1799, 7422, 304, 272, 298, 2714, 626, 5074, 4676, 2122, 339, 347, 9576, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 1074, 63, 3756, 342, 267, 340, 2257, 14, 1730, 14, 362, 360, 12419, 63, 262, 297, 756, 304, 288, 372, 291, 14, 1069, 2031, 589, 12, 1011, 958, 9, 267, 587, 26, 288, 746, 3330, 14, 3239, 1848, 2336, 2886, 15, 525, 63, 1364, 358, 339, 347, 8761, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 372, 291, 14, 2970, 2031, 589, 12, 1011, 958, 9, 199, 199, 533, 10033, 8, 1799, 7422, 304, 272, 298, 3310, 2122, 339, 347, 9576, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 1074, 63, 3756, 342, 267, 372, 291, 14, 1069, 2031, 589, 12, 1011, 958, 9, 339, 347, 8761, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 1074, 63, 3756, 342, 267, 372, 291, 14, 1069, 2031, 589, 12, 1011, 958, 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, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 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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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
oasiswork/odoo
openerp/report/render/rml2txt/rml2txt.py
442
16460
#!/usr/bin/env python # -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009, P. Christeas, 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/>. # ############################################################################## import sys import StringIO from lxml import etree import utils Font_size= 10.0 def verbose(text): sys.stderr.write(text+"\n") class textbox(object): """A box containing plain text. It can have an offset, in chars. Lines can be either text strings, or textbox'es, recursively. """ def __init__(self,x=0, y=0): self.posx = x self.posy = y self.lines = [] self.curline = '' self.endspace = False def newline(self): if isinstance(self.curline, textbox): self.lines.extend(self.curline.renderlines()) else: self.lines.append(self.curline) self.curline = '' def fline(self): if isinstance(self.curline, textbox): self.lines.extend(self.curline.renderlines()) elif len(self.curline): self.lines.append(self.curline) self.curline = '' def appendtxt(self,txt): """Append some text to the current line. Mimic the HTML behaviour, where all whitespace evaluates to a single space """ if not txt: return bs = es = False if txt[0].isspace(): bs = True if txt[len(txt)-1].isspace(): es = True if bs and not self.endspace: self.curline += " " self.curline += txt.strip().replace("\n"," ").replace("\t"," ") if es: self.curline += " " self.endspace = es def rendertxt(self,xoffset=0): result = '' lineoff = "" for i in range(self.posy): result +="\n" for i in range(self.posx+xoffset): lineoff+=" " for l in self.lines: result+= lineoff+ l +"\n" return result def renderlines(self,pad=0): """Returns a list of lines, from the current object pad: all lines must be at least pad characters. """ result = [] lineoff = "" for i in range(self.posx): lineoff+=" " for l in self.lines: lpad = "" if pad and len(l) < pad : for i in range(pad - len(l)): lpad += " " #elif pad and len(l) > pad ? result.append(lineoff+ l+lpad) return result def haplines(self,arr,offset,cc= ''): """ Horizontaly append lines """ while len(self.lines) < len(arr): self.lines.append("") for i in range(len(self.lines)): while len(self.lines[i]) < offset: self.lines[i] += " " for i in range(len(arr)): self.lines[i] += cc +arr[i] class _flowable(object): def __init__(self, template, doc,localcontext): self._tags = { '1title': self._tag_title, '1spacer': self._tag_spacer, 'para': self._tag_para, 'font': self._tag_font, 'section': self._tag_section, '1nextFrame': self._tag_next_frame, 'blockTable': self._tag_table, '1pageBreak': self._tag_page_break, '1setNextTemplate': self._tag_next_template, } self.template = template self.doc = doc self.localcontext = localcontext self.nitags = [] self.tbox = None def warn_nitag(self,tag): if tag not in self.nitags: verbose("Unknown tag \"%s\", please implement it." % tag) self.nitags.append(tag) def _tag_page_break(self, node): return "\f" def _tag_next_template(self, node): return '' def _tag_next_frame(self, node): result=self.template.frame_stop() result+='\n' result+=self.template.frame_start() return result def _tag_title(self, node): node.tagName='h1' return node.toxml() def _tag_spacer(self, node): length = 1+int(utils.unit_get(node.get('length')))/35 return "\n"*length def _tag_table(self, node): self.tb.fline() saved_tb = self.tb self.tb = None sizes = None if node.get('colWidths'): sizes = map(lambda x: utils.unit_get(x), node.get('colWidths').split(',')) trs = [] for n in utils._child_get(node,self): if n.tag == 'tr': tds = [] for m in utils._child_get(n,self): if m.tag == 'td': self.tb = textbox() self.rec_render_cnodes(m) tds.append(self.tb) self.tb = None if len(tds): trs.append(tds) if not sizes: verbose("computing table sizes..") for tds in trs: trt = textbox() off=0 for i in range(len(tds)): p = int(sizes[i]/Font_size) trl = tds[i].renderlines(pad=p) trt.haplines(trl,off) off += sizes[i]/Font_size saved_tb.curline = trt saved_tb.fline() self.tb = saved_tb return def _tag_para(self, node): #TODO: styles self.rec_render_cnodes(node) self.tb.newline() def _tag_section(self, node): #TODO: styles self.rec_render_cnodes(node) self.tb.newline() def _tag_font(self, node): """We do ignore fonts..""" self.rec_render_cnodes(node) def rec_render_cnodes(self,node): self.tb.appendtxt(utils._process_text(self, node.text or '')) for n in utils._child_get(node,self): self.rec_render(n) self.tb.appendtxt(utils._process_text(self, node.tail or '')) def rec_render(self,node): """ Recursive render: fill outarr with text of current node """ if node.tag is not None: if node.tag in self._tags: self._tags[node.tag](node) else: self.warn_nitag(node.tag) def render(self, node): self.tb= textbox() #result = self.template.start() #result += self.template.frame_start() self.rec_render_cnodes(node) #result += self.template.frame_stop() #result += self.template.end() result = self.tb.rendertxt() del self.tb return result class _rml_tmpl_tag(object): def __init__(self, *args): pass def tag_start(self): return '' def tag_end(self): return False def tag_stop(self): return '' def tag_mergeable(self): return True class _rml_tmpl_frame(_rml_tmpl_tag): def __init__(self, posx, width): self.width = width self.posx = posx def tag_start(self): return "frame start" def tag_end(self): return True def tag_stop(self): return "frame stop" def tag_mergeable(self): return False # An awfull workaround since I don't really understand the semantic behind merge. def merge(self, frame): pass class _rml_tmpl_draw_string(_rml_tmpl_tag): def __init__(self, node, style): self.posx = utils.unit_get(node.get('x')) self.posy = utils.unit_get(node.get('y')) aligns = { 'drawString': 'left', 'drawRightString': 'right', 'drawCentredString': 'center' } align = aligns[node.localName] self.pos = [(self.posx, self.posy, align, utils.text_get(node), style.get('td'), style.font_size_get('td'))] def tag_start(self): return "draw string \"%s\" @(%d,%d)..\n" %("txt",self.posx,self.posy) def merge(self, ds): self.pos+=ds.pos class _rml_tmpl_draw_lines(_rml_tmpl_tag): def __init__(self, node, style): coord = [utils.unit_get(x) for x in utils.text_get(node).split(' ')] self.ok = False self.posx = coord[0] self.posy = coord[1] self.width = coord[2]-coord[0] self.ok = coord[1]==coord[3] self.style = style self.style = style.get('hr') def tag_start(self): return "draw lines..\n" class _rml_stylesheet(object): def __init__(self, stylesheet, doc): self.doc = doc self.attrs = {} self._tags = { 'fontSize': lambda x: ('font-size',str(utils.unit_get(x))+'px'), 'alignment': lambda x: ('text-align',str(x)) } result = '' for ps in stylesheet.findall('paraStyle'): attr = {} attrs = ps.attributes for i in range(attrs.length): name = attrs.item(i).localName attr[name] = ps.get(name) attrs = [] for a in attr: if a in self._tags: attrs.append("%s:%s" % self._tags[a](attr[a])) if len(attrs): result += "p."+attr['name']+" {"+'; '.join(attrs)+"}\n" self.result = result def render(self): return '' class _rml_draw_style(object): def __init__(self): self.style = {} self._styles = { 'fill': lambda x: {'td': {'color':x.get('color')}}, 'setFont': lambda x: {'td': {'font-size':x.get('size')+'px'}}, 'stroke': lambda x: {'hr': {'color':x.get('color')}}, } def update(self, node): if node.localName in self._styles: result = self._styles[node.localName](node) for key in result: if key in self.style: self.style[key].update(result[key]) else: self.style[key] = result[key] def font_size_get(self,tag): size = utils.unit_get(self.style.get('td', {}).get('font-size','16')) return size def get(self,tag): if not tag in self.style: return "" return ';'.join(['%s:%s' % (x[0],x[1]) for x in self.style[tag].items()]) class _rml_template(object): def __init__(self, localcontext, out, node, doc, images=None, path='.', title=None): self.localcontext = localcontext self.frame_pos = -1 self.frames = [] self.template_order = [] self.page_template = {} self.loop = 0 self._tags = { 'drawString': _rml_tmpl_draw_string, 'drawRightString': _rml_tmpl_draw_string, 'drawCentredString': _rml_tmpl_draw_string, 'lines': _rml_tmpl_draw_lines } self.style = _rml_draw_style() for pt in node.findall('pageTemplate'): frames = {} id = pt.get('id') self.template_order.append(id) for tmpl in pt.findall('frame'): posy = int(utils.unit_get(tmpl.get('y1'))) #+utils.unit_get(tmpl.get('height'))) posx = int(utils.unit_get(tmpl.get('x1'))) frames[(posy,posx,tmpl.get('id'))] = _rml_tmpl_frame(posx, utils.unit_get(tmpl.get('width'))) for tmpl in node.findall('pageGraphics'): for n in tmpl.getchildren(): if n.nodeType==n.ELEMENT_NODE: if n.localName in self._tags: t = self._tags[n.localName](n, self.style) frames[(t.posy,t.posx,n.localName)] = t else: self.style.update(n) keys = frames.keys() keys.sort() keys.reverse() self.page_template[id] = [] for key in range(len(keys)): if key>0 and keys[key-1][0] == keys[key][0]: if type(self.page_template[id][-1]) == type(frames[keys[key]]): if self.page_template[id][-1].tag_mergeable(): self.page_template[id][-1].merge(frames[keys[key]]) continue self.page_template[id].append(frames[keys[key]]) self.template = self.template_order[0] def _get_style(self): return self.style def set_next_template(self): self.template = self.template_order[(self.template_order.index(name)+1) % self.template_order] self.frame_pos = -1 def set_template(self, name): self.template = name self.frame_pos = -1 def frame_start(self): result = '' frames = self.page_template[self.template] ok = True while ok: self.frame_pos += 1 if self.frame_pos>=len(frames): self.frame_pos=0 self.loop=1 ok = False continue f = frames[self.frame_pos] result+=f.tag_start() ok = not f.tag_end() if ok: result+=f.tag_stop() return result def frame_stop(self): frames = self.page_template[self.template] f = frames[self.frame_pos] result=f.tag_stop() return result def start(self): return '' def end(self): return "template end\n" class _rml_doc(object): def __init__(self, node, localcontext=None, images=None, path='.', title=None): self.localcontext = {} if localcontext is None else localcontext self.etree = node self.filename = self.etree.get('filename') self.result = '' def render(self, out): #el = self.etree.findall('docinit') #if el: #self.docinit(el) #el = self.etree.findall('stylesheet') #self.styles = _rml_styles(el,self.localcontext) el = self.etree.findall('template') self.result ="" if len(el): pt_obj = _rml_template(self.localcontext, out, el[0], self) stories = utils._child_get(self.etree, self, 'story') for story in stories: if self.result: self.result += '\f' f = _flowable(pt_obj,story,self.localcontext) self.result += f.render(story) del f else: self.result = "<cannot render w/o template>" self.result += '\n' out.write( self.result) def parseNode(rml, localcontext=None,fout=None, images=None, path='.',title=None): node = etree.XML(rml) r = _rml_doc(node, localcontext, images, path, title=title) fp = StringIO.StringIO() r.render(fp) return fp.getvalue() def parseString(rml, localcontext=None,fout=None, images=None, path='.',title=None): node = etree.XML(rml) r = _rml_doc(node, localcontext, images, path, title=title) if fout: fp = file(fout,'wb') r.render(fp) fp.close() return fout else: fp = StringIO.StringIO() r.render(fp) return fp.getvalue() def trml2pdf_help(): print 'Usage: rml2txt input.rml >output.html' print 'Render the standard input (RML) and output an TXT file' sys.exit(0) if __name__=="__main__": if len(sys.argv)>1: if sys.argv[1]=='--help': trml2pdf_help() print parseString(file(sys.argv[1], 'r').read()).encode('iso8859-7') else: print 'Usage: trml2txt input.rml >output.pdf' print 'Try \'trml2txt --help\' for more information.' # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
agpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 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, 8664, 12, 510, 14, 2799, 322, 1597, 305, 12, 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, 646, 984, 199, 646, 5228, 199, 504, 14490, 492, 7559, 199, 199, 646, 3778, 199, 199, 6986, 63, 890, 29, 1616, 14, 16, 199, 199, 318, 3376, 8, 505, 304, 272, 984, 14, 3083, 14, 952, 8, 505, 25789, 78, 531, 421, 199, 533, 1318, 1977, 8, 785, 304, 272, 408, 33, 5689, 3035, 8971, 1318, 14, 272, 2779, 883, 1172, 376, 3268, 12, 315, 8365, 14, 272, 29406, 883, 506, 1902, 1318, 3326, 12, 503, 1318, 1977, 7, 397, 12, 15035, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 88, 29, 16, 12, 612, 29, 16, 304, 267, 291, 14, 32405, 275, 671, 267, 291, 14, 1712, 89, 275, 612, 267, 291, 14, 1278, 275, 942, 267, 291, 14, 895, 604, 275, 2125, 267, 291, 14, 500, 2638, 275, 756, 489, 272, 347, 8057, 8, 277, 304, 267, 340, 1228, 8, 277, 14, 895, 604, 12, 1318, 1977, 304, 288, 291, 14, 1278, 14, 2880, 8, 277, 14, 895, 604, 14, 3352, 1278, 1012, 267, 587, 26, 288, 291, 14, 1278, 14, 740, 8, 277, 14, 895, 604, 9, 267, 291, 14, 895, 604, 275, 2125, 2286, 347, 289, 604, 8, 277, 304, 267, 340, 1228, 8, 277, 14, 895, 604, 12, 1318, 1977, 304, 288, 291, 14, 1278, 14, 2880, 8, 277, 14, 895, 604, 14, 3352, 1278, 1012, 267, 916, 822, 8, 277, 14, 895, 604, 304, 288, 291, 14, 1278, 14, 740, 8, 277, 14, 895, 604, 9, 267, 291, 14, 895, 604, 275, 2125, 2286, 347, 5666, 2424, 8, 277, 12, 2424, 304, 267, 408, 8310, 2005, 1318, 370, 314, 1453, 1004, 14, 1779, 603, 1017, 530, 314, 4163, 13942, 12, 2382, 1006, 8139, 22014, 370, 1779, 282, 2849, 4601, 408, 267, 340, 440, 9444, 26, 288, 372, 267, 9922, 275, 9455, 275, 756, 267, 340, 9444, 59, 16, 1055, 23360, 837, 288, 9922, 275, 715, 267, 340, 9444, 59, 552, 8, 2424, 7216, 17, 1055, 23360, 837, 288, 9455, 275, 715, 267, 340, 9922, 436, 440, 291, 14, 500, 2638, 26, 288, 291, 14, 895, 604, 847, 298, 298, 267, 291, 14, 895, 604, 847, 9444, 14, 1913, 1252, 1814, 4582, 78, 2266, 298, 680, 1814, 4582, 84, 2266, 6099, 267, 340, 9455, 26, 288, 291, 14, 895, 604, 847, 298, 298, 267, 291, 14, 500, 2638, 275, 9455, 339, 347, 3795, 2424, 8, 277, 12, 88, 2743, 29, 16, 304, 267, 754, 275, 2125, 267, 1004, 1997, 275, 3087, 267, 367, 284, 315, 1425, 8, 277, 14, 1712, 89, 304, 288, 754, 435, 21024, 78, 2, 267, 367, 284, 315, 1425, 8, 277, 14, 32405, 11, 88, 2743, 304, 288, 1004, 1997, 11, 628, 298, 267, 367, 634, 315, 291, 14, 1278, 26, 288, 754, 10365, 1004, 1997, 11, 634, 435, 3212, 78, 2, 267, 372, 754, 2286, 347, 3795, 1278, 8, 277, 12, 6226, 29, 16, 304, 267, 408, 3407, 282, 769, 402, 2385, 12, 687, 314, 1453, 909, 267, 6567, 26, 1006, 2385, 1471, 506, 737, 5210, 6567, 4110, 14, 267, 408, 267, 754, 275, 942, 267, 1004, 1997, 275, 3087, 267, 367, 284, 315, 1425, 8, 277, 14, 32405, 304, 288, 1004, 1997, 11, 628, 298, 267, 367, 634, 315, 291, 14, 1278, 26, 288, 634, 6226, 275, 3087, 288, 340, 6567, 436, 822, 8, 76, 9, 665, 6567, 520, 355, 367, 284, 315, 1425, 8, 6226, 446, 822, 8, 76, 2298, 490, 634, 6226, 847, 298, 298, 355, 327, 4164, 6567, 436, 822, 8, 76, 9, 690, 6567, 5805, 355, 754, 14, 740, 8, 604, 1997, 11, 634, 11, 76, 6226, 9, 267, 372, 754, 1467, 15567, 347, 394, 439, 1278, 8, 277, 12, 5250, 12, 2743, 12, 2055, 29, 21019, 267, 408, 869, 7366, 2618, 5666, 2385, 4960, 408, 267, 1830, 822, 8, 277, 14, 1278, 9, 665, 822, 8, 5250, 304, 288, 291, 14, 1278, 14, 740, 10804, 2728, 367, 284, 315, 1425, 8, 552, 8, 277, 14, 1278, 2298, 288, 1830, 822, 8, 277, 14, 1278, 59, 73, 566, 665, 3268, 26, 355, 291, 14, 1278, 59, 73, 61, 847, 298, 298, 267, 367, 284, 315, 1425, 8, 552, 8, 5250, 2298, 288, 291, 14, 1278, 59, 73, 61, 847, 7429, 435, 5250, 59, 73, 61, 221, 27844, 199, 533, 485, 1659, 461, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 1978, 12, 1382, 12, 17886, 304, 267, 291, 423, 2969, 275, 469, 288, 283, 17, 1213, 356, 291, 423, 1450, 63, 1213, 12, 288, 283, 17, 3770, 2247, 356, 291, 423, 1450, 63, 3770, 2247, 12, 288, 283, 12227, 356, 291, 423, 1450, 63, 12227, 12, 288, 283, 4246, 356, 291, 423, 1450, 63, 4246, 12, 288, 283, 2792, 356, 291, 423, 1450, 63, 2792, 12, 288, 283, 17, 2184, 3160, 356, 291, 423, 1450, 63, 2184 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 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, 8664, 12, 510, 14, 2799, 322, 1597, 305, 12, 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, 646, 984, 199, 646, 5228, 199, 504, 14490, 492, 7559, 199, 199, 646, 3778, 199, 199, 6986, 63, 890, 29, 1616, 14, 16, 199, 199, 318, 3376, 8, 505, 304, 272, 984, 14, 3083, 14, 952, 8, 505, 25789, 78, 531, 421, 199, 533, 1318, 1977, 8, 785, 304, 272, 408, 33, 5689, 3035, 8971, 1318, 14, 272, 2779, 883, 1172, 376, 3268, 12, 315, 8365, 14, 272, 29406, 883, 506, 1902, 1318, 3326, 12, 503, 1318, 1977, 7, 397, 12, 15035, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 88, 29, 16, 12, 612, 29, 16, 304, 267, 291, 14, 32405, 275, 671, 267, 291, 14, 1712, 89, 275, 612, 267, 291, 14, 1278, 275, 942, 267, 291, 14, 895, 604, 275, 2125, 267, 291, 14, 500, 2638, 275, 756, 489, 272, 347, 8057, 8, 277, 304, 267, 340, 1228, 8, 277, 14, 895, 604, 12, 1318, 1977, 304, 288, 291, 14, 1278, 14, 2880, 8, 277, 14, 895, 604, 14, 3352, 1278, 1012, 267, 587, 26, 288, 291, 14, 1278, 14, 740, 8, 277, 14, 895, 604, 9, 267, 291, 14, 895, 604, 275, 2125, 2286, 347, 289, 604, 8, 277, 304, 267, 340, 1228, 8, 277, 14, 895, 604, 12, 1318, 1977, 304, 288, 291, 14, 1278, 14, 2880, 8, 277, 14, 895, 604, 14, 3352, 1278, 1012, 267, 916, 822, 8, 277, 14, 895, 604, 304, 288, 291, 14, 1278, 14, 740, 8, 277, 14, 895, 604, 9, 267, 291, 14, 895, 604, 275, 2125, 2286, 347, 5666, 2424, 8, 277, 12, 2424, 304, 267, 408, 8310, 2005, 1318, 370, 314, 1453, 1004, 14, 1779, 603, 1017, 530, 314, 4163, 13942, 12, 2382, 1006, 8139, 22014, 370, 1779, 282, 2849, 4601, 408, 267, 340, 440, 9444, 26, 288, 372, 267, 9922, 275, 9455, 275, 756, 267, 340, 9444, 59, 16, 1055, 23360, 837, 288, 9922, 275, 715, 267, 340, 9444, 59, 552, 8, 2424, 7216, 17, 1055, 23360, 837, 288, 9455, 275, 715, 267, 340, 9922, 436, 440, 291, 14, 500, 2638, 26, 288, 291, 14, 895, 604, 847, 298, 298, 267, 291, 14, 895, 604, 847, 9444, 14, 1913, 1252, 1814, 4582, 78, 2266, 298, 680, 1814, 4582, 84, 2266, 6099, 267, 340, 9455, 26, 288, 291, 14, 895, 604, 847, 298, 298, 267, 291, 14, 500, 2638, 275, 9455, 339, 347, 3795, 2424, 8, 277, 12, 88, 2743, 29, 16, 304, 267, 754, 275, 2125, 267, 1004, 1997, 275, 3087, 267, 367, 284, 315, 1425, 8, 277, 14, 1712, 89, 304, 288, 754, 435, 21024, 78, 2, 267, 367, 284, 315, 1425, 8, 277, 14, 32405, 11, 88, 2743, 304, 288, 1004, 1997, 11, 628, 298, 267, 367, 634, 315, 291, 14, 1278, 26, 288, 754, 10365, 1004, 1997, 11, 634, 435, 3212, 78, 2, 267, 372, 754, 2286, 347, 3795, 1278, 8, 277, 12, 6226, 29, 16, 304, 267, 408, 3407, 282, 769, 402, 2385, 12, 687, 314, 1453, 909, 267, 6567, 26, 1006, 2385, 1471, 506, 737, 5210, 6567, 4110, 14, 267, 408, 267, 754, 275, 942, 267, 1004, 1997, 275, 3087, 267, 367, 284, 315, 1425, 8, 277, 14, 32405, 304, 288, 1004, 1997, 11, 628, 298, 267, 367, 634, 315, 291, 14, 1278, 26, 288, 634, 6226, 275, 3087, 288, 340, 6567, 436, 822, 8, 76, 9, 665, 6567, 520, 355, 367, 284, 315, 1425, 8, 6226, 446, 822, 8, 76, 2298, 490, 634, 6226, 847, 298, 298, 355, 327, 4164, 6567, 436, 822, 8, 76, 9, 690, 6567, 5805, 355, 754, 14, 740, 8, 604, 1997, 11, 634, 11, 76, 6226, 9, 267, 372, 754, 1467, 15567, 347, 394, 439, 1278, 8, 277, 12, 5250, 12, 2743, 12, 2055, 29, 21019, 267, 408, 869, 7366, 2618, 5666, 2385, 4960, 408, 267, 1830, 822, 8, 277, 14, 1278, 9, 665, 822, 8, 5250, 304, 288, 291, 14, 1278, 14, 740, 10804, 2728, 367, 284, 315, 1425, 8, 552, 8, 277, 14, 1278, 2298, 288, 1830, 822, 8, 277, 14, 1278, 59, 73, 566, 665, 3268, 26, 355, 291, 14, 1278, 59, 73, 61, 847, 298, 298, 267, 367, 284, 315, 1425, 8, 552, 8, 5250, 2298, 288, 291, 14, 1278, 59, 73, 61, 847, 7429, 435, 5250, 59, 73, 61, 221, 27844, 199, 533, 485, 1659, 461, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 1978, 12, 1382, 12, 17886, 304, 267, 291, 423, 2969, 275, 469, 288, 283, 17, 1213, 356, 291, 423, 1450, 63, 1213, 12, 288, 283, 17, 3770, 2247, 356, 291, 423, 1450, 63, 3770, 2247, 12, 288, 283, 12227, 356, 291, 423, 1450, 63, 12227, 12, 288, 283, 4246, 356, 291, 423, 1450, 63, 4246, 12, 288, 283, 2792, 356, 291, 423, 1450, 63, 2792, 12, 288, 283, 17, 2184, 3160, 356, 291, 423, 1450, 63, 2184, 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 ]
whosonfirst/whosonfirst-www-boundaryissues
services/geojson-server/wof-geojson-server.py
1
7923
#!/usr/bin/env python import StringIO import sys import logging import os import re import flask from flask import Flask, request, jsonify import geojson import requests import json import mapzen.whosonfirst.geojson import mapzen.whosonfirst.export import mapzen.whosonfirst.search import mapzen.whosonfirst.utils import mapzen.whosonfirst.placetypes import mapzen.whosonfirst.hierarchy import mapzen.whosonfirst.spatial.whosonfirst app = Flask(__name__) app.config['MAX_CONTENT_LENGTH'] = 116 * 1024 * 1024 @app.before_request def init(): flask.g.wof_pending_dir = os.environ.get('WOF_PENDING_DIR', '/usr/local/data/whosonfirst-pending/') flask.g.geojson_encoder = mapzen.whosonfirst.geojson.encoder(precision=None) flask.g.mapzen_api_key = os.environ.get('MAPZEN_API_KEY', '') flask.g.places_api_endpoint = 'https://places.mapzen.com/v1' flask.g.api_client = mapzen.whosonfirst.spatial.whosonfirst.api(api_key=flask.g.mapzen_api_key, endpoint=flask.g.places_api_endpoint) flask.g.hierarchy_ancs = mapzen.whosonfirst.hierarchy.ancestors(spatial_client=flask.g.api_client) @app.route('/encode', methods=['POST']) def geojson_encode(): try: g = request.form['geojson'] f = geojson.loads(g) except Exception, e: error = "failed to load geojson, because %s" % e logging.error(error) return jsonify(ok=0, error=error) if (f.is_valid == False): error = "GeoJSON doesn't validate: %s" % f.errors() logging.error(error) return jsonify(ok=0, error=error) e = flask.g.geojson_encoder try: fh = StringIO.StringIO() e.encode_feature(f, fh) except Exception, e: error = "failed to encode geojson, because %s" % e logging.error(error) return jsonify(ok=0, error=error) fh.seek(0) encoded = fh.read() return jsonify(ok=1, encoded=encoded) @app.route('/save', methods=['POST']) def geojson_save(): # THIS IS PART 6 (six) OF THE #datavoyage # Search the codebase for #datavoyage to follow along at home. # (20171121/dphiffer) try: g = request.form['geojson'] branch = request.form['branch'] # Another #datavoyage JSON parsing event! Exciting. f = geojson.loads(g) except Exception, e: err = "failed to load geojson, because %s" % e return jsonify(ok=0, error=err) p = re.compile('^[a-zA-Z0-9-_]+$') if not p.match(branch): return jsonify(ok=0, error='Invalid branch name: %s' % branch) if (f.is_valid == False): error = "GeoJSON doesn't validate: %s" % f.errors() logging.error(error) return jsonify(ok=0, error=error) try: data_dir = "%s%s/data" % (flask.g.wof_pending_dir, branch) if not os.path.exists(data_dir): os.makedirs(data_dir, 0775) # An exciting moment, #datavoyage friends, we are writing to disk! ff = mapzen.whosonfirst.export.flatfile(data_dir, debug=False) path = ff.export_feature(f) except Exception, e: error = "failed to export geojson, because %s" % e logging.error(error) return jsonify(ok=0, error=error) if not path: return jsonify(ok=0, error="File export returned an empty path, maybe check file permissions?") # Repeat back the file we just wrote try: gf = open(path, 'r') exported = gf.read() except Exception, e: error = "failed to read exported geojson, because %s" % e logging.error(error) return jsonify(ok=0, error=error) # THIS IS PART 7 (seven) OF THE #datavoyage # Search the codebase for #datavoyage to follow along at home. # And... we are headed back to the front-end! # It's been quite a #datavoyage... (20171121/dphiffer) return jsonify(ok=1, geojson=exported, path=path) @app.route('/pip', methods=['POST']) def geojson_pip(): try: g = request.form['geojson'] feature = geojson.loads(g) except Exception, e: err = "failed to load geojson, because %s" % e return jsonify(ok=0, error=err) props = feature["properties"] geom = feature["geometry"] placetype = props["wof:placetype"] lat = geom["coordinates"][1] lng = geom["coordinates"][0] if (mapzen.whosonfirst.placetypes.is_valid_placetype(placetype) == False): return jsonify(ok=0, error="What is that placetype?") if not "wof:id" in props: props["wof:id"] = -1 try: flask.g.hierarchy_ancs.rebuild_feature(feature) except Exception, e: error = "failed to determine hierarchy, because %s" % e logging.error(error) return jsonify(ok=0, error=error) hierarchy = feature["properties"]["wof:hierarchy"] parent_id = feature["properties"]["wof:parent_id"] for h in hierarchy: if "venue_id" in h and h["venue_id"] == -1: del h["venue_id"] pt = mapzen.whosonfirst.placetypes.placetype(placetype) parents = [] for p in pt.parents(): # These won't pip correctly, so just skip em if str(p) in ("building", "address"): continue filters = { "wof:placetype_id": p.id() } kwargs = { "filters": filters, "extras": "wof:superseded_by,edtf:deprecated" } for r in flask.g.api_client.point_in_polygon(lat, lng, **kwargs): # see this - it's not a feature... it should be a thing you # specify in filters and have the spatial client take care # of for you but it's currently blocked on this: # https://github.com/whosonfirst/go-whosonfirst-pip/issues/32 if r['edtf:deprecated'] != "" and r['edtf:deprecated'] != 'uuuu': continue if len(r['wof:superseded_by']) > 0: continue parents.append(r) if len(parents): break return jsonify(ok=1, hierarchy=hierarchy, parents=parents, parent_id=parent_id) @app.route('/nearby', methods=['GET']) def geojson_nearby(): api_key = flask.g.mapzen_api_key lat = float(request.args.get('latitude')) lng = float(request.args.get('longitude')) name = request.args.get('name') results = [] result_ids = [] method = 'whosonfirst.places.getByLatLon' params = { 'api_key': api_key, 'method': method, 'latitude': lat, 'longitude': lng, 'placetype': 'neighbourhood' } extras = 'addr:full,wof:tags' rsp = requests.get(flask.g.places_api_endpoint, params=params) data = json.loads(rsp.content) if (data['places'] and len(data['places']) > 0): for neighbourhood in data['places']: wofid = neighbourhood['wof:id'] method = 'whosonfirst.places.search' params = { 'api_key': api_key, 'method': method, 'neighbourhood_id': wofid, 'names': name, 'extras': extras, 'placetype': 'venue' } rsp = requests.get(flask.g.places_api_endpoint, params=params) data = json.loads(rsp.content) if data['places']: for pl in data['places']: if pl['wof:id'] not in result_ids: result_ids.append(pl['wof:id']) results.append(pl) method = "whosonfirst.places.getNearby" params = { 'api_key': api_key, 'method': method, 'latitude': lat, 'longitude': lng, 'placetype': 'venue', 'radius': 100, 'extras': extras } rsp = requests.get(flask.g.places_api_endpoint, params=params) print rsp.content data = json.loads(rsp.content) if (data['places'] and len(data['places']) > 0): for pl in data['places']: if pl['wof:id'] not in result_ids: result_ids.append(pl['wof:id']) results.append(pl) return jsonify(ok=1, results=results) if __name__ == "__main__": import sys import optparse import ConfigParser opt_parser = optparse.OptionParser() opt_parser.add_option('-p', '--port', dest='port', action='store', default=8181, help='') opt_parser.add_option('-d', '--dir', dest='dir', action='store', default='/usr/local/mapzen/whosonfirst-www-boundaryissues/pending/', help='wof_pending_dir') opt_parser.add_option('-k', '--api-key', dest='api_key', action='store', default='', help='mapzen_api_key') opt_parser.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False, help='Be chatty (default is false)') options, args = opt_parser.parse_args() if options.verbose: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) os.environ['WOF_PENDING_DIR'] = options.dir os.environ['MAPZEN_API_KEY'] = options.api_key port = int(options.port) app.run(port=port)
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 646, 5228, 199, 646, 984, 199, 646, 2050, 199, 646, 747, 199, 646, 295, 199, 646, 7209, 199, 504, 7209, 492, 16704, 12, 1056, 12, 23819, 199, 199, 646, 8509, 1001, 199, 646, 4145, 199, 646, 2022, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 27043, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 3790, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 1733, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 1208, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 2778, 1313, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 14861, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 11679, 14, 11345, 834, 2246, 199, 199, 571, 275, 16704, 3460, 354, 3368, 199, 571, 14, 888, 459, 4283, 63, 9663, 63, 9127, 418, 275, 25186, 627, 6619, 627, 6619, 199, 199, 32, 571, 14, 5182, 63, 1069, 199, 318, 4205, 837, 199, 198, 15720, 14, 71, 14, 87, 1618, 63, 6455, 63, 694, 275, 747, 14, 2314, 14, 362, 360, 55, 3359, 63, 21243, 63, 3022, 297, 1994, 2647, 15, 1832, 15, 576, 15, 11345, 834, 2246, 13, 6455, 6217, 199, 198, 15720, 14, 71, 14, 27043, 63, 9347, 275, 2341, 5193, 14, 11345, 834, 2246, 14, 27043, 14, 9347, 8, 6833, 29, 403, 9, 421, 198, 15720, 14, 71, 14, 1130, 5193, 63, 1246, 63, 498, 275, 747, 14, 2314, 14, 362, 360, 5443, 58, 742, 63, 3735, 63, 3078, 297, 4074, 199, 198, 15720, 14, 71, 14, 10696, 63, 1246, 63, 6520, 275, 283, 2859, 921, 10696, 14, 1130, 5193, 14, 957, 15, 86, 17, 7, 199, 198, 15720, 14, 71, 14, 1246, 63, 1258, 275, 2341, 5193, 14, 11345, 834, 2246, 14, 11679, 14, 11345, 834, 2246, 14, 1246, 8, 1246, 63, 498, 29, 15720, 14, 71, 14, 1130, 5193, 63, 1246, 63, 498, 12, 6037, 29, 15720, 14, 71, 14, 10696, 63, 1246, 63, 6520, 9, 199, 198, 15720, 14, 71, 14, 14861, 63, 290, 1259, 275, 2341, 5193, 14, 11345, 834, 2246, 14, 14861, 14, 23732, 8, 11679, 63, 1258, 29, 15720, 14, 71, 14, 1246, 63, 1258, 9, 199, 199, 32, 571, 14, 4449, 2336, 2143, 297, 3102, 2968, 4030, 1105, 199, 318, 8509, 1001, 63, 2143, 837, 421, 198, 893, 26, 507, 198, 71, 275, 1056, 14, 964, 459, 27043, 418, 507, 198, 70, 275, 8509, 1001, 14, 3640, 8, 71, 9, 199, 198, 2590, 2186, 12, 325, 26, 507, 198, 705, 275, 298, 4892, 370, 2248, 8509, 1001, 12, 2952, 450, 83, 2, 450, 325, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 705, 9, 421, 198, 692, 334, 70, 14, 374, 63, 1078, 508, 756, 304, 507, 198, 705, 275, 298, 10748, 6243, 3181, 1133, 4107, 26, 450, 83, 2, 450, 289, 14, 2550, 342, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 705, 9, 421, 198, 69, 275, 7209, 14, 71, 14, 27043, 63, 9347, 421, 198, 893, 26, 507, 198, 12853, 275, 5228, 14, 6424, 342, 507, 198, 69, 14, 2143, 63, 4445, 8, 70, 12, 11155, 9, 199, 198, 2590, 2186, 12, 325, 26, 507, 198, 705, 275, 298, 4892, 370, 3752, 8509, 1001, 12, 2952, 450, 83, 2, 450, 325, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 705, 9, 421, 198, 12853, 14, 5507, 8, 16, 9, 199, 198, 8167, 275, 11155, 14, 739, 342, 421, 198, 1107, 23819, 8, 745, 29, 17, 12, 5737, 29, 8167, 9, 199, 199, 32, 571, 14, 4449, 2336, 2117, 297, 3102, 2968, 4030, 1105, 199, 318, 8509, 1001, 63, 2117, 837, 421, 198, 3, 5749, 2281, 3076, 1227, 334, 4174, 9, 1634, 2334, 327, 576, 2392, 89, 474, 199, 198, 3, 8730, 314, 1233, 1095, 367, 327, 576, 2392, 89, 474, 370, 2035, 3180, 737, 5629, 14, 199, 198, 3, 334, 1797, 3172, 10753, 15, 68, 10909, 1260, 9, 199, 198, 893, 26, 507, 198, 71, 275, 1056, 14, 964, 459, 27043, 418, 507, 198, 4694, 275, 1056, 14, 964, 459, 4694, 418, 2742, 198, 3, 22604, 327, 576, 2392, 89, 474, 4840, 6057, 1566, 1, 1316, 14422, 316, 14, 507, 198, 70, 275, 8509, 1001, 14, 3640, 8, 71, 9, 421, 198, 2590, 2186, 12, 325, 26, 507, 198, 1508, 275, 298, 4892, 370, 2248, 8509, 1001, 12, 2952, 450, 83, 2, 450, 325, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 1508, 9, 421, 198, 80, 275, 295, 14, 2014, 9097, 59, 65, 13, 6353, 13, 58, 16, 13, 25, 13, 22155, 9988, 199, 198, 692, 440, 299, 14, 1431, 8, 4694, 304, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 534, 3364, 5246, 536, 26, 450, 83, 7, 450, 5246, 9, 421, 198, 692, 334, 70, 14, 374, 63, 1078, 508, 756, 304, 507, 198, 705, 275, 298, 10748, 6243, 3181, 1133, 4107, 26, 450, 83, 2, 450, 289, 14, 2550, 342, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 705, 9, 421, 198, 893, 26, 507, 198, 576, 63, 694, 275, 2071, 83, 5, 83, 15, 576, 2, 450, 334, 15720, 14, 71, 14, 87, 1618, 63, 6455, 63, 694, 12, 5246, 9, 507, 198, 692, 440, 747, 14, 515, 14, 2444, 8, 576, 63, 694, 304, 686, 198, 736, 14, 8347, 8, 576, 63, 694, 12, 378, 12710, 9, 2742, 198, 3, 1626, 3178, 390, 316, 12427, 12, 327, 576, 2392, 89, 474, 26157, 12, 781, 787, 3575, 370, 4543, 1, 507, 198, 556, 275, 2341, 5193, 14, 11345, 834, 2246, 14, 3790, 14, 7088, 493, 8, 576, 63, 694, 12, 3105, 29, 797, 9, 507, 198, 515, 275, 16328, 14, 3790, 63, 4445, 8, 70, 9, 199, 198, 2590, 2186, 12, 325, 26, 507, 198, 705, 275, 298, 4892, 370, 4843, 8509, 1001, 12, 2952, 450, 83, 2, 450, 325, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 646, 5228, 199, 646, 984, 199, 646, 2050, 199, 646, 747, 199, 646, 295, 199, 646, 7209, 199, 504, 7209, 492, 16704, 12, 1056, 12, 23819, 199, 199, 646, 8509, 1001, 199, 646, 4145, 199, 646, 2022, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 27043, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 3790, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 1733, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 1208, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 2778, 1313, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 14861, 199, 646, 2341, 5193, 14, 11345, 834, 2246, 14, 11679, 14, 11345, 834, 2246, 199, 199, 571, 275, 16704, 3460, 354, 3368, 199, 571, 14, 888, 459, 4283, 63, 9663, 63, 9127, 418, 275, 25186, 627, 6619, 627, 6619, 199, 199, 32, 571, 14, 5182, 63, 1069, 199, 318, 4205, 837, 199, 198, 15720, 14, 71, 14, 87, 1618, 63, 6455, 63, 694, 275, 747, 14, 2314, 14, 362, 360, 55, 3359, 63, 21243, 63, 3022, 297, 1994, 2647, 15, 1832, 15, 576, 15, 11345, 834, 2246, 13, 6455, 6217, 199, 198, 15720, 14, 71, 14, 27043, 63, 9347, 275, 2341, 5193, 14, 11345, 834, 2246, 14, 27043, 14, 9347, 8, 6833, 29, 403, 9, 421, 198, 15720, 14, 71, 14, 1130, 5193, 63, 1246, 63, 498, 275, 747, 14, 2314, 14, 362, 360, 5443, 58, 742, 63, 3735, 63, 3078, 297, 4074, 199, 198, 15720, 14, 71, 14, 10696, 63, 1246, 63, 6520, 275, 283, 2859, 921, 10696, 14, 1130, 5193, 14, 957, 15, 86, 17, 7, 199, 198, 15720, 14, 71, 14, 1246, 63, 1258, 275, 2341, 5193, 14, 11345, 834, 2246, 14, 11679, 14, 11345, 834, 2246, 14, 1246, 8, 1246, 63, 498, 29, 15720, 14, 71, 14, 1130, 5193, 63, 1246, 63, 498, 12, 6037, 29, 15720, 14, 71, 14, 10696, 63, 1246, 63, 6520, 9, 199, 198, 15720, 14, 71, 14, 14861, 63, 290, 1259, 275, 2341, 5193, 14, 11345, 834, 2246, 14, 14861, 14, 23732, 8, 11679, 63, 1258, 29, 15720, 14, 71, 14, 1246, 63, 1258, 9, 199, 199, 32, 571, 14, 4449, 2336, 2143, 297, 3102, 2968, 4030, 1105, 199, 318, 8509, 1001, 63, 2143, 837, 421, 198, 893, 26, 507, 198, 71, 275, 1056, 14, 964, 459, 27043, 418, 507, 198, 70, 275, 8509, 1001, 14, 3640, 8, 71, 9, 199, 198, 2590, 2186, 12, 325, 26, 507, 198, 705, 275, 298, 4892, 370, 2248, 8509, 1001, 12, 2952, 450, 83, 2, 450, 325, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 705, 9, 421, 198, 692, 334, 70, 14, 374, 63, 1078, 508, 756, 304, 507, 198, 705, 275, 298, 10748, 6243, 3181, 1133, 4107, 26, 450, 83, 2, 450, 289, 14, 2550, 342, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 705, 9, 421, 198, 69, 275, 7209, 14, 71, 14, 27043, 63, 9347, 421, 198, 893, 26, 507, 198, 12853, 275, 5228, 14, 6424, 342, 507, 198, 69, 14, 2143, 63, 4445, 8, 70, 12, 11155, 9, 199, 198, 2590, 2186, 12, 325, 26, 507, 198, 705, 275, 298, 4892, 370, 3752, 8509, 1001, 12, 2952, 450, 83, 2, 450, 325, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 705, 9, 421, 198, 12853, 14, 5507, 8, 16, 9, 199, 198, 8167, 275, 11155, 14, 739, 342, 421, 198, 1107, 23819, 8, 745, 29, 17, 12, 5737, 29, 8167, 9, 199, 199, 32, 571, 14, 4449, 2336, 2117, 297, 3102, 2968, 4030, 1105, 199, 318, 8509, 1001, 63, 2117, 837, 421, 198, 3, 5749, 2281, 3076, 1227, 334, 4174, 9, 1634, 2334, 327, 576, 2392, 89, 474, 199, 198, 3, 8730, 314, 1233, 1095, 367, 327, 576, 2392, 89, 474, 370, 2035, 3180, 737, 5629, 14, 199, 198, 3, 334, 1797, 3172, 10753, 15, 68, 10909, 1260, 9, 199, 198, 893, 26, 507, 198, 71, 275, 1056, 14, 964, 459, 27043, 418, 507, 198, 4694, 275, 1056, 14, 964, 459, 4694, 418, 2742, 198, 3, 22604, 327, 576, 2392, 89, 474, 4840, 6057, 1566, 1, 1316, 14422, 316, 14, 507, 198, 70, 275, 8509, 1001, 14, 3640, 8, 71, 9, 421, 198, 2590, 2186, 12, 325, 26, 507, 198, 1508, 275, 298, 4892, 370, 2248, 8509, 1001, 12, 2952, 450, 83, 2, 450, 325, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 1508, 9, 421, 198, 80, 275, 295, 14, 2014, 9097, 59, 65, 13, 6353, 13, 58, 16, 13, 25, 13, 22155, 9988, 199, 198, 692, 440, 299, 14, 1431, 8, 4694, 304, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 534, 3364, 5246, 536, 26, 450, 83, 7, 450, 5246, 9, 421, 198, 692, 334, 70, 14, 374, 63, 1078, 508, 756, 304, 507, 198, 705, 275, 298, 10748, 6243, 3181, 1133, 4107, 26, 450, 83, 2, 450, 289, 14, 2550, 342, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107, 23819, 8, 745, 29, 16, 12, 1125, 29, 705, 9, 421, 198, 893, 26, 507, 198, 576, 63, 694, 275, 2071, 83, 5, 83, 15, 576, 2, 450, 334, 15720, 14, 71, 14, 87, 1618, 63, 6455, 63, 694, 12, 5246, 9, 507, 198, 692, 440, 747, 14, 515, 14, 2444, 8, 576, 63, 694, 304, 686, 198, 736, 14, 8347, 8, 576, 63, 694, 12, 378, 12710, 9, 2742, 198, 3, 1626, 3178, 390, 316, 12427, 12, 327, 576, 2392, 89, 474, 26157, 12, 781, 787, 3575, 370, 4543, 1, 507, 198, 556, 275, 2341, 5193, 14, 11345, 834, 2246, 14, 3790, 14, 7088, 493, 8, 576, 63, 694, 12, 3105, 29, 797, 9, 507, 198, 515, 275, 16328, 14, 3790, 63, 4445, 8, 70, 9, 199, 198, 2590, 2186, 12, 325, 26, 507, 198, 705, 275, 298, 4892, 370, 4843, 8509, 1001, 12, 2952, 450, 83, 2, 450, 325, 507, 198, 4806, 14, 705, 8, 705, 9, 507, 198, 1107, 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 ]
ZeitOnline/zeit.content.author
src/zeit/content/author/author.py
1
9296
from requests.exceptions import RequestException from zeit.cms.content.property import ObjectPathProperty from zeit.cms.i18n import MessageFactory as _ from zeit.content.author.interfaces import IAuthor import UserDict import grokcore.component as grok import lxml.objectify import requests import urllib import zeit.cms.content.interfaces import zeit.cms.content.property import zeit.cms.content.reference import zeit.cms.content.xmlsupport import zeit.cms.interfaces import zeit.cms.related.related import zeit.cms.repository.interfaces import zeit.cms.type import zeit.content.author.interfaces import zeit.find.interfaces import zeit.workflow.dependency import zope.interface import zope.security.proxy class Author(zeit.cms.content.xmlsupport.XMLContentBase): zope.interface.implements(zeit.content.author.interfaces.IAuthor, zeit.cms.interfaces.IAsset) default_template = ( u'<author xmlns:py="http://codespeak.net/lxml/objectify/pytype">' u'</author>') for name in [ 'biography', 'display_name', 'email', 'sso_connect', 'ssoid', 'enable_followpush', 'entered_display_name', 'external', 'facebook', 'firstname', 'instagram', 'lastname', 'occupation', 'status', 'summary', 'title', 'topiclink_label_1', 'topiclink_label_2', 'topiclink_label_3', 'topiclink_url_1', 'topiclink_url_2', 'topiclink_url_3', 'twitter', 'vgwortcode', 'vgwortid', ]: locals()[name] = ObjectPathProperty('.%s' % name, IAuthor[name]) community_profile = zeit.cms.content.property.ObjectPathProperty( '.communityprofile') enable_feedback = zeit.cms.content.property.ObjectPathProperty( '.enable_feedback', IAuthor['enable_feedback'], use_default=False) favourite_content = zeit.cms.content.reference.MultiResource( '.favourites.reference', 'related') @property def exists(self): elastic = zope.component.getUtility(zeit.find.interfaces.ICMSSearch) return bool(elastic.search({'query': {'bool': {'filter': [ {'term': {'doc_type': 'author'}}, {'term': {'payload.xml.firstname': self.firstname}}, {'term': {'payload.xml.lastname': self.lastname}}, ]}}}).hits) @property def bio_questions(self): return zeit.content.author.interfaces.IBiographyQuestions(self) @property def image_group(self): # BBB Deprecated in favor of a separate images adapter return zeit.content.image.interfaces.IImages(self).image class AuthorType(zeit.cms.type.XMLContentTypeDeclaration): factory = Author interface = zeit.content.author.interfaces.IAuthor type = 'author' title = _('Author') addform = 'zeit.content.author.add_contextfree' class AuthorImages(zeit.cms.related.related.RelatedBase): zope.component.adapts(zeit.content.author.interfaces.IAuthor) zope.interface.implements(zeit.content.image.interfaces.IImages) image = zeit.cms.content.reference.SingleResource('.image_group', 'image') fill_color = zeit.cms.content.property.ObjectPathAttributeProperty( '.image_group', 'fill_color', zeit.content.image.interfaces.IImages['fill_color']) @grok.subscribe( zeit.content.author.interfaces.IAuthor, zeit.cms.repository.interfaces.IBeforeObjectAddEvent) def update_display_name(obj, event): if obj.entered_display_name: obj.display_name = obj.entered_display_name else: obj.display_name = u'%s %s' % (obj.firstname, obj.lastname) @grok.subscribe( zeit.content.author.interfaces.IAuthor, zeit.cms.repository.interfaces.IBeforeObjectAddEvent) def set_ssoid(obj, event): if obj.email and obj.sso_connect: ssoid = request_acs(obj.email) if ssoid: obj.ssoid = ssoid else: obj.ssoid = None @grok.subscribe( zeit.content.author.interfaces.IAuthor, zope.lifecycleevent.IObjectModifiedEvent) def update_ssoid(context, event): for desc in event.descriptions: if (desc.interface is zeit.cms.content.interfaces.ICommonMetadata and 'sso_connect' or 'email' in desc.attributes): if context.sso_connect and context.email: ssoid = request_acs(context.email) if ssoid: context.ssoid = ssoid else: context.ssoid = None break def request_acs(email): config = zope.app.appsetup.product.getProductConfiguration( 'zeit.content.author') url = config['sso-api-url'] + '/users/' + urllib.quote( email.encode('utf8')) auth = (config['sso-user'], config['sso-password']) try: r = requests.get(url, auth=auth) r.raise_for_status() return r.json().get('id', None) except RequestException: return None # Note: This is needed by the publisher and zeit.vgwort, among others. # Publisher only indexes the freetext field at the moment. # zeit.vgwort.report uses the fact that the references to author objects are # copied to the freetext 'author' webdav property to filter out which content # objects to report. def update_author_freetext(content): content.authors = [x.target.display_name for x in content.authorships] @grok.subscribe( zeit.cms.content.interfaces.ICommonMetadata, zope.lifecycleevent.interfaces.IObjectModifiedEvent) def update_freetext_on_change(context, event): if event.descriptions: for description in event.descriptions: if (issubclass(description.interface, zeit.cms.content.interfaces.ICommonMetadata) and 'authorships' in description.attributes): update_author_freetext(context) @grok.subscribe( zeit.cms.content.interfaces.ICommonMetadata, zope.lifecycleevent.interfaces.IObjectCreatedEvent) def update_freetext_on_add(context, event): # ObjectCopied inherits from ObjectCreated if zeit.cms.repository.interfaces.IRepositoryContent.providedBy(context): return update_author_freetext(context) class Dependencies(zeit.workflow.dependency.DependencyBase): """When content is published, make sure that all author objects referenced by it are also available to the published content. """ grok.context(zeit.cms.content.interfaces.ICommonMetadata) grok.name('zeit.content.author') def get_dependencies(self): result = [] for ref in self.context.authorships: author = ref.target if not zeit.cms.workflow.interfaces.IPublishInfo(author).published: result.append(author) return result @grok.adapter( zeit.cms.content.interfaces.ICommonMetadata, name='zeit.content.author') @grok.implementer( zeit.cms.relation.interfaces.IReferenceProvider) def references(context): return [x.target for x in context.authorships] @grok.adapter( zeit.content.author.interfaces.IAuthor, zeit.cms.content.interfaces.IContentAdder) @grok.implementer(zeit.cms.content.interfaces.IAddLocation) def author_location(type_, adder): return zope.component.getUtility( zeit.cms.repository.interfaces.IRepository) class BiographyQuestions( grok.Adapter, UserDict.DictMixin, zeit.cms.content.xmlsupport.Persistent): grok.context(zeit.content.author.interfaces.IAuthor) grok.implements(zeit.content.author.interfaces.IBiographyQuestions) def __init__(self, context): object.__setattr__(self, 'context', context) object.__setattr__(self, 'xml', zope.security.proxy.getObject( context.xml)) object.__setattr__(self, '__parent__', context) def __getitem__(self, key): node = self.xml.xpath('//question[@id="%s"]' % key) return Question( key, self.title(key), unicode(node[0]) if node else None) def __setitem__(self, key, value): node = self.xml.xpath('//question[@id="%s"]' % key) if node: self.xml.remove(node[0]) if value: node = lxml.objectify.E.question(value, id=key) lxml.objectify.deannotate(node[0], cleanup_namespaces=True) self.xml.append(node) super(BiographyQuestions, self).__setattr__('_p_changed', True) def keys(self): return list(zeit.content.author.interfaces.BIOGRAPHY_QUESTIONS(self)) def title(self, key): return zeit.content.author.interfaces.BIOGRAPHY_QUESTIONS( self).title(key) # Attribute-style access to answers is meant only for zope.formlib. # This works without an explicit security declaration, since we are not # security-wrapped ourselves, only our context is, and we bypass that for # XML access. def __getattr__(self, key): return self.get(key).answer def __setattr__(self, key, value): self[key] = value class Question(object): zope.interface.implements(zeit.content.author.interfaces.IQuestion) def __init__(self, id, title, answer): self.id = id self.title = title self.answer = answer
bsd-3-clause
[ 504, 4145, 14, 3924, 492, 4784, 1726, 199, 504, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 492, 6935, 2042, 3697, 199, 504, 29986, 390, 14, 10781, 14, 73, 1085, 78, 492, 6430, 2927, 465, 485, 199, 504, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 492, 473, 5949, 199, 646, 32241, 199, 646, 486, 29275, 1018, 14, 3173, 465, 486, 29275, 199, 646, 14490, 14, 1113, 825, 3338, 199, 646, 4145, 199, 646, 4011, 199, 646, 29986, 390, 14, 10781, 14, 1317, 14, 7436, 199, 646, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 199, 646, 29986, 390, 14, 10781, 14, 1317, 14, 4443, 199, 646, 29986, 390, 14, 10781, 14, 1317, 14, 10198, 478, 384, 719, 199, 646, 29986, 390, 14, 10781, 14, 7436, 199, 646, 29986, 390, 14, 10781, 14, 2407, 14, 2407, 199, 646, 29986, 390, 14, 10781, 14, 8421, 14, 7436, 199, 646, 29986, 390, 14, 10781, 14, 466, 199, 646, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 199, 646, 29986, 390, 14, 1623, 14, 7436, 199, 646, 29986, 390, 14, 8856, 14, 8575, 199, 646, 20110, 14, 3266, 199, 646, 20110, 14, 4416, 14, 3280, 421, 199, 533, 6529, 8, 806, 390, 14, 10781, 14, 1317, 14, 10198, 478, 384, 719, 14, 4317, 2714, 1563, 304, 339, 20110, 14, 3266, 14, 24900, 8, 806, 390, 14, 1317, 14, 2502, 14, 7436, 14, 41, 5949, 12, 2892, 29986, 390, 14, 10781, 14, 7436, 14, 41, 19979, 9, 339, 849, 63, 1160, 275, 334, 267, 399, 7601, 2502, 9604, 26, 647, 628, 1014, 921, 6021, 8556, 14, 846, 15, 22899, 15, 1113, 825, 3338, 15, 647, 466, 15603, 267, 399, 29477, 2502, 5971, 339, 367, 536, 315, 359, 267, 283, 17614, 9773, 297, 267, 283, 2918, 63, 354, 297, 267, 283, 2123, 297, 267, 283, 25479, 63, 2242, 297, 267, 283, 385, 1170, 297, 267, 283, 4296, 63, 7207, 5335, 297, 267, 283, 287, 3014, 63, 2918, 63, 354, 297, 267, 283, 5159, 297, 267, 283, 16652, 297, 267, 283, 25603, 297, 267, 283, 3615, 32208, 297, 267, 283, 31164, 297, 267, 283, 27256, 425, 297, 267, 283, 1205, 297, 267, 283, 4705, 297, 267, 283, 1213, 297, 267, 283, 2119, 73, 429, 2292, 63, 1302, 63, 17, 297, 267, 283, 2119, 73, 429, 2292, 63, 1302, 63, 18, 297, 267, 283, 2119, 73, 429, 2292, 63, 1302, 63, 19, 297, 267, 283, 2119, 73, 429, 2292, 63, 633, 63, 17, 297, 267, 283, 2119, 73, 429, 2292, 63, 633, 63, 18, 297, 267, 283, 2119, 73, 429, 2292, 63, 633, 63, 19, 297, 267, 283, 13746, 297, 267, 283, 26408, 361, 600, 297, 267, 283, 10929, 584, 5700, 297, 272, 16246, 267, 9480, 3430, 354, 61, 275, 6935, 2042, 3697, 360, 4111, 83, 7, 450, 536, 12, 473, 5949, 59, 354, 566, 339, 23633, 63, 2913, 275, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 14, 1692, 2042, 3697, 8, 267, 1987, 9387, 2913, 358, 339, 4756, 63, 13485, 275, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 14, 1692, 2042, 3697, 8, 267, 1987, 4296, 63, 13485, 297, 267, 473, 5949, 459, 4296, 63, 13485, 995, 267, 675, 63, 885, 29, 797, 9, 339, 289, 1214, 567, 1175, 63, 1317, 275, 29986, 390, 14, 10781, 14, 1317, 14, 4443, 14, 3947, 4031, 8, 267, 1987, 30763, 567, 4033, 14, 4443, 297, 283, 2407, 358, 339, 768, 1829, 272, 347, 3495, 8, 277, 304, 267, 24380, 275, 20110, 14, 3173, 14, 362, 17505, 8, 806, 390, 14, 1623, 14, 7436, 14, 948, 3053, 5278, 9, 267, 372, 2155, 8, 15565, 14, 1733, 3252, 1131, 356, 791, 2245, 356, 791, 1541, 356, 359, 288, 791, 5125, 356, 791, 1301, 63, 466, 356, 283, 2502, 28400, 288, 791, 5125, 356, 791, 4749, 14, 1652, 14, 25603, 356, 291, 14, 25603, 13459, 288, 791, 5125, 356, 791, 4749, 14, 1652, 14, 31164, 356, 291, 14, 31164, 13459, 267, 1622, 4863, 21385, 16595, 9, 339, 768, 1829, 272, 347, 28897, 63, 16069, 8, 277, 304, 267, 372, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 14, 2100, 2308, 9773, 16778, 83, 8, 277, 9, 339, 768, 1829, 272, 347, 1834, 63, 923, 8, 277, 304, 267, 327, 699, 5342, 17993, 315, 17914, 402, 282, 7396, 5935, 12146, 267, 372, 29986, 390, 14, 1317, 14, 1569, 14, 7436, 14, 41, 18882, 8, 277, 680, 1569, 421, 199, 533, 6529, 804, 8, 806, 390, 14, 10781, 14, 466, 14, 4317, 11282, 17737, 304, 339, 6434, 275, 6529, 272, 3217, 275, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 14, 41, 5949, 272, 730, 275, 283, 2502, 7, 272, 2538, 275, 4018, 5949, 358, 272, 1050, 964, 275, 283, 806, 390, 14, 1317, 14, 2502, 14, 525, 63, 1100, 4624, 7, 421, 199, 533, 6529, 18882, 8, 806, 390, 14, 10781, 14, 2407, 14, 2407, 14, 13885, 1563, 304, 339, 20110, 14, 3173, 14, 350, 439, 1086, 8, 806, 390, 14, 1317, 14, 2502, 14, 7436, 14, 41, 5949, 9, 272, 20110, 14, 3266, 14, 24900, 8, 806, 390, 14, 1317, 14, 1569, 14, 7436, 14, 41, 18882, 9, 339, 1834, 275, 29986, 390, 14, 10781, 14, 1317, 14, 4443, 14, 7200, 4031, 5175, 1569, 63, 923, 297, 283, 1569, 358, 339, 5554, 63, 2326, 275, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 14, 1692, 2042, 1646, 3697, 8, 267, 1987, 1569, 63, 923, 297, 283, 4498, 63, 2326, 297, 267, 29986, 390, 14, 1317, 14, 1569, 14, 7436, 14, 41, 18882, 459, 4498, 63, 2326, 1105, 421, 199, 32, 23260, 75, 14, 10108, 8, 272, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 14, 41, 5949, 12, 272, 29986, 390, 14, 10781, 14, 8421, 14, 7436, 14, 2100, 69, 1707, 1692, 1123, 2390, 9, 199, 318, 1678, 63, 2918, 63, 354, 8, 1113, 12, 1566, 304, 272, 340, 1559, 14, 287, 3014, 63, 2918, 63, 354, 26, 267, 1559, 14, 2918, 63, 354, 275, 1559, 14, 287, 3014, 63, 2918, 63, 354, 272, 587, 26, 267, 1559, 14, 2918, 63, 354, 275, 399, 5956, 83, 450, 83, 7, 450, 334, 1113, 14, 25603, 12, 1559, 14, 31164, 9, 421, 199, 32, 23260, 75 ]
[ 4145, 14, 3924, 492, 4784, 1726, 199, 504, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 492, 6935, 2042, 3697, 199, 504, 29986, 390, 14, 10781, 14, 73, 1085, 78, 492, 6430, 2927, 465, 485, 199, 504, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 492, 473, 5949, 199, 646, 32241, 199, 646, 486, 29275, 1018, 14, 3173, 465, 486, 29275, 199, 646, 14490, 14, 1113, 825, 3338, 199, 646, 4145, 199, 646, 4011, 199, 646, 29986, 390, 14, 10781, 14, 1317, 14, 7436, 199, 646, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 199, 646, 29986, 390, 14, 10781, 14, 1317, 14, 4443, 199, 646, 29986, 390, 14, 10781, 14, 1317, 14, 10198, 478, 384, 719, 199, 646, 29986, 390, 14, 10781, 14, 7436, 199, 646, 29986, 390, 14, 10781, 14, 2407, 14, 2407, 199, 646, 29986, 390, 14, 10781, 14, 8421, 14, 7436, 199, 646, 29986, 390, 14, 10781, 14, 466, 199, 646, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 199, 646, 29986, 390, 14, 1623, 14, 7436, 199, 646, 29986, 390, 14, 8856, 14, 8575, 199, 646, 20110, 14, 3266, 199, 646, 20110, 14, 4416, 14, 3280, 421, 199, 533, 6529, 8, 806, 390, 14, 10781, 14, 1317, 14, 10198, 478, 384, 719, 14, 4317, 2714, 1563, 304, 339, 20110, 14, 3266, 14, 24900, 8, 806, 390, 14, 1317, 14, 2502, 14, 7436, 14, 41, 5949, 12, 2892, 29986, 390, 14, 10781, 14, 7436, 14, 41, 19979, 9, 339, 849, 63, 1160, 275, 334, 267, 399, 7601, 2502, 9604, 26, 647, 628, 1014, 921, 6021, 8556, 14, 846, 15, 22899, 15, 1113, 825, 3338, 15, 647, 466, 15603, 267, 399, 29477, 2502, 5971, 339, 367, 536, 315, 359, 267, 283, 17614, 9773, 297, 267, 283, 2918, 63, 354, 297, 267, 283, 2123, 297, 267, 283, 25479, 63, 2242, 297, 267, 283, 385, 1170, 297, 267, 283, 4296, 63, 7207, 5335, 297, 267, 283, 287, 3014, 63, 2918, 63, 354, 297, 267, 283, 5159, 297, 267, 283, 16652, 297, 267, 283, 25603, 297, 267, 283, 3615, 32208, 297, 267, 283, 31164, 297, 267, 283, 27256, 425, 297, 267, 283, 1205, 297, 267, 283, 4705, 297, 267, 283, 1213, 297, 267, 283, 2119, 73, 429, 2292, 63, 1302, 63, 17, 297, 267, 283, 2119, 73, 429, 2292, 63, 1302, 63, 18, 297, 267, 283, 2119, 73, 429, 2292, 63, 1302, 63, 19, 297, 267, 283, 2119, 73, 429, 2292, 63, 633, 63, 17, 297, 267, 283, 2119, 73, 429, 2292, 63, 633, 63, 18, 297, 267, 283, 2119, 73, 429, 2292, 63, 633, 63, 19, 297, 267, 283, 13746, 297, 267, 283, 26408, 361, 600, 297, 267, 283, 10929, 584, 5700, 297, 272, 16246, 267, 9480, 3430, 354, 61, 275, 6935, 2042, 3697, 360, 4111, 83, 7, 450, 536, 12, 473, 5949, 59, 354, 566, 339, 23633, 63, 2913, 275, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 14, 1692, 2042, 3697, 8, 267, 1987, 9387, 2913, 358, 339, 4756, 63, 13485, 275, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 14, 1692, 2042, 3697, 8, 267, 1987, 4296, 63, 13485, 297, 267, 473, 5949, 459, 4296, 63, 13485, 995, 267, 675, 63, 885, 29, 797, 9, 339, 289, 1214, 567, 1175, 63, 1317, 275, 29986, 390, 14, 10781, 14, 1317, 14, 4443, 14, 3947, 4031, 8, 267, 1987, 30763, 567, 4033, 14, 4443, 297, 283, 2407, 358, 339, 768, 1829, 272, 347, 3495, 8, 277, 304, 267, 24380, 275, 20110, 14, 3173, 14, 362, 17505, 8, 806, 390, 14, 1623, 14, 7436, 14, 948, 3053, 5278, 9, 267, 372, 2155, 8, 15565, 14, 1733, 3252, 1131, 356, 791, 2245, 356, 791, 1541, 356, 359, 288, 791, 5125, 356, 791, 1301, 63, 466, 356, 283, 2502, 28400, 288, 791, 5125, 356, 791, 4749, 14, 1652, 14, 25603, 356, 291, 14, 25603, 13459, 288, 791, 5125, 356, 791, 4749, 14, 1652, 14, 31164, 356, 291, 14, 31164, 13459, 267, 1622, 4863, 21385, 16595, 9, 339, 768, 1829, 272, 347, 28897, 63, 16069, 8, 277, 304, 267, 372, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 14, 2100, 2308, 9773, 16778, 83, 8, 277, 9, 339, 768, 1829, 272, 347, 1834, 63, 923, 8, 277, 304, 267, 327, 699, 5342, 17993, 315, 17914, 402, 282, 7396, 5935, 12146, 267, 372, 29986, 390, 14, 1317, 14, 1569, 14, 7436, 14, 41, 18882, 8, 277, 680, 1569, 421, 199, 533, 6529, 804, 8, 806, 390, 14, 10781, 14, 466, 14, 4317, 11282, 17737, 304, 339, 6434, 275, 6529, 272, 3217, 275, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 14, 41, 5949, 272, 730, 275, 283, 2502, 7, 272, 2538, 275, 4018, 5949, 358, 272, 1050, 964, 275, 283, 806, 390, 14, 1317, 14, 2502, 14, 525, 63, 1100, 4624, 7, 421, 199, 533, 6529, 18882, 8, 806, 390, 14, 10781, 14, 2407, 14, 2407, 14, 13885, 1563, 304, 339, 20110, 14, 3173, 14, 350, 439, 1086, 8, 806, 390, 14, 1317, 14, 2502, 14, 7436, 14, 41, 5949, 9, 272, 20110, 14, 3266, 14, 24900, 8, 806, 390, 14, 1317, 14, 1569, 14, 7436, 14, 41, 18882, 9, 339, 1834, 275, 29986, 390, 14, 10781, 14, 1317, 14, 4443, 14, 7200, 4031, 5175, 1569, 63, 923, 297, 283, 1569, 358, 339, 5554, 63, 2326, 275, 29986, 390, 14, 10781, 14, 1317, 14, 1829, 14, 1692, 2042, 1646, 3697, 8, 267, 1987, 1569, 63, 923, 297, 283, 4498, 63, 2326, 297, 267, 29986, 390, 14, 1317, 14, 1569, 14, 7436, 14, 41, 18882, 459, 4498, 63, 2326, 1105, 421, 199, 32, 23260, 75, 14, 10108, 8, 272, 29986, 390, 14, 1317, 14, 2502, 14, 7436, 14, 41, 5949, 12, 272, 29986, 390, 14, 10781, 14, 8421, 14, 7436, 14, 2100, 69, 1707, 1692, 1123, 2390, 9, 199, 318, 1678, 63, 2918, 63, 354, 8, 1113, 12, 1566, 304, 272, 340, 1559, 14, 287, 3014, 63, 2918, 63, 354, 26, 267, 1559, 14, 2918, 63, 354, 275, 1559, 14, 287, 3014, 63, 2918, 63, 354, 272, 587, 26, 267, 1559, 14, 2918, 63, 354, 275, 399, 5956, 83, 450, 83, 7, 450, 334, 1113, 14, 25603, 12, 1559, 14, 31164, 9, 421, 199, 32, 23260, 75, 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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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 ]
pedropena/iteexe
exe/export/singlepage.py
1
14738
# =========================================================================== # eXe # Copyright 2004-2005, University of Auckland # Copyright 2004-2008 eXe Project, http://eXeLearning.org/ # # This program 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. # # 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # =========================================================================== """ This class transforms an eXe node into a page on a single page website """ import logging import re from cgi import escape from urllib import quote from exe.webui.blockfactory import g_blockFactory from exe.engine.error import Error from exe.engine.path import Path from exe.engine.version import release from exe.export import helper from exe.export.helper import lineBreak from exe.export.pages import Page, uniquifyNames from exe.webui import common from exe import globals as G log = logging.getLogger(__name__) class SinglePage(Page): """ This class transforms an eXe node into a page on a single page website """ def save(self, filename, for_print=0): """ Save page to a file. 'outputDir' is the directory where the filenames will be saved (a 'path' instance) """ outfile = open(filename, 'wb') outfile.write(self.render(self.node.package, for_print).encode('utf8')) outfile.close() def render(self, package, for_print = 0): """ Returns an XHTML string rendering this page. """ # Get the DocType docType = common.getExportDocType() # Get section and header tags sectionTag = u'div' headerTag = u'div' if docType == u'HTML5': sectionTag = u'section' headerTag = u'header' # Get package title if package.title != '': title = escape(package.title) else: title = escape(package.root.titleLong) # Render HTML header html = self.renderHeader(title, docType, for_print) if for_print: # Include extra onload bit: html += u'<body class="exe-single-page" onload="print_page()">' else: html += u'<body class="exe-single-page">' # Script to check if JS is enabled html += u'<script type="text/javascript">document.body.className+=" js"</script>' + lineBreak # Main content block html += u'<div id="content">' + lineBreak # Header html += u'<%s id="header">%s' % (headerTag, lineBreak) # Header content block html += u'<div id="headerContent">' + lineBreak # Package title html += u'<h1>%s</h1>%s' % (escape(title), lineBreak) # Close header content block html += u'</div>' + lineBreak # Close header html += u'</%s>%s' % (headerTag, lineBreak) # Main section html += u'<%s id="main">%s' % (sectionTag, lineBreak) # Render node contents html += self.renderNode(package.root, docType, 1) # Close main section html += u'</%s>%s' % (sectionTag, lineBreak) # Render the license html += self.renderLicense() + lineBreak # Render the footer html += self.renderFooter() + lineBreak # Close main content block html += u'</div>' + lineBreak # Some styles might have their own JavaScript files (see their config.xml file) style = G.application.config.styleStore.getStyle(self.node.package.style) if style.hasValidConfig: html += style.get_extra_body() # Close body and HTML tags html += u'</body>' + lineBreak html += u'</html>' # Remove ecuation attributes html = helper.removeEcuationAttr(html) # Change glosary path html = helper.changeGlossaryPath(html) # Escape & html = helper.escapeAmp(html) # Remove "resources/" from data="resources/ and the url param html = helper.removeResources(html) return html def renderHeader(self, title, docType, for_print = 0): """ Returns an XHTML string for the header of this page. """ # Check what iDevices and special features the node has hasGallery = helper.hasGalleryIdevice(self.node) hasEffects = helper.hasFX(self.node) hasHighlighter = helper.hasSH(self.node) hasJSGames = helper.hasGames(self.node) hasWikipedia = helper.hasWikipediaIdevice(self.node) hasMediaelement = helper.nodeHasMediaelement(self.node) hasABCMusic = helper.nodeHasABCMusic(self.node) listIdevicesFiles = helper.addListIdevicesFiles(self.node) # Get package language lang = G.application.config.locale if self.node.package.dublinCore.language != '': lang = self.node.package.dublinCore.language # Write page DocType and HTML start tag if docType == 'HTML5': html = u'<!DOCTYPE html>' + lineBreak html += u'<html lang="%s">%s' % (lang, lineBreak) else: html = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' + lineBreak html += u'<html lang="%s" xml:lang="%s" xmlns="http://www.w3.org/1999/xhtml">%s' % (lang, lang, lineBreak) # HTML head start tag html += u'<head>' + lineBreak # Page charset html += u'<meta http-equiv="content-type" content="text/html; charset=utf-8" />' + lineBreak # Page title html += u'<title>%s</title>%s' % (title, lineBreak) # Favicon html += u'<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />' + lineBreak # If the page is not in HTML5, we need to specify the language here if docType != 'HTML5' and self.node.package.dublinCore.language != '': html += u'<meta http-equiv="content-language" content="%s" />%s' % (lang, lineBreak) # Render the author META tag if self.node.package.author != "": html += u'<meta name="author" content="%s" />%s' % (escape(self.node.package.author, True), lineBreak) # Render the license META tag(s) html += common.getLicenseMetadata(self.node.package.license) # Render the generator META tag html += u'<meta name="generator" content="eXeLearning %s - exelearning.net" />%s' % (release, lineBreak) # Render the description META tag if self.node.package.description != "": desc = self.node.package.description # If the description has any double quotes, we have to escape them desc = desc.replace('"', '&quot;') html += u'<meta name="description" content="%s" />%s' % (desc, lineBreak) # Add CSS files html += u'<link rel="stylesheet" type="text/css" href="base.css" />' + lineBreak if hasWikipedia: html += u'<link rel="stylesheet" type="text/css" href="exe_wikipedia.css" />' + lineBreak if hasGallery: html += u'<link rel="stylesheet" type="text/css" href="exe_lightbox.css" />' + lineBreak if hasEffects: html += u'<link rel="stylesheet" type="text/css" href="exe_effects.css" />' + lineBreak if hasHighlighter: html += u'<link rel="stylesheet" type="text/css" href="exe_highlighter.css" />' + lineBreak if hasJSGames: html += u'<link rel="stylesheet" type="text/css" href="exe_games.css" />' + lineBreak if hasABCMusic: html += u'<link rel="stylesheet" type="text/css" href="exe_abcmusic.css" />' + lineBreak html += u'<link rel="stylesheet" type="text/css" href="content.css" />' + lineBreak # Add HTML compatibility script to IE 9 if docType == "HTML5" or hasMediaelement: html += u'<!--[if lt IE 9]><script type="text/javascript" src="exe_html5.js"></script><![endif]-->' + lineBreak # Get the style style = G.application.config.styleStore.getStyle(self.node.package.style) # Add JS files if style.hasValidConfig: if style.get_jquery() == True: html += u'<script type="text/javascript" src="exe_jquery.js"></script>' + lineBreak else: html += u'<script type="text/javascript" src="%s"></script>%s' % (style.get_jquery(), lineBreak) else: html += u'<script type="text/javascript" src="exe_jquery.js"></script>' + lineBreak if hasGallery: html += u'<script type="text/javascript" src="exe_lightbox.js"></script>' + lineBreak if hasEffects: html += u'<script type="text/javascript" src="exe_effects.js"></script>' + lineBreak if hasHighlighter: html += u'<script type="text/javascript" src="exe_highlighter.js"></script>' + lineBreak html += u'<script type="text/javascript" src="common_i18n.js"></script>' + lineBreak if hasJSGames: html += u'<script type="text/javascript" src="exe_games.js"></script>' + lineBreak if hasABCMusic: html += u'<script type="text/javascript" src="exe_abcmusic.js"></script>' + lineBreak html += u'<script type="text/javascript" src="common.js"></script>' + lineBreak for ideviceFile in set(listIdevicesFiles): html += ideviceFile if common.hasMagnifier(self.node): html += u'<script type="text/javascript" src="mojomagnify.js"></script>' + lineBreak # include extra print-script for onload bit if for_print: html += u'<script type="text/javascript">' + lineBreak html += u'var interval;' + lineBreak html += u'function checkClose() {' + lineBreak html += u' if (document.hasFocus()) {' + lineBreak html += u' alert("' + _("You can close this window") + u'");' + lineBreak html += u' clearInterval(interval);' + lineBreak #html += u' window.close();' + lineBreak html += u' }' + lineBreak html += u'}' + lineBreak html += u'function print_page() {' + lineBreak html += u' if(typeof document.hasFocus === "undefined") {' + lineBreak html += u' document.hasFocus = function () {' + lineBreak html += u' return document.visibilityState == "visible";' + lineBreak html += u' }' + lineBreak html += u' }' + lineBreak html += u' window.print();' + lineBreak html += u' interval = setInterval(checkClose, 300);' + lineBreak html += u'}' + lineBreak html += u'</script>' + lineBreak if style.hasValidConfig: html += style.get_extra_head() html += common.getExtraHeadContent(self.node.package) # Close head tag html += u'</head>' + lineBreak return html def renderNode(self, node, docType, level): """ Returns an XHTML string for this node and recurse for the children """ # Get section and header tags headerTag = u'div' articleTag = u'div' if docType == 'HTML5': headerTag = u'header' articleTag = u'article' headerLevel = level if(level > 6): headerLevel = 6 html = u'' # Main node container html += u'<%s class="node level-%d-node" id="exe-node-%s">%s' % (articleTag, level, node.id, lineBreak) # Node header container html += u'<%s class="nodeDecoration">%s' % (headerTag, lineBreak) # Node title html += u'<h1 id="%s" class="nodeTitle">%s</h1>%s' % (node.GetAnchorName(), escape(node.titleLong), lineBreak) # Close Node header container html += u'</%s>%s' % (headerTag, lineBreak) # Get the node Style style = self.node.package.style # Set node export type node.exportType = 'singlepage' # Render node iDevices for idevice in node.idevices: if idevice.klass != 'NotaIdevice': e = " em_iDevice" if unicode(idevice.emphasis) == '0': e = "" # iDevice container html += u'<%s class="iDevice_wrapper %s%s" id="id%s">%s' % (articleTag, idevice.klass, e, (idevice.id + '-' + node.id), lineBreak) # Try to render the iDevice block = g_blockFactory.createBlock(None, idevice) if not block: log.critical('Unable to render iDevice %s.' % (idevice.klass)) raise Error('Unable to render iDevice.') if hasattr(idevice, "isQuiz"): html += block.renderJavascriptForWeb() # Process iDevice internal links html += helper.processInternalLinks(self.node.package, block.renderView(style)) # Replace top links with "empty" links html = helper.replaceTopLinks(html) # Close iDevice container html += u'</%s>%s' % (articleTag, lineBreak) # Close main node container html += u'</%s>%s' % (articleTag, lineBreak) # Render all child nodes for child in node.children: html += self.renderNode(child, docType, level + 1) return html
gpl-2.0
[ 3, 7819, 17575, 199, 3, 325, 56, 69, 221, 199, 3, 1898, 8353, 13, 9397, 12, 15904, 402, 437, 10112, 9688, 199, 3, 1898, 8353, 13, 9300, 325, 56, 69, 7290, 12, 1455, 921, 69, 56, 69, 25519, 14, 1308, 15, 199, 3, 199, 3, 961, 2240, 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, 961, 2240, 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, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 221, 15673, 13, 13421, 221, 8217, 199, 3, 7819, 17575, 199, 624, 199, 2765, 1021, 18501, 376, 325, 56, 69, 1031, 1901, 282, 2034, 641, 282, 2849, 2034, 10691, 199, 624, 199, 199, 646, 2050, 199, 646, 295, 199, 504, 16004, 10473, 492, 4772, 199, 504, 4011, 7861, 492, 6313, 199, 504, 14778, 14, 31991, 73, 14, 1457, 3702, 257, 492, 486, 63, 1457, 2927, 199, 504, 14778, 14, 3908, 14, 705, 260, 492, 4520, 199, 504, 14778, 14, 3908, 14, 515, 3515, 492, 6912, 199, 504, 14778, 14, 3908, 14, 1023, 755, 492, 4683, 199, 504, 14778, 14, 3790, 5185, 492, 5922, 199, 504, 14778, 14, 3790, 14, 3676, 263, 492, 1004, 13948, 221, 199, 504, 14778, 14, 3790, 14, 5856, 260, 492, 10331, 12, 15439, 392, 2021, 5866, 199, 504, 14778, 14, 31991, 73, 4483, 492, 2863, 199, 504, 14778, 10473, 492, 7992, 465, 598, 199, 199, 793, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 533, 13050, 3276, 8, 3276, 304, 272, 408, 272, 961, 1021, 18501, 376, 325, 56, 69, 1031, 1901, 282, 2034, 641, 282, 2849, 2034, 10691, 272, 408, 5493, 347, 3354, 8, 277, 12, 1788, 12, 367, 63, 1361, 29, 16, 304, 267, 408, 267, 11063, 2034, 370, 282, 570, 14, 27439, 283, 1199, 3567, 7, 365, 314, 2082, 2382, 314, 6203, 911, 506, 6290, 267, 334, 65, 283, 515, 7, 1256, 9, 267, 408, 267, 4386, 275, 1551, 8, 1501, 12, 283, 6603, 358, 267, 4386, 14, 952, 8, 277, 14, 3352, 8, 277, 14, 932, 14, 2491, 12, 367, 63, 1361, 680, 2143, 360, 1624, 24, 1333, 267, 4386, 14, 1600, 342, 5493, 347, 3795, 8, 277, 12, 2559, 12, 367, 63, 1361, 275, 378, 304, 267, 408, 267, 1803, 376, 26223, 1059, 14066, 642, 2034, 14, 267, 408, 2728, 327, 2372, 314, 5454, 804, 267, 1382, 804, 275, 2863, 14, 362, 11399, 3768, 804, 342, 2728, 327, 2372, 3420, 436, 1406, 3762, 267, 3420, 1931, 275, 399, 5121, 1003, 7, 267, 1406, 1931, 275, 399, 5121, 1003, 7, 267, 340, 1382, 804, 508, 399, 7, 4943, 21, 356, 288, 3420, 1931, 275, 399, 1159, 15636, 7, 288, 1406, 1931, 275, 399, 7, 1291, 7, 10631, 327, 2372, 2559, 2538, 267, 340, 2559, 14, 1213, 1137, 8061, 288, 2538, 275, 4772, 8, 2491, 14, 1213, 9, 267, 587, 26, 288, 2538, 275, 4772, 8, 2491, 14, 1231, 14, 1213, 9551, 9, 10631, 327, 17769, 4163, 1406, 267, 3517, 221, 275, 291, 14, 3352, 2567, 8, 1213, 12, 1382, 804, 12, 367, 63, 1361, 9, 2728, 340, 367, 63, 1361, 26, 288, 327, 15783, 2402, 641, 912, 4546, 26, 288, 3517, 847, 399, 7601, 2030, 1021, 628, 5803, 13, 4780, 13, 1606, 2, 641, 912, 628, 1361, 63, 1606, 342, 15603, 267, 587, 26, 288, 3517, 847, 399, 7601, 2030, 1021, 628, 5803, 13, 4780, 13, 1606, 15603, 10631, 327, 14914, 370, 1104, 340, 18001, 365, 5223, 267, 3517, 847, 399, 7601, 1579, 730, 628, 505, 15, 9554, 1743, 3554, 14, 2030, 14, 533, 985, 11, 628, 8586, 2, 1108, 1579, 3524, 435, 1004, 13948, 2728, 327, 11298, 1564, 1853, 267, 3517, 847, 399, 7601, 3015, 1305, 628, 1317, 15603, 435, 1004, 13948, 2728, 327, 10240, 267, 3517, 847, 399, 7601, 5, 83, 1305, 628, 1291, 14423, 83, 7, 450, 334, 1291, 1931, 12, 1004, 13948, 9, 267, 327, 10240, 1564, 1853, 267, 3517, 847, 399, 7601, 3015, 1305, 628, 1291, 2714, 15603, 435, 1004, 13948, 267, 327, 15665, 2538, 267, 3517, 847, 399, 7601, 72, 17, 6598, 83, 1108, 72, 17, 6598, 83, 7, 450, 334, 3765, 8, 1213, 395, 1004, 13948, 9, 267, 327, 15524, 1406, 1564, 1853, 267, 3517, 847, 399, 29477, 3015, 3524, 435, 1004, 13948, 267, 327, 15524, 1406, 267, 3517, 847, 399, 7, 26191, 83, 6598, 83, 7, 450, 334, 1291, 1931, 12, 1004, 13948, 9, 2728, 327, 11298, 3420, 267, 3517, 847, 399, 7601, 5, 83, 1305, 628, 973, 14423, 83, 7, 450, 334, 2792, 1931, 12, 1004, 13948, 9, 2728, 327, 17769, 1031, 4072, 267, 3517, 847, 291, 14, 3352, 1716, 8, 2491, 14, 1231, 12, 1382, 804, 12, 413, 9, 2728, 327, 15524, 2446, 3420, 267, 3517, 847, 399, 7, 26191, 83, 6598, 83, 7, 450, 334, 2792, 1931, 12, 1004, 13948, 9, 2728, 327, 17769, 314, 4190, 267, 3517, 847, 291, 14, 3352, 3761, 342, 435, 1004, 13948, 2728, 327, 17769, 314, 14178, 267, 3517, 847, 291, 14, 3352, 5686, 351, 342, 435, 1004, 13948, 2728, 327, 15524, 2446, 1564, 1853, 267, 3517, 847, 399, 29477, 3015, 3524, 435, 1004, 13948, 2728, 327, 6601, 15725, 5594, 1172, 3932, 5705, 15250, 1584, 334, 3239, 3932, 1101, 14, 1652, 570, 9, 267, 3449, 275, 598, 14, 3578, 14, 888, 14, 2487, 5502, 14, 362, 6609, 8, 277, 14, 932, 14, 2491, 14, 2487, 9, 267, 340, 3449, 14, 1989, 3490, 2028, 26, 288, 3517, 847, 3449, 14, 362, 63, 2911, 63, 2030, 342, 10631, 327, 15524, 2396 ]
[ 7819, 17575, 199, 3, 325, 56, 69, 221, 199, 3, 1898, 8353, 13, 9397, 12, 15904, 402, 437, 10112, 9688, 199, 3, 1898, 8353, 13, 9300, 325, 56, 69, 7290, 12, 1455, 921, 69, 56, 69, 25519, 14, 1308, 15, 199, 3, 199, 3, 961, 2240, 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, 961, 2240, 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, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 221, 15673, 13, 13421, 221, 8217, 199, 3, 7819, 17575, 199, 624, 199, 2765, 1021, 18501, 376, 325, 56, 69, 1031, 1901, 282, 2034, 641, 282, 2849, 2034, 10691, 199, 624, 199, 199, 646, 2050, 199, 646, 295, 199, 504, 16004, 10473, 492, 4772, 199, 504, 4011, 7861, 492, 6313, 199, 504, 14778, 14, 31991, 73, 14, 1457, 3702, 257, 492, 486, 63, 1457, 2927, 199, 504, 14778, 14, 3908, 14, 705, 260, 492, 4520, 199, 504, 14778, 14, 3908, 14, 515, 3515, 492, 6912, 199, 504, 14778, 14, 3908, 14, 1023, 755, 492, 4683, 199, 504, 14778, 14, 3790, 5185, 492, 5922, 199, 504, 14778, 14, 3790, 14, 3676, 263, 492, 1004, 13948, 221, 199, 504, 14778, 14, 3790, 14, 5856, 260, 492, 10331, 12, 15439, 392, 2021, 5866, 199, 504, 14778, 14, 31991, 73, 4483, 492, 2863, 199, 504, 14778, 10473, 492, 7992, 465, 598, 199, 199, 793, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 533, 13050, 3276, 8, 3276, 304, 272, 408, 272, 961, 1021, 18501, 376, 325, 56, 69, 1031, 1901, 282, 2034, 641, 282, 2849, 2034, 10691, 272, 408, 5493, 347, 3354, 8, 277, 12, 1788, 12, 367, 63, 1361, 29, 16, 304, 267, 408, 267, 11063, 2034, 370, 282, 570, 14, 27439, 283, 1199, 3567, 7, 365, 314, 2082, 2382, 314, 6203, 911, 506, 6290, 267, 334, 65, 283, 515, 7, 1256, 9, 267, 408, 267, 4386, 275, 1551, 8, 1501, 12, 283, 6603, 358, 267, 4386, 14, 952, 8, 277, 14, 3352, 8, 277, 14, 932, 14, 2491, 12, 367, 63, 1361, 680, 2143, 360, 1624, 24, 1333, 267, 4386, 14, 1600, 342, 5493, 347, 3795, 8, 277, 12, 2559, 12, 367, 63, 1361, 275, 378, 304, 267, 408, 267, 1803, 376, 26223, 1059, 14066, 642, 2034, 14, 267, 408, 2728, 327, 2372, 314, 5454, 804, 267, 1382, 804, 275, 2863, 14, 362, 11399, 3768, 804, 342, 2728, 327, 2372, 3420, 436, 1406, 3762, 267, 3420, 1931, 275, 399, 5121, 1003, 7, 267, 1406, 1931, 275, 399, 5121, 1003, 7, 267, 340, 1382, 804, 508, 399, 7, 4943, 21, 356, 288, 3420, 1931, 275, 399, 1159, 15636, 7, 288, 1406, 1931, 275, 399, 7, 1291, 7, 10631, 327, 2372, 2559, 2538, 267, 340, 2559, 14, 1213, 1137, 8061, 288, 2538, 275, 4772, 8, 2491, 14, 1213, 9, 267, 587, 26, 288, 2538, 275, 4772, 8, 2491, 14, 1231, 14, 1213, 9551, 9, 10631, 327, 17769, 4163, 1406, 267, 3517, 221, 275, 291, 14, 3352, 2567, 8, 1213, 12, 1382, 804, 12, 367, 63, 1361, 9, 2728, 340, 367, 63, 1361, 26, 288, 327, 15783, 2402, 641, 912, 4546, 26, 288, 3517, 847, 399, 7601, 2030, 1021, 628, 5803, 13, 4780, 13, 1606, 2, 641, 912, 628, 1361, 63, 1606, 342, 15603, 267, 587, 26, 288, 3517, 847, 399, 7601, 2030, 1021, 628, 5803, 13, 4780, 13, 1606, 15603, 10631, 327, 14914, 370, 1104, 340, 18001, 365, 5223, 267, 3517, 847, 399, 7601, 1579, 730, 628, 505, 15, 9554, 1743, 3554, 14, 2030, 14, 533, 985, 11, 628, 8586, 2, 1108, 1579, 3524, 435, 1004, 13948, 2728, 327, 11298, 1564, 1853, 267, 3517, 847, 399, 7601, 3015, 1305, 628, 1317, 15603, 435, 1004, 13948, 2728, 327, 10240, 267, 3517, 847, 399, 7601, 5, 83, 1305, 628, 1291, 14423, 83, 7, 450, 334, 1291, 1931, 12, 1004, 13948, 9, 267, 327, 10240, 1564, 1853, 267, 3517, 847, 399, 7601, 3015, 1305, 628, 1291, 2714, 15603, 435, 1004, 13948, 267, 327, 15665, 2538, 267, 3517, 847, 399, 7601, 72, 17, 6598, 83, 1108, 72, 17, 6598, 83, 7, 450, 334, 3765, 8, 1213, 395, 1004, 13948, 9, 267, 327, 15524, 1406, 1564, 1853, 267, 3517, 847, 399, 29477, 3015, 3524, 435, 1004, 13948, 267, 327, 15524, 1406, 267, 3517, 847, 399, 7, 26191, 83, 6598, 83, 7, 450, 334, 1291, 1931, 12, 1004, 13948, 9, 2728, 327, 11298, 3420, 267, 3517, 847, 399, 7601, 5, 83, 1305, 628, 973, 14423, 83, 7, 450, 334, 2792, 1931, 12, 1004, 13948, 9, 2728, 327, 17769, 1031, 4072, 267, 3517, 847, 291, 14, 3352, 1716, 8, 2491, 14, 1231, 12, 1382, 804, 12, 413, 9, 2728, 327, 15524, 2446, 3420, 267, 3517, 847, 399, 7, 26191, 83, 6598, 83, 7, 450, 334, 2792, 1931, 12, 1004, 13948, 9, 2728, 327, 17769, 314, 4190, 267, 3517, 847, 291, 14, 3352, 3761, 342, 435, 1004, 13948, 2728, 327, 17769, 314, 14178, 267, 3517, 847, 291, 14, 3352, 5686, 351, 342, 435, 1004, 13948, 2728, 327, 15524, 2446, 1564, 1853, 267, 3517, 847, 399, 29477, 3015, 3524, 435, 1004, 13948, 2728, 327, 6601, 15725, 5594, 1172, 3932, 5705, 15250, 1584, 334, 3239, 3932, 1101, 14, 1652, 570, 9, 267, 3449, 275, 598, 14, 3578, 14, 888, 14, 2487, 5502, 14, 362, 6609, 8, 277, 14, 932, 14, 2491, 14, 2487, 9, 267, 340, 3449, 14, 1989, 3490, 2028, 26, 288, 3517, 847, 3449, 14, 362, 63, 2911, 63, 2030, 342, 10631, 327, 15524, 2396, 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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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 ]
ilblackdragon/tf_examples
seq2seq/data.py
1
2291
import tensorflow as tf from tensorflow.contrib import layers from tensorflow.contrib import learn def make_input_fn(mode, filename_in, filename_out, in_vocab_file, out_vocab_file, batch_size, vocab_size, input_max_length, output_max_length, queue_capacity=10000, num_threads=10): def input_fn(): num_epochs = None if mode == tf.estimator.ModeKeys.TRAIN else 1 filename_in_queue = tf.train.string_input_producer( [filename_in], num_epochs=num_epochs) filename_out_queue = tf.train.string_input_producer( [filename_out], num_epochs=num_epochs) reader_in = tf.TextLineReader() reader_out = tf.TextLineReader() in_list, out_list = [], [] for _ in range(num_threads): in_list.append(reader_in.read(filename_in_queue)[1]) out_list.append(reader_out.read(filename_out_queue)[1]) tensor_in = reader_in.read(filename_in_queue)[1] tensor_out = reader_out.read(filename_out_queue)[1] if mode == tf.estimator.ModeKeys.TRAIN: inputs, outputs = tf.train.shuffle_batch( (tensor_in, tensor_out), batch_size, capacity=queue_capacity, min_after_dequeue=batch_size * 3, enqueue_many=True ) else: inputs, outputs = tf.train.batch( (tensor_in, tensor_out), batch_size, capacity=queue_capacity, allow_smaller_final_batch=True) # Preprocess inputs. inputs = utils.sparse_to_dense_trim(tf.string_split(inputs), output_shape=[batch_size, input_max_length], default_value='<\S>') outputs = utils.sparse_to_dense_trim(tf.string_split(outputs), output_shape=[batch_size, output_max_length], default_value='<\S>') tf.identity(inputs[0], name='inputs') tf.identity(outputs[0], name='outputs') in_vocab = tf.contrib.lookup.index_table_from_file(in_vocab_file, vocab_size=vocab_size, default_value=2) input_ids = in_vocab.lookup(inputs) out_vocab = tf.contrib.lookup.index_table_from_file(out_vocab_file, vocab_size=vocab_size, default_value=2) output_ids = out_vocab.lookup(outputs) return {'inputs': inputs_ids, 'outputs': outputs_ids}, None return input_fn
apache-2.0
[ 646, 3228, 465, 2833, 199, 504, 3228, 14, 2828, 492, 9393, 199, 504, 3228, 14, 2828, 492, 12537, 421, 199, 318, 1852, 63, 1210, 63, 2324, 8, 632, 12, 1788, 63, 262, 12, 1788, 63, 548, 12, 315, 63, 9953, 63, 493, 12, 734, 63, 9953, 63, 493, 12, 3522, 63, 890, 12, 11181, 63, 890, 12, 2116, 1324, 63, 988, 63, 1267, 12, 1072, 63, 988, 63, 1267, 12, 4126, 63, 10457, 29, 9943, 12, 1967, 63, 6962, 29, 709, 304, 272, 347, 1324, 63, 2324, 837, 267, 1967, 63, 13161, 275, 488, 340, 818, 508, 2833, 14, 8627, 14, 26870, 14, 18473, 587, 413, 267, 1788, 63, 262, 63, 1825, 275, 2833, 14, 2834, 14, 875, 63, 1210, 63, 16376, 8, 288, 359, 1501, 63, 262, 467, 1967, 63, 13161, 29, 1507, 63, 13161, 9, 267, 1788, 63, 548, 63, 1825, 275, 2833, 14, 2834, 14, 875, 63, 1210, 63, 16376, 8, 288, 359, 1501, 63, 548, 467, 1967, 63, 13161, 29, 1507, 63, 13161, 9, 267, 7002, 63, 262, 275, 2833, 14, 1872, 3049, 5929, 342, 267, 7002, 63, 548, 275, 2833, 14, 1872, 3049, 5929, 342, 267, 315, 63, 513, 12, 734, 63, 513, 275, 990, 942, 267, 367, 485, 315, 1425, 8, 1507, 63, 6962, 304, 288, 315, 63, 513, 14, 740, 8, 5503, 63, 262, 14, 739, 8, 1501, 63, 262, 63, 1825, 2788, 17, 566, 288, 734, 63, 513, 14, 740, 8, 5503, 63, 548, 14, 739, 8, 1501, 63, 548, 63, 1825, 2788, 17, 566, 267, 2345, 63, 262, 275, 7002, 63, 262, 14, 739, 8, 1501, 63, 262, 63, 1825, 2788, 17, 61, 267, 2345, 63, 548, 275, 7002, 63, 548, 14, 739, 8, 1501, 63, 548, 63, 1825, 2788, 17, 61, 267, 340, 818, 508, 2833, 14, 8627, 14, 26870, 14, 18473, 26, 288, 4153, 12, 4704, 275, 2833, 14, 2834, 14, 11777, 63, 2912, 8, 355, 334, 3128, 63, 262, 12, 2345, 63, 548, 395, 3522, 63, 890, 12, 14893, 29, 1825, 63, 10457, 12, 355, 1748, 63, 4399, 63, 18522, 29, 2912, 63, 890, 627, 650, 12, 355, 14892, 63, 3479, 29, 549, 288, 776, 267, 587, 26, 288, 4153, 12, 4704, 275, 2833, 14, 2834, 14, 2912, 8, 355, 334, 3128, 63, 262, 12, 2345, 63, 548, 395, 3522, 63, 890, 12, 14893, 29, 1825, 63, 10457, 12, 355, 2040, 63, 24460, 1435, 63, 5094, 63, 2912, 29, 549, 9, 398, 327, 5543, 1412, 4153, 14, 267, 4153, 275, 3778, 14, 4421, 63, 475, 63, 7253, 63, 12263, 8, 3249, 14, 875, 63, 1294, 8, 3711, 395, 1072, 63, 1392, 1524, 2912, 63, 890, 12, 1324, 63, 988, 63, 1267, 467, 849, 63, 585, 15829, 60, 51, 5971, 267, 4704, 275, 3778, 14, 4421, 63, 475, 63, 7253, 63, 12263, 8, 3249, 14, 875, 63, 1294, 8, 4467, 395, 1072, 63, 1392, 1524, 2912, 63, 890, 12, 1072, 63, 988, 63, 1267, 467, 849, 63, 585, 15829, 60, 51, 5971, 267, 2833, 14, 5582, 8, 3711, 59, 16, 467, 536, 534, 3711, 358, 267, 2833, 14, 5582, 8, 4467, 59, 16, 467, 536, 534, 4467, 358, 267, 315, 63, 9953, 275, 2833, 14, 2828, 14, 3892, 14, 1080, 63, 1224, 63, 504, 63, 493, 8, 262, 63, 9953, 63, 493, 12, 11181, 63, 890, 29, 9953, 63, 890, 12, 849, 63, 585, 29, 18, 9, 267, 1324, 63, 1580, 275, 315, 63, 9953, 14, 3892, 8, 3711, 9, 267, 734, 63, 9953, 275, 2833, 14, 2828, 14, 3892, 14, 1080, 63, 1224, 63, 504, 63, 493, 8, 548, 63, 9953, 63, 493, 12, 11181, 63, 890, 29, 9953, 63, 890, 12, 849, 63, 585, 29, 18, 9, 267, 1072, 63, 1580, 275, 734, 63, 9953, 14, 3892, 8, 4467, 9, 267, 372, 791, 3711, 356, 4153, 63, 1580, 12, 283, 4467, 356, 4704, 63, 1580, 1386, 488, 272, 372, 1324, 63, 2324, 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 ]
[ 3228, 465, 2833, 199, 504, 3228, 14, 2828, 492, 9393, 199, 504, 3228, 14, 2828, 492, 12537, 421, 199, 318, 1852, 63, 1210, 63, 2324, 8, 632, 12, 1788, 63, 262, 12, 1788, 63, 548, 12, 315, 63, 9953, 63, 493, 12, 734, 63, 9953, 63, 493, 12, 3522, 63, 890, 12, 11181, 63, 890, 12, 2116, 1324, 63, 988, 63, 1267, 12, 1072, 63, 988, 63, 1267, 12, 4126, 63, 10457, 29, 9943, 12, 1967, 63, 6962, 29, 709, 304, 272, 347, 1324, 63, 2324, 837, 267, 1967, 63, 13161, 275, 488, 340, 818, 508, 2833, 14, 8627, 14, 26870, 14, 18473, 587, 413, 267, 1788, 63, 262, 63, 1825, 275, 2833, 14, 2834, 14, 875, 63, 1210, 63, 16376, 8, 288, 359, 1501, 63, 262, 467, 1967, 63, 13161, 29, 1507, 63, 13161, 9, 267, 1788, 63, 548, 63, 1825, 275, 2833, 14, 2834, 14, 875, 63, 1210, 63, 16376, 8, 288, 359, 1501, 63, 548, 467, 1967, 63, 13161, 29, 1507, 63, 13161, 9, 267, 7002, 63, 262, 275, 2833, 14, 1872, 3049, 5929, 342, 267, 7002, 63, 548, 275, 2833, 14, 1872, 3049, 5929, 342, 267, 315, 63, 513, 12, 734, 63, 513, 275, 990, 942, 267, 367, 485, 315, 1425, 8, 1507, 63, 6962, 304, 288, 315, 63, 513, 14, 740, 8, 5503, 63, 262, 14, 739, 8, 1501, 63, 262, 63, 1825, 2788, 17, 566, 288, 734, 63, 513, 14, 740, 8, 5503, 63, 548, 14, 739, 8, 1501, 63, 548, 63, 1825, 2788, 17, 566, 267, 2345, 63, 262, 275, 7002, 63, 262, 14, 739, 8, 1501, 63, 262, 63, 1825, 2788, 17, 61, 267, 2345, 63, 548, 275, 7002, 63, 548, 14, 739, 8, 1501, 63, 548, 63, 1825, 2788, 17, 61, 267, 340, 818, 508, 2833, 14, 8627, 14, 26870, 14, 18473, 26, 288, 4153, 12, 4704, 275, 2833, 14, 2834, 14, 11777, 63, 2912, 8, 355, 334, 3128, 63, 262, 12, 2345, 63, 548, 395, 3522, 63, 890, 12, 14893, 29, 1825, 63, 10457, 12, 355, 1748, 63, 4399, 63, 18522, 29, 2912, 63, 890, 627, 650, 12, 355, 14892, 63, 3479, 29, 549, 288, 776, 267, 587, 26, 288, 4153, 12, 4704, 275, 2833, 14, 2834, 14, 2912, 8, 355, 334, 3128, 63, 262, 12, 2345, 63, 548, 395, 3522, 63, 890, 12, 14893, 29, 1825, 63, 10457, 12, 355, 2040, 63, 24460, 1435, 63, 5094, 63, 2912, 29, 549, 9, 398, 327, 5543, 1412, 4153, 14, 267, 4153, 275, 3778, 14, 4421, 63, 475, 63, 7253, 63, 12263, 8, 3249, 14, 875, 63, 1294, 8, 3711, 395, 1072, 63, 1392, 1524, 2912, 63, 890, 12, 1324, 63, 988, 63, 1267, 467, 849, 63, 585, 15829, 60, 51, 5971, 267, 4704, 275, 3778, 14, 4421, 63, 475, 63, 7253, 63, 12263, 8, 3249, 14, 875, 63, 1294, 8, 4467, 395, 1072, 63, 1392, 1524, 2912, 63, 890, 12, 1072, 63, 988, 63, 1267, 467, 849, 63, 585, 15829, 60, 51, 5971, 267, 2833, 14, 5582, 8, 3711, 59, 16, 467, 536, 534, 3711, 358, 267, 2833, 14, 5582, 8, 4467, 59, 16, 467, 536, 534, 4467, 358, 267, 315, 63, 9953, 275, 2833, 14, 2828, 14, 3892, 14, 1080, 63, 1224, 63, 504, 63, 493, 8, 262, 63, 9953, 63, 493, 12, 11181, 63, 890, 29, 9953, 63, 890, 12, 849, 63, 585, 29, 18, 9, 267, 1324, 63, 1580, 275, 315, 63, 9953, 14, 3892, 8, 3711, 9, 267, 734, 63, 9953, 275, 2833, 14, 2828, 14, 3892, 14, 1080, 63, 1224, 63, 504, 63, 493, 8, 548, 63, 9953, 63, 493, 12, 11181, 63, 890, 29, 9953, 63, 890, 12, 849, 63, 585, 29, 18, 9, 267, 1072, 63, 1580, 275, 734, 63, 9953, 14, 3892, 8, 4467, 9, 267, 372, 791, 3711, 356, 4153, 63, 1580, 12, 283, 4467, 356, 4704, 63, 1580, 1386, 488, 272, 372, 1324, 63, 2324, 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, 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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SD 3 clause import warnings import numpy as np import scipy.sparse as sp from .base import BaseEstimator, ClassifierMixin, RegressorMixin from .base import MultiOutputMixin from .utils import check_random_state from .utils.validation import _num_samples from .utils.validation import check_array from .utils.validation import check_consistent_length from .utils.validation import check_is_fitted, _check_sample_weight from .utils.random import _random_choice_csc from .utils.stats import _weighted_percentile from .utils.multiclass import class_distribution from .utils.validation import _deprecate_positional_args class DummyClassifier(MultiOutputMixin, ClassifierMixin, BaseEstimator): """ DummyClassifier is a classifier that makes predictions using simple rules. This classifier is useful as a simple baseline to compare with other (real) classifiers. Do not use it for real problems. Read more in the :ref:`User Guide <dummy_estimators>`. .. versionadded:: 0.13 Parameters ---------- strategy : {"stratified", "most_frequent", "prior", "uniform", \ "constant"}, default="prior" Strategy to use to generate predictions. * "stratified": generates predictions by respecting the training set's class distribution. * "most_frequent": always predicts the most frequent label in the training set. * "prior": always predicts the class that maximizes the class prior (like "most_frequent") and ``predict_proba`` returns the class prior. * "uniform": generates predictions uniformly at random. * "constant": always predicts a constant label that is provided by the user. This is useful for metrics that evaluate a non-majority class .. versionchanged:: 0.24 The default value of `strategy` has changed to "prior" in version 0.24. random_state : int, RandomState instance or None, default=None Controls the randomness to generate the predictions when ``strategy='stratified'`` or ``strategy='uniform'``. Pass an int for reproducible output across multiple function calls. See :term:`Glossary <random_state>`. constant : int or str or array-like of shape (n_outputs,) The explicit constant as predicted by the "constant" strategy. This parameter is useful only for the "constant" strategy. Attributes ---------- classes_ : ndarray of shape (n_classes,) or list thereof Class labels for each output. n_classes_ : int or list of int Number of label for each output. class_prior_ : ndarray of shape (n_classes,) or list thereof Probability of each class for each output. n_outputs_ : int Number of outputs. sparse_output_ : bool True if the array returned from predict is to be in sparse CSC format. Is automatically set to True if the input y is passed in sparse format. Examples -------- >>> import numpy as np >>> from sklearn.dummy import DummyClassifier >>> X = np.array([-1, 1, 1, 1]) >>> y = np.array([0, 1, 1, 1]) >>> dummy_clf = DummyClassifier(strategy="most_frequent") >>> dummy_clf.fit(X, y) DummyClassifier(strategy='most_frequent') >>> dummy_clf.predict(X) array([1, 1, 1, 1]) >>> dummy_clf.score(X, y) 0.75 """ @_deprecate_positional_args def __init__(self, *, strategy="prior", random_state=None, constant=None): self.strategy = strategy self.random_state = random_state self.constant = constant def fit(self, X, y, sample_weight=None): """Fit the random classifier. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data. y : array-like of shape (n_samples,) or (n_samples, n_outputs) Target values. sample_weight : array-like of shape (n_samples,), default=None Sample weights. Returns ------- self : object """ allowed_strategies = ("most_frequent", "stratified", "uniform", "constant", "prior") if self.strategy not in allowed_strategies: raise ValueError("Unknown strategy type: %s, expected one of %s." % (self.strategy, allowed_strategies)) self._strategy = self.strategy if self._strategy == "uniform" and sp.issparse(y): y = y.toarray() warnings.warn('A local copy of the target data has been converted ' 'to a numpy array. Predicting on sparse target data ' 'with the uniform strategy would not save memory ' 'and would be slower.', UserWarning) self.sparse_output_ = sp.issparse(y) if not self.sparse_output_: y = np.asarray(y) y = np.atleast_1d(y) if y.ndim == 1: y = np.reshape(y, (-1, 1)) self.n_outputs_ = y.shape[1] self.n_features_in_ = None # No input validation is done for X check_consistent_length(X, y) if sample_weight is not None: sample_weight = _check_sample_weight(sample_weight, X) if self._strategy == "constant": if self.constant is None: raise ValueError("Constant target value has to be specified " "when the constant strategy is used.") else: constant = np.reshape(np.atleast_1d(self.constant), (-1, 1)) if constant.shape[0] != self.n_outputs_: raise ValueError("Constant target value should have " "shape (%d, 1)." % self.n_outputs_) (self.classes_, self.n_classes_, self.class_prior_) = class_distribution(y, sample_weight) if self._strategy == "constant": for k in range(self.n_outputs_): if not any(constant[k][0] == c for c in self.classes_[k]): # Checking in case of constant strategy if the constant # provided by the user is in y. err_msg = ("The constant target value must be present in " "the training data. You provided constant={}. " "Possible values are: {}." .format(self.constant, list(self.classes_[k]))) raise ValueError(err_msg) if self.n_outputs_ == 1: self.n_classes_ = self.n_classes_[0] self.classes_ = self.classes_[0] self.class_prior_ = self.class_prior_[0] return self def predict(self, X): """Perform classification on test vectors X. Parameters ---------- X : array-like of shape (n_samples, n_features) Test data. Returns ------- y : array-like of shape (n_samples,) or (n_samples, n_outputs) Predicted target values for X. """ check_is_fitted(self) # numpy random_state expects Python int and not long as size argument # under Windows n_samples = _num_samples(X) rs = check_random_state(self.random_state) n_classes_ = self.n_classes_ classes_ = self.classes_ class_prior_ = self.class_prior_ constant = self.constant if self.n_outputs_ == 1: # Get same type even for self.n_outputs_ == 1 n_classes_ = [n_classes_] classes_ = [classes_] class_prior_ = [class_prior_] constant = [constant] # Compute probability only once if self._strategy == "stratified": proba = self.predict_proba(X) if self.n_outputs_ == 1: proba = [proba] if self.sparse_output_: class_prob = None if self._strategy in ("most_frequent", "prior"): classes_ = [np.array([cp.argmax()]) for cp in class_prior_] elif self._strategy == "stratified": class_prob = class_prior_ elif self._strategy == "uniform": raise ValueError("Sparse target prediction is not " "supported with the uniform strategy") elif self._strategy == "constant": classes_ = [np.array([c]) for c in constant] y = _random_choice_csc(n_samples, classes_, class_prob, self.random_state) else: if self._strategy in ("most_frequent", "prior"): y = np.tile([classes_[k][class_prior_[k].argmax()] for k in range(self.n_outputs_)], [n_samples, 1]) elif self._strategy == "stratified": y = np.vstack([classes_[k][proba[k].argmax(axis=1)] for k in range(self.n_outputs_)]).T elif self._strategy == "uniform": ret = [classes_[k][rs.randint(n_classes_[k], size=n_samples)] for k in range(self.n_outputs_)] y = np.vstack(ret).T elif self._strategy == "constant": y = np.tile(self.constant, (n_samples, 1)) if self.n_outputs_ == 1: y = np.ravel(y) return y def predict_proba(self, X): """ Return probability estimates for the test vectors X. Parameters ---------- X : array-like of shape (n_samples, n_features) Test data. Returns ------- P : ndarray of shape (n_samples, n_classes) or list thereof Returns the probability of the sample for each class in the model, where classes are ordered arithmetically, for each output. """ check_is_fitted(self) # numpy random_state expects Python int and not long as size argument # under Windows n_samples = _num_samples(X) rs = check_random_state(self.random_state) n_classes_ = self.n_classes_ classes_ = self.classes_ class_prior_ = self.class_prior_ constant = self.constant if self.n_outputs_ == 1: # Get same type even for self.n_outputs_ == 1 n_classes_ = [n_classes_] classes_ = [classes_] class_prior_ = [class_prior_] constant = [constant] P = [] for k in range(self.n_outputs_): if self._strategy == "most_frequent": ind = class_prior_[k].argmax() out = np.zeros((n_samples, n_classes_[k]), dtype=np.float64) out[:, ind] = 1.0 elif self._strategy == "prior": out = np.ones((n_samples, 1)) * class_prior_[k] elif self._strategy == "stratified": out = rs.multinomial(1, class_prior_[k], size=n_samples) out = out.astype(np.float64) elif self._strategy == "uniform": out = np.ones((n_samples, n_classes_[k]), dtype=np.float64) out /= n_classes_[k] elif self._strategy == "constant": ind = np.where(classes_[k] == constant[k]) out = np.zeros((n_samples, n_classes_[k]), dtype=np.float64) out[:, ind] = 1.0 P.append(out) if self.n_outputs_ == 1: P = P[0] return P def predict_log_proba(self, X): """ Return log probability estimates for the test vectors X. Parameters ---------- X : {array-like, object with finite length or shape} Training data, requires length = n_samples Returns ------- P : ndarray of shape (n_samples, n_classes) or list thereof Returns the log probability of the sample for each class in the model, where classes are ordered arithmetically for each output. """ proba = self.predict_proba(X) if self.n_outputs_ == 1: return np.log(proba) else: return [np.log(p) for p in proba] def _more_tags(self): return { 'poor_score': True, 'no_validation': True, '_xfail_checks': { 'check_methods_subset_invariance': 'fails for the predict method', 'check_methods_sample_order_invariance': 'fails for the predict method' } } def score(self, X, y, sample_weight=None): """Returns the mean accuracy on the given test data and labels. In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted. Parameters ---------- X : None or array-like of shape (n_samples, n_features) Test samples. Passing None as test samples gives the same result as passing real test samples, since DummyClassifier operates independently of the sampled observations. y : array-like of shape (n_samples,) or (n_samples, n_outputs) True labels for X. sample_weight : array-like of shape (n_samples,), default=None Sample weights. Returns ------- score : float Mean accuracy of self.predict(X) wrt. y. """ if X is None: X = np.zeros(shape=(len(y), 1)) return super().score(X, y, sample_weight) class DummyRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator): """ DummyRegressor is a regressor that makes predictions using simple rules. This regressor is useful as a simple baseline to compare with other (real) regressors. Do not use it for real problems. Read more in the :ref:`User Guide <dummy_estimators>`. .. versionadded:: 0.13 Parameters ---------- strategy : {"mean", "median", "quantile", "constant"}, default="mean" Strategy to use to generate predictions. * "mean": always predicts the mean of the training set * "median": always predicts the median of the training set * "quantile": always predicts a specified quantile of the training set, provided with the quantile parameter. * "constant": always predicts a constant value that is provided by the user. constant : int or float or array-like of shape (n_outputs,), default=None The explicit constant as predicted by the "constant" strategy. This parameter is useful only for the "constant" strategy. quantile : float in [0.0, 1.0], default=None The quantile to predict using the "quantile" strategy. A quantile of 0.5 corresponds to the median, while 0.0 to the minimum and 1.0 to the maximum. Attributes ---------- constant_ : ndarray of shape (1, n_outputs) Mean or median or quantile of the training targets or constant value given by the user. n_outputs_ : int Number of outputs. Examples -------- >>> import numpy as np >>> from sklearn.dummy import DummyRegressor >>> X = np.array([1.0, 2.0, 3.0, 4.0]) >>> y = np.array([2.0, 3.0, 5.0, 10.0]) >>> dummy_regr = DummyRegressor(strategy="mean") >>> dummy_regr.fit(X, y) DummyRegressor() >>> dummy_regr.predict(X) array([5., 5., 5., 5.]) >>> dummy_regr.score(X, y) 0.0 """ @_deprecate_positional_args def __init__(self, *, strategy="mean", constant=None, quantile=None): self.strategy = strategy self.constant = constant self.quantile = quantile def fit(self, X, y, sample_weight=None): """Fit the random regressor. Parameters ---------- X : array-like of shape (n_samples, n_features) Training data. y : array-like of shape (n_samples,) or (n_samples, n_outputs) Target values. sample_weight : array-like of shape (n_samples,), default=None Sample weights. Returns ------- self : object """ allowed_strategies = ("mean", "median", "quantile", "constant") if self.strategy not in allowed_strategies: raise ValueError("Unknown strategy type: %s, expected one of %s." % (self.strategy, allowed_strategies)) y = check_array(y, ensure_2d=False) self.n_features_in_ = None # No input validation is done for X if len(y) == 0: raise ValueError("y must not be empty.") if y.ndim == 1: y = np.reshape(y, (-1, 1)) self.n_outputs_ = y.shape[1] check_consistent_length(X, y, sample_weight) if sample_weight is not None: sample_weight = _check_sample_weight(sample_weight, X) if self.strategy == "mean": self.constant_ = np.average(y, axis=0, weights=sample_weight) elif self.strategy == "median": if sample_weight is None: self.constant_ = np.median(y, axis=0) else: self.constant_ = [_weighted_percentile(y[:, k], sample_weight, percentile=50.) for k in range(self.n_outputs_)] elif self.strategy == "quantile": if self.quantile is None or not np.isscalar(self.quantile): raise ValueError("Quantile must be a scalar in the range " "[0.0, 1.0], but got %s." % self.quantile) percentile = self.quantile * 100.0 if sample_weight is None: self.constant_ = np.percentile(y, axis=0, q=percentile) else: self.constant_ = [_weighted_percentile(y[:, k], sample_weight, percentile=percentile) for k in range(self.n_outputs_)] elif self.strategy == "constant": if self.constant is None: raise TypeError("Constant target value has to be specified " "when the constant strategy is used.") self.constant = check_array(self.constant, accept_sparse=['csr', 'csc', 'coo'], ensure_2d=False, ensure_min_samples=0) if self.n_outputs_ != 1 and self.constant.shape[0] != y.shape[1]: raise ValueError( "Constant target value should have " "shape (%d, 1)." % y.shape[1]) self.constant_ = self.constant self.constant_ = np.reshape(self.constant_, (1, -1)) return self def predict(self, X, return_std=False): """ Perform classification on test vectors X. Parameters ---------- X : array-like of shape (n_samples, n_features) Test data. return_std : bool, default=False Whether to return the standard deviation of posterior prediction. All zeros in this case. .. versionadded:: 0.20 Returns ------- y : array-like of shape (n_samples,) or (n_samples, n_outputs) Predicted target values for X. y_std : array-like of shape (n_samples,) or (n_samples, n_outputs) Standard deviation of predictive distribution of query points. """ check_is_fitted(self) n_samples = _num_samples(X) y = np.full((n_samples, self.n_outputs_), self.constant_, dtype=np.array(self.constant_).dtype) y_std = np.zeros((n_samples, self.n_outputs_)) if self.n_outputs_ == 1: y = np.ravel(y) y_std = np.ravel(y_std) return (y, y_std) if return_std else y def _more_tags(self): return {'poor_score': True, 'no_validation': True} def score(self, X, y, sample_weight=None): """Returns the coefficient of determination R^2 of the prediction. The coefficient R^2 is defined as (1 - u/v), where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() and v is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R^2 score of 0.0. Parameters ---------- X : None or array-like of shape (n_samples, n_features) Test samples. Passing None as test samples gives the same result as passing real test samples, since DummyRegressor operates independently of the sampled observations. y : array-like of shape (n_samples,) or (n_samples, n_outputs) True values for X. sample_weight : array-like of shape (n_samples,), default=None Sample weights. Returns ------- score : float R^2 of self.predict(X) wrt. y. """ if X is None: X = np.zeros(shape=(len(y), 1)) return super().score(X, y, sample_weight)
bsd-3-clause
[ 3, 6529, 26, 21066, 29364, 699, 5298, 2264, 665, 3442, 29364, 32, 887, 5298, 2264, 14, 1308, 30, 199, 3, 260, 1952, 3540, 1181, 1603, 16242, 665, 65, 14, 74, 16242, 32, 27092, 14, 645, 14, 1235, 30, 199, 3, 260, 603, 11326, 10613, 1151, 11552, 644, 7879, 546, 285, 848, 65, 665, 391, 72, 10613, 1151, 11552, 14, 709, 32, 67, 261, 14, 77, 2591, 14, 645, 14, 23333, 30, 199, 3, 844, 26, 6289, 650, 8502, 199, 199, 646, 3598, 199, 646, 2680, 465, 980, 199, 646, 7026, 14, 4421, 465, 2249, 199, 199, 504, 1275, 1095, 492, 3523, 13183, 12, 8465, 5541, 4256, 12, 799, 3313, 269, 4256, 199, 504, 1275, 1095, 492, 6879, 2959, 4256, 199, 504, 1275, 1208, 492, 1104, 63, 2355, 63, 929, 199, 504, 1275, 1208, 14, 6136, 492, 485, 1507, 63, 3356, 199, 504, 1275, 1208, 14, 6136, 492, 1104, 63, 1144, 199, 504, 1275, 1208, 14, 6136, 492, 1104, 63, 15478, 63, 1267, 199, 504, 1275, 1208, 14, 6136, 492, 1104, 63, 374, 63, 21903, 12, 485, 1074, 63, 3271, 63, 3463, 199, 504, 1275, 1208, 14, 2355, 492, 485, 2355, 63, 5095, 63, 17000, 199, 504, 1275, 1208, 14, 3200, 492, 485, 13522, 63, 21188, 199, 504, 1275, 1208, 14, 30016, 492, 1021, 63, 4972, 199, 504, 1275, 1208, 14, 6136, 492, 485, 27891, 63, 17867, 63, 589, 421, 199, 533, 9762, 8508, 8, 3947, 2959, 4256, 12, 8465, 5541, 4256, 12, 3523, 13183, 304, 272, 408, 272, 9762, 8508, 365, 282, 12429, 626, 7704, 7914, 1808, 3486, 4713, 14, 339, 961, 12429, 365, 2997, 465, 282, 3486, 18828, 370, 6540, 543, 1163, 272, 334, 3093, 9, 19137, 14, 4226, 440, 675, 652, 367, 3363, 8826, 14, 339, 5574, 1655, 315, 314, 520, 1121, 1705, 1899, 15423, 665, 5869, 63, 10646, 14943, 339, 2508, 7445, 447, 378, 14, 969, 339, 3897, 272, 4143, 272, 10054, 520, 2420, 14183, 8981, 401, 298, 2786, 63, 20153, 9333, 401, 298, 13775, 401, 298, 8830, 401, 971, 288, 298, 4083, 6018, 849, 628, 13775, 2, 267, 8303, 5374, 370, 675, 370, 3550, 7914, 14, 398, 627, 298, 14183, 8981, 582, 12821, 7914, 701, 14021, 316, 314, 6093, 881, 663, 1159, 1021, 4084, 14, 267, 627, 298, 2786, 63, 20153, 9333, 582, 3544, 876, 7892, 314, 4750, 28914, 1768, 315, 314, 881, 6093, 663, 14, 267, 627, 298, 13775, 582, 3544, 876, 7892, 314, 1021, 626, 1390, 1017, 6491, 314, 1021, 6791, 881, 334, 2930, 298, 2786, 63, 20153, 9333, 531, 436, 1124, 6892, 63, 14417, 1040, 2529, 314, 1021, 6791, 14, 267, 627, 298, 8830, 582, 12821, 7914, 14818, 590, 737, 2196, 14, 267, 627, 298, 4083, 582, 3544, 876, 7892, 282, 4413, 1768, 626, 365, 2741, 701, 881, 314, 922, 14, 961, 365, 2997, 367, 7186, 626, 9352, 282, 2222, 13, 31611, 3822, 881, 1021, 8592, 2508, 16434, 447, 378, 14, 1194, 1467, 710, 849, 574, 402, 658, 8590, 64, 965, 2896, 370, 298, 13775, 2, 315, 1015, 1467, 378, 14, 1194, 14, 339, 2196, 63, 929, 520, 1109, 12, 22233, 1256, 503, 488, 12, 849, 29, 403, 267, 29001, 314, 2196, 4171, 370, 3550, 314, 7914, 1380, 267, 1124, 8590, 534, 14183, 8981, 14700, 503, 1124, 8590, 534, 8830, 26809, 267, 8325, 376, 1109, 367, 295, 496, 2033, 559, 830, 1072, 9371, 3663, 805, 4882, 14, 267, 1666, 520, 5125, 1705, 39, 4358, 695, 665, 2355, 63, 929, 14943, 339, 4413, 520, 1109, 503, 620, 503, 1625, 13, 2930, 402, 2215, 334, 78, 63, 4467, 4258, 267, 710, 5027, 4413, 465, 14746, 701, 314, 298, 4083, 2, 10054, 14, 961, 267, 2725, 365, 2997, 1454, 367, 314, 298, 4083, 2, 10054, 14, 339, 9382, 272, 4143, 272, 3992, 63, 520, 6800, 402, 2215, 334, 78, 63, 2888, 4258, 503, 769, 2337, 1618, 267, 8089, 3628, 367, 1924, 1072, 14, 339, 302, 63, 2888, 63, 520, 1109, 503, 769, 402, 1109, 267, 4860, 402, 1768, 367, 1924, 1072, 14, 339, 1021, 63, 13775, 63, 520, 6800, 402, 2215, 334, 78, 63, 2888, 4258, 503, 769, 2337, 1618, 267, 22770, 3616, 402, 1924, 1021, 367, 1924, 1072, 14, 339, 302, 63, 4467, 63, 520, 1109, 267, 4860, 402, 4704, 14, 339, 5178, 63, 1199, 63, 520, 2155, 267, 715, 340, 314, 1625, 2138, 687, 12610, 365, 370, 506, 315, 5178, 445, 5153, 1475, 14, 267, 6596, 5847, 663, 370, 715, 340, 314, 1324, 612, 365, 3032, 315, 5178, 1475, 14, 339, 6058, 272, 3001, 272, 1306, 492, 2680, 465, 980, 272, 1306, 687, 6357, 14, 5869, 492, 9762, 8508, 272, 1306, 1323, 275, 980, 14, 1144, 11468, 17, 12, 413, 12, 413, 12, 413, 566, 272, 1306, 612, 275, 980, 14, 1144, 779, 16, 12, 413, 12, 413, 12, 413, 566, 272, 1306, 7283, 63, 9694, 275, 9762, 8508, 8, 8590, 628, 2786, 63, 20153, 9333, 531, 272, 1306, 7283, 63, 9694, 14, 3269, 8, 56, 12, 612, 9, 272, 9762, 8508, 8, 8590, 534, 2786, 63, 20153, 9333, 358, 272, 1306, 7283, 63, 9694, 14, 6892, 8, 56, 9, 272, 1625, 779, 17, 12, 413, 12, 413, 12, 413, 566, 272, 1306, 7283, 63, 9694, 14, 3397, 8, 56, 12, 612, 9, 272, 378, 14, 2194, 272, 408, 272, 19915, 27891, 63, 17867, 63, 589, 272, 347, 636, 826, 721, 277, 12, 9889, 10054, 628, 13775, 401, 2196, 63, 929, 29, 403, 12, 326, 4413, 29, 403, 304, 267, 291, 14, 8590, 275, 10054, 267, 291, 14, 2355, 63, 929, 275, 2196, 63, 929, 267, 291, 14, 4083, 275, 4413, 339, 347, 5542, 8, 277, 12, 1323, 12, 612, 12, 2690, 63, 3463, 29, 403, 304, 267, 408, 13776, 314, 2196, 12429, 14, 398, 3897, 267, 4143, 267, 1323, 520, 1625, 13, 2930, 402, 2215, 334, 78, 63, 3356, 12, 302, 63, 3179, 9, 288, 22859, 666, 14, 398, 612, 520, 1625, 13, 2930, 402, 2215, 334, 78, 63, 3356, 4258, 503, 334, 78, 63, 3356, 12, 302, 63, 4467, 9, 288, 10256, 1338, 14, 398, 2690, 63, 3463, 520, 1625, 13, 2930, 402, 2215, 334, 78, 63, 3356, 4706, 849, 29, 403, 288, 15227, 4931, 14, 398, 1803, 267, 5514, 267, 291, 520, 909, 267, 408 ]
[ 6529, 26, 21066, 29364, 699, 5298, 2264, 665, 3442, 29364, 32, 887, 5298, 2264, 14, 1308, 30, 199, 3, 260, 1952, 3540, 1181, 1603, 16242, 665, 65, 14, 74, 16242, 32, 27092, 14, 645, 14, 1235, 30, 199, 3, 260, 603, 11326, 10613, 1151, 11552, 644, 7879, 546, 285, 848, 65, 665, 391, 72, 10613, 1151, 11552, 14, 709, 32, 67, 261, 14, 77, 2591, 14, 645, 14, 23333, 30, 199, 3, 844, 26, 6289, 650, 8502, 199, 199, 646, 3598, 199, 646, 2680, 465, 980, 199, 646, 7026, 14, 4421, 465, 2249, 199, 199, 504, 1275, 1095, 492, 3523, 13183, 12, 8465, 5541, 4256, 12, 799, 3313, 269, 4256, 199, 504, 1275, 1095, 492, 6879, 2959, 4256, 199, 504, 1275, 1208, 492, 1104, 63, 2355, 63, 929, 199, 504, 1275, 1208, 14, 6136, 492, 485, 1507, 63, 3356, 199, 504, 1275, 1208, 14, 6136, 492, 1104, 63, 1144, 199, 504, 1275, 1208, 14, 6136, 492, 1104, 63, 15478, 63, 1267, 199, 504, 1275, 1208, 14, 6136, 492, 1104, 63, 374, 63, 21903, 12, 485, 1074, 63, 3271, 63, 3463, 199, 504, 1275, 1208, 14, 2355, 492, 485, 2355, 63, 5095, 63, 17000, 199, 504, 1275, 1208, 14, 3200, 492, 485, 13522, 63, 21188, 199, 504, 1275, 1208, 14, 30016, 492, 1021, 63, 4972, 199, 504, 1275, 1208, 14, 6136, 492, 485, 27891, 63, 17867, 63, 589, 421, 199, 533, 9762, 8508, 8, 3947, 2959, 4256, 12, 8465, 5541, 4256, 12, 3523, 13183, 304, 272, 408, 272, 9762, 8508, 365, 282, 12429, 626, 7704, 7914, 1808, 3486, 4713, 14, 339, 961, 12429, 365, 2997, 465, 282, 3486, 18828, 370, 6540, 543, 1163, 272, 334, 3093, 9, 19137, 14, 4226, 440, 675, 652, 367, 3363, 8826, 14, 339, 5574, 1655, 315, 314, 520, 1121, 1705, 1899, 15423, 665, 5869, 63, 10646, 14943, 339, 2508, 7445, 447, 378, 14, 969, 339, 3897, 272, 4143, 272, 10054, 520, 2420, 14183, 8981, 401, 298, 2786, 63, 20153, 9333, 401, 298, 13775, 401, 298, 8830, 401, 971, 288, 298, 4083, 6018, 849, 628, 13775, 2, 267, 8303, 5374, 370, 675, 370, 3550, 7914, 14, 398, 627, 298, 14183, 8981, 582, 12821, 7914, 701, 14021, 316, 314, 6093, 881, 663, 1159, 1021, 4084, 14, 267, 627, 298, 2786, 63, 20153, 9333, 582, 3544, 876, 7892, 314, 4750, 28914, 1768, 315, 314, 881, 6093, 663, 14, 267, 627, 298, 13775, 582, 3544, 876, 7892, 314, 1021, 626, 1390, 1017, 6491, 314, 1021, 6791, 881, 334, 2930, 298, 2786, 63, 20153, 9333, 531, 436, 1124, 6892, 63, 14417, 1040, 2529, 314, 1021, 6791, 14, 267, 627, 298, 8830, 582, 12821, 7914, 14818, 590, 737, 2196, 14, 267, 627, 298, 4083, 582, 3544, 876, 7892, 282, 4413, 1768, 626, 365, 2741, 701, 881, 314, 922, 14, 961, 365, 2997, 367, 7186, 626, 9352, 282, 2222, 13, 31611, 3822, 881, 1021, 8592, 2508, 16434, 447, 378, 14, 1194, 1467, 710, 849, 574, 402, 658, 8590, 64, 965, 2896, 370, 298, 13775, 2, 315, 1015, 1467, 378, 14, 1194, 14, 339, 2196, 63, 929, 520, 1109, 12, 22233, 1256, 503, 488, 12, 849, 29, 403, 267, 29001, 314, 2196, 4171, 370, 3550, 314, 7914, 1380, 267, 1124, 8590, 534, 14183, 8981, 14700, 503, 1124, 8590, 534, 8830, 26809, 267, 8325, 376, 1109, 367, 295, 496, 2033, 559, 830, 1072, 9371, 3663, 805, 4882, 14, 267, 1666, 520, 5125, 1705, 39, 4358, 695, 665, 2355, 63, 929, 14943, 339, 4413, 520, 1109, 503, 620, 503, 1625, 13, 2930, 402, 2215, 334, 78, 63, 4467, 4258, 267, 710, 5027, 4413, 465, 14746, 701, 314, 298, 4083, 2, 10054, 14, 961, 267, 2725, 365, 2997, 1454, 367, 314, 298, 4083, 2, 10054, 14, 339, 9382, 272, 4143, 272, 3992, 63, 520, 6800, 402, 2215, 334, 78, 63, 2888, 4258, 503, 769, 2337, 1618, 267, 8089, 3628, 367, 1924, 1072, 14, 339, 302, 63, 2888, 63, 520, 1109, 503, 769, 402, 1109, 267, 4860, 402, 1768, 367, 1924, 1072, 14, 339, 1021, 63, 13775, 63, 520, 6800, 402, 2215, 334, 78, 63, 2888, 4258, 503, 769, 2337, 1618, 267, 22770, 3616, 402, 1924, 1021, 367, 1924, 1072, 14, 339, 302, 63, 4467, 63, 520, 1109, 267, 4860, 402, 4704, 14, 339, 5178, 63, 1199, 63, 520, 2155, 267, 715, 340, 314, 1625, 2138, 687, 12610, 365, 370, 506, 315, 5178, 445, 5153, 1475, 14, 267, 6596, 5847, 663, 370, 715, 340, 314, 1324, 612, 365, 3032, 315, 5178, 1475, 14, 339, 6058, 272, 3001, 272, 1306, 492, 2680, 465, 980, 272, 1306, 687, 6357, 14, 5869, 492, 9762, 8508, 272, 1306, 1323, 275, 980, 14, 1144, 11468, 17, 12, 413, 12, 413, 12, 413, 566, 272, 1306, 612, 275, 980, 14, 1144, 779, 16, 12, 413, 12, 413, 12, 413, 566, 272, 1306, 7283, 63, 9694, 275, 9762, 8508, 8, 8590, 628, 2786, 63, 20153, 9333, 531, 272, 1306, 7283, 63, 9694, 14, 3269, 8, 56, 12, 612, 9, 272, 9762, 8508, 8, 8590, 534, 2786, 63, 20153, 9333, 358, 272, 1306, 7283, 63, 9694, 14, 6892, 8, 56, 9, 272, 1625, 779, 17, 12, 413, 12, 413, 12, 413, 566, 272, 1306, 7283, 63, 9694, 14, 3397, 8, 56, 12, 612, 9, 272, 378, 14, 2194, 272, 408, 272, 19915, 27891, 63, 17867, 63, 589, 272, 347, 636, 826, 721, 277, 12, 9889, 10054, 628, 13775, 401, 2196, 63, 929, 29, 403, 12, 326, 4413, 29, 403, 304, 267, 291, 14, 8590, 275, 10054, 267, 291, 14, 2355, 63, 929, 275, 2196, 63, 929, 267, 291, 14, 4083, 275, 4413, 339, 347, 5542, 8, 277, 12, 1323, 12, 612, 12, 2690, 63, 3463, 29, 403, 304, 267, 408, 13776, 314, 2196, 12429, 14, 398, 3897, 267, 4143, 267, 1323, 520, 1625, 13, 2930, 402, 2215, 334, 78, 63, 3356, 12, 302, 63, 3179, 9, 288, 22859, 666, 14, 398, 612, 520, 1625, 13, 2930, 402, 2215, 334, 78, 63, 3356, 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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 ]
insidenothing/3D-Printing-Software
skein_engines/skeinforge-35/fabmetheus_utilities/geometry/solids/cube.py
6
3514
""" This page is in the table of contents. The xml.py script is an import translator plugin to get a carving from an Art of Illusion xml file. An import plugin is a script in the interpret_plugins folder which has the function getCarving. It is meant to be run from the interpret tool. To ensure that the plugin works on platforms which do not handle file capitalization properly, give the plugin a lower case name. The getCarving function takes the file name of an xml file and returns the carving. This example gets a triangle mesh for the xml file boolean.xml. This example is run in a terminal in the folder which contains boolean.xml and xml.py. > python Python 2.5.1 (r251:54863, Sep 22 2007, 01:43:31) [GCC 4.2.1 (SUSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import xml >>> xml.getCarving().getCarveRotatedBoundaryLayers() [-1.159765625, None, [[(-18.925000000000001-2.4550000000000001j), (-18.754999999999981-2.4550000000000001j) .. many more lines of the carving .. An xml file can be exported from Art of Illusion by going to the "File" menu, then going into the "Export" menu item, then picking the XML choice. This will bring up the XML file chooser window, choose a place to save the file then click "OK". Leave the "compressFile" checkbox unchecked. All the objects from the scene will be exported, this plugin will ignore the light and camera. If you want to fabricate more than one object at a time, you can have multiple objects in the Art of Illusion scene and they will all be carved, then fabricated together. """ from __future__ import absolute_import #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module. import __init__ from fabmetheus_utilities.geometry.geometry_utilities import evaluate from fabmetheus_utilities.geometry.solids import group from fabmetheus_utilities.geometry.solids import trianglemesh from fabmetheus_utilities.vector3 import Vector3 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)' __credits__ = 'Nophead <http://hydraraptor.blogspot.com/>\nArt of Illusion <http://www.artofillusion.org/>' __date__ = '$Date: 2008/21/04 $' __license__ = 'GPL 3.0' def processXMLElement(xmlElement): "Process the xml element." group.processShape( Cube, xmlElement) class Cube( trianglemesh.TriangleMesh ): "A cube object." def addXMLSection(self, depth, output): "Add the xml section for this object." pass def createShape(self): "Create the shape." square = [ complex( - self.inradius.x, - self.inradius.y ), complex( self.inradius.x, - self.inradius.y ), complex( self.inradius.x, self.inradius.y ), complex( - self.inradius.x, self.inradius.y ) ] bottomTopSquare = trianglemesh.getAddIndexedLoops( square, self.vertexes, [ - self.inradius.z, self.inradius.z ] ) trianglemesh.addPillarByLoops( self.faces, bottomTopSquare ) def setToObjectAttributeDictionary(self): "Set the shape of this carvable object info." self.inradius = evaluate.getVector3ByPrefixes( ['demisize', 'inradius'], Vector3(1.0, 1.0, 1.0), self.xmlElement ) self.inradius = evaluate.getVector3ByMultiplierPrefix( 2.0, 'size', self.inradius, self.xmlElement ) self.xmlElement.attributeDictionary['inradius.x'] = self.inradius.x self.xmlElement.attributeDictionary['inradius.y'] = self.inradius.y self.xmlElement.attributeDictionary['inradius.z'] = self.inradius.z self.createShape()
gpl-2.0
[ 624, 199, 2765, 2034, 365, 315, 314, 1817, 402, 4072, 14, 199, 1918, 2748, 14, 647, 2884, 365, 376, 492, 32034, 3589, 370, 664, 282, 9590, 4007, 687, 376, 1952, 84, 402, 473, 914, 12444, 2748, 570, 14, 199, 199, 2493, 492, 3589, 365, 282, 2884, 315, 314, 15579, 63, 5265, 4922, 1314, 965, 314, 805, 664, 16034, 4007, 14, 221, 2779, 365, 18329, 370, 506, 1255, 687, 314, 15579, 4744, 14, 221, 4005, 4868, 626, 314, 3589, 5419, 641, 10677, 1314, 886, 440, 2429, 570, 17094, 2072, 7684, 12, 8120, 314, 3589, 282, 5117, 1930, 536, 14, 199, 199, 1918, 664, 16034, 4007, 805, 6181, 314, 570, 536, 402, 376, 2748, 570, 436, 2529, 314, 9590, 4007, 14, 199, 199, 2765, 2893, 7545, 282, 26268, 9364, 367, 314, 2748, 570, 5046, 14, 1652, 14, 221, 961, 2893, 365, 1255, 315, 282, 11167, 315, 314, 4922, 1314, 3509, 5046, 14, 1652, 436, 2748, 14, 647, 14, 421, 199, 30, 2366, 199, 4718, 499, 14, 21, 14, 17, 334, 82, 12140, 26, 1477, 15887, 12, 428, 1545, 6928, 10219, 12, 17163, 26, 2824, 26, 2192, 9, 199, 59, 10566, 841, 14, 18, 14, 17, 334, 51, 4701, 10130, 1874, 641, 18369, 18, 199, 804, 298, 3437, 401, 298, 7307, 401, 298, 22461, 2, 503, 298, 1682, 2, 367, 1655, 2556, 14, 199, 6071, 492, 2748, 199, 6071, 2748, 14, 362, 16034, 4007, 1252, 362, 16034, 432, 14728, 972, 19831, 16862, 342, 199, 1988, 17, 14, 9327, 2114, 1367, 821, 12, 488, 12, 3474, 2801, 1085, 14, 32503, 20625, 614, 13, 18, 14, 13267, 15672, 17, 74, 395, 5868, 1085, 14, 13332, 13453, 1020, 2835, 13, 18, 14, 13267, 15672, 17, 74, 9, 199, 703, 199, 3479, 1655, 2385, 402, 314, 9590, 4007, 199, 703, 421, 199, 2493, 2748, 570, 883, 506, 16629, 687, 1952, 84, 402, 473, 914, 12444, 701, 9995, 370, 314, 298, 1173, 2, 6269, 12, 2066, 9995, 1901, 314, 298, 11399, 2, 6269, 1242, 12, 2066, 12433, 314, 4692, 7141, 14, 221, 961, 911, 330, 5985, 1536, 314, 4692, 570, 2468, 13041, 4353, 12, 11496, 282, 4192, 370, 3354, 314, 570, 2066, 8968, 298, 3593, 1674, 221, 28015, 314, 298, 6447, 1173, 2, 24190, 625, 10718, 14, 221, 2900, 314, 2251, 687, 314, 13856, 911, 506, 16629, 12, 642, 3589, 911, 3686, 314, 10540, 436, 15177, 14, 221, 982, 1265, 2934, 370, 31507, 322, 1411, 1655, 2419, 1373, 909, 737, 282, 900, 12, 1265, 883, 1172, 3663, 2251, 315, 314, 1952, 84, 402, 473, 914, 12444, 13856, 436, 2985, 911, 1006, 506, 9590, 1354, 12, 2066, 2630, 972, 10451, 14, 199, 199, 624, 421, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 3, 9346, 965, 370, 506, 8439, 1642, 2952, 652, 965, 1233, 370, 18092, 314, 2366, 6519, 2382, 3847, 8925, 2793, 1133, 1736, 340, 314, 859, 365, 8439, 465, 282, 2446, 859, 14, 199, 646, 636, 826, 363, 199, 199, 504, 31507, 278, 32761, 63, 16355, 14, 7660, 14, 7660, 63, 16355, 492, 9352, 199, 504, 31507, 278, 32761, 63, 16355, 14, 7660, 14, 28335, 795, 492, 1572, 199, 504, 31507, 278, 32761, 63, 16355, 14, 7660, 14, 28335, 795, 492, 26268, 6480, 199, 504, 31507, 278, 32761, 63, 16355, 14, 4106, 19, 492, 11388, 19, 421, 199, 363, 2502, 363, 275, 283, 1327, 322, 544, 11379, 25409, 334, 321, 25409, 63, 287, 322, 544, 32, 27231, 14, 957, 3171, 199, 363, 22461, 363, 275, 283, 46, 411, 2993, 665, 1014, 921, 3577, 5012, 285, 6182, 269, 14, 66, 7270, 14173, 14, 957, 15, 3072, 78, 28922, 402, 473, 914, 12444, 665, 1014, 921, 1544, 14, 285, 475, 4498, 12444, 14, 1308, 3133, 7, 199, 363, 602, 363, 275, 4505, 2506, 26, 9079, 15, 2025, 15, 966, 2672, 7, 199, 363, 1682, 363, 275, 283, 12006, 650, 14, 16, 7, 421, 199, 318, 2112, 13901, 906, 968, 8, 1652, 2162, 304, 199, 198, 2, 3498, 314, 2748, 1819, 2122, 199, 198, 923, 14, 1412, 7238, 8, 445, 3375, 12, 2748, 2162, 9, 421, 199, 533, 445, 3375, 8, 26268, 6480, 14, 30402, 12241, 3461, 199, 198, 2, 33, 15681, 909, 2122, 199, 198, 318, 1050, 4317, 8660, 8, 277, 12, 5818, 12, 1072, 304, 507, 198, 2, 1123, 314, 2748, 3420, 367, 642, 909, 2122, 507, 198, 1529, 421, 198, 318, 1218, 7238, 8, 277, 304, 507, 198, 2, 2499, 314, 2215, 2122, 507, 198, 9646, 275, 359, 686, 198, 5254, 8, 446, 291, 14, 262, 8017, 14, 88, 12, 446, 291, 14, 262, 8017, 14, 89, 2318, 686, 198, 5254, 8, 291, 14, 262, 8017, 14, 88, 12, 446, 291, 14, 262, 8017, 14, 89, 2318, 686, 198, 5254, 8, 291, 14, 262, 8017, 14, 88, 12, 291, 14, 262, 8017, 14, 89, 2318, 686, 198, 5254, 8, 446, 291, 14, 262, 8017, 14, 88, 12, 291, 14, 262, 8017, 14, 89, 776, 1622, 507, 198, 8305, 6105, 23373, 275, 26268, 6480, 14, 362, 1123, 19067, 2041, 1483, 8, 12386, 12, 291, 14, 11417, 397, 12, 359, 446, 291, 14, 262, 8017, 14, 90, 12, 291, 14, 262, 8017, 14, 90, 1622, 776, 507, 198, 21584, 6480, 14, 525, 48, 778, 285, 2175, 2041, 1483, 8, 291, 14, 4309, 12, 9048, 6105, 23373, 776, 421, 198, 318, 663, 1378, 1692, 1646, 11728, 8, 277, 304, 507, 198, 2, 1084, 314, 2215, 402, 642, 9590, 30456, 909, 2256, 2122, 507, 198, 277, 14, 262, 8017, 275, 9352, 14, 362, 3646, 19, 2175, 4793, 397, 8, 788, 271, 2664, 890, 297, 283, 262, 8017, 995, 11388, 19, 8, 17, 14, 16, 12, 413, 14, 16, 12, 413, 14, 16, 395, 291, 14, 1652, 2162, 776, 507, 198, 277, 14, 262, 8017, 275, 9352, 14, 362, 3646, 19, 2175, 25314, 5697, 4793, 8, 499, 14, 16, 12, 283, 890, 297, 291, 14, 262, 8017, 12, 291, 14, 1652, 2162, 776, 507, 198, 277, 14, 1652, 2162, 14, 3215, 11728, 459, 262, 8017, 14, 88, 418, 275, 291, 14, 262, 8017, 14, 88, 507, 198, 277, 14, 1652, 2162, 14, 3215, 11728, 459, 262, 8017, 14, 89, 418, 275, 291, 14, 262, 8017, 14, 89, 507, 198, 277, 14, 1652, 2162, 14 ]
[ 199, 2765, 2034, 365, 315, 314, 1817, 402, 4072, 14, 199, 1918, 2748, 14, 647, 2884, 365, 376, 492, 32034, 3589, 370, 664, 282, 9590, 4007, 687, 376, 1952, 84, 402, 473, 914, 12444, 2748, 570, 14, 199, 199, 2493, 492, 3589, 365, 282, 2884, 315, 314, 15579, 63, 5265, 4922, 1314, 965, 314, 805, 664, 16034, 4007, 14, 221, 2779, 365, 18329, 370, 506, 1255, 687, 314, 15579, 4744, 14, 221, 4005, 4868, 626, 314, 3589, 5419, 641, 10677, 1314, 886, 440, 2429, 570, 17094, 2072, 7684, 12, 8120, 314, 3589, 282, 5117, 1930, 536, 14, 199, 199, 1918, 664, 16034, 4007, 805, 6181, 314, 570, 536, 402, 376, 2748, 570, 436, 2529, 314, 9590, 4007, 14, 199, 199, 2765, 2893, 7545, 282, 26268, 9364, 367, 314, 2748, 570, 5046, 14, 1652, 14, 221, 961, 2893, 365, 1255, 315, 282, 11167, 315, 314, 4922, 1314, 3509, 5046, 14, 1652, 436, 2748, 14, 647, 14, 421, 199, 30, 2366, 199, 4718, 499, 14, 21, 14, 17, 334, 82, 12140, 26, 1477, 15887, 12, 428, 1545, 6928, 10219, 12, 17163, 26, 2824, 26, 2192, 9, 199, 59, 10566, 841, 14, 18, 14, 17, 334, 51, 4701, 10130, 1874, 641, 18369, 18, 199, 804, 298, 3437, 401, 298, 7307, 401, 298, 22461, 2, 503, 298, 1682, 2, 367, 1655, 2556, 14, 199, 6071, 492, 2748, 199, 6071, 2748, 14, 362, 16034, 4007, 1252, 362, 16034, 432, 14728, 972, 19831, 16862, 342, 199, 1988, 17, 14, 9327, 2114, 1367, 821, 12, 488, 12, 3474, 2801, 1085, 14, 32503, 20625, 614, 13, 18, 14, 13267, 15672, 17, 74, 395, 5868, 1085, 14, 13332, 13453, 1020, 2835, 13, 18, 14, 13267, 15672, 17, 74, 9, 199, 703, 199, 3479, 1655, 2385, 402, 314, 9590, 4007, 199, 703, 421, 199, 2493, 2748, 570, 883, 506, 16629, 687, 1952, 84, 402, 473, 914, 12444, 701, 9995, 370, 314, 298, 1173, 2, 6269, 12, 2066, 9995, 1901, 314, 298, 11399, 2, 6269, 1242, 12, 2066, 12433, 314, 4692, 7141, 14, 221, 961, 911, 330, 5985, 1536, 314, 4692, 570, 2468, 13041, 4353, 12, 11496, 282, 4192, 370, 3354, 314, 570, 2066, 8968, 298, 3593, 1674, 221, 28015, 314, 298, 6447, 1173, 2, 24190, 625, 10718, 14, 221, 2900, 314, 2251, 687, 314, 13856, 911, 506, 16629, 12, 642, 3589, 911, 3686, 314, 10540, 436, 15177, 14, 221, 982, 1265, 2934, 370, 31507, 322, 1411, 1655, 2419, 1373, 909, 737, 282, 900, 12, 1265, 883, 1172, 3663, 2251, 315, 314, 1952, 84, 402, 473, 914, 12444, 13856, 436, 2985, 911, 1006, 506, 9590, 1354, 12, 2066, 2630, 972, 10451, 14, 199, 199, 624, 421, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 3, 9346, 965, 370, 506, 8439, 1642, 2952, 652, 965, 1233, 370, 18092, 314, 2366, 6519, 2382, 3847, 8925, 2793, 1133, 1736, 340, 314, 859, 365, 8439, 465, 282, 2446, 859, 14, 199, 646, 636, 826, 363, 199, 199, 504, 31507, 278, 32761, 63, 16355, 14, 7660, 14, 7660, 63, 16355, 492, 9352, 199, 504, 31507, 278, 32761, 63, 16355, 14, 7660, 14, 28335, 795, 492, 1572, 199, 504, 31507, 278, 32761, 63, 16355, 14, 7660, 14, 28335, 795, 492, 26268, 6480, 199, 504, 31507, 278, 32761, 63, 16355, 14, 4106, 19, 492, 11388, 19, 421, 199, 363, 2502, 363, 275, 283, 1327, 322, 544, 11379, 25409, 334, 321, 25409, 63, 287, 322, 544, 32, 27231, 14, 957, 3171, 199, 363, 22461, 363, 275, 283, 46, 411, 2993, 665, 1014, 921, 3577, 5012, 285, 6182, 269, 14, 66, 7270, 14173, 14, 957, 15, 3072, 78, 28922, 402, 473, 914, 12444, 665, 1014, 921, 1544, 14, 285, 475, 4498, 12444, 14, 1308, 3133, 7, 199, 363, 602, 363, 275, 4505, 2506, 26, 9079, 15, 2025, 15, 966, 2672, 7, 199, 363, 1682, 363, 275, 283, 12006, 650, 14, 16, 7, 421, 199, 318, 2112, 13901, 906, 968, 8, 1652, 2162, 304, 199, 198, 2, 3498, 314, 2748, 1819, 2122, 199, 198, 923, 14, 1412, 7238, 8, 445, 3375, 12, 2748, 2162, 9, 421, 199, 533, 445, 3375, 8, 26268, 6480, 14, 30402, 12241, 3461, 199, 198, 2, 33, 15681, 909, 2122, 199, 198, 318, 1050, 4317, 8660, 8, 277, 12, 5818, 12, 1072, 304, 507, 198, 2, 1123, 314, 2748, 3420, 367, 642, 909, 2122, 507, 198, 1529, 421, 198, 318, 1218, 7238, 8, 277, 304, 507, 198, 2, 2499, 314, 2215, 2122, 507, 198, 9646, 275, 359, 686, 198, 5254, 8, 446, 291, 14, 262, 8017, 14, 88, 12, 446, 291, 14, 262, 8017, 14, 89, 2318, 686, 198, 5254, 8, 291, 14, 262, 8017, 14, 88, 12, 446, 291, 14, 262, 8017, 14, 89, 2318, 686, 198, 5254, 8, 291, 14, 262, 8017, 14, 88, 12, 291, 14, 262, 8017, 14, 89, 2318, 686, 198, 5254, 8, 446, 291, 14, 262, 8017, 14, 88, 12, 291, 14, 262, 8017, 14, 89, 776, 1622, 507, 198, 8305, 6105, 23373, 275, 26268, 6480, 14, 362, 1123, 19067, 2041, 1483, 8, 12386, 12, 291, 14, 11417, 397, 12, 359, 446, 291, 14, 262, 8017, 14, 90, 12, 291, 14, 262, 8017, 14, 90, 1622, 776, 507, 198, 21584, 6480, 14, 525, 48, 778, 285, 2175, 2041, 1483, 8, 291, 14, 4309, 12, 9048, 6105, 23373, 776, 421, 198, 318, 663, 1378, 1692, 1646, 11728, 8, 277, 304, 507, 198, 2, 1084, 314, 2215, 402, 642, 9590, 30456, 909, 2256, 2122, 507, 198, 277, 14, 262, 8017, 275, 9352, 14, 362, 3646, 19, 2175, 4793, 397, 8, 788, 271, 2664, 890, 297, 283, 262, 8017, 995, 11388, 19, 8, 17, 14, 16, 12, 413, 14, 16, 12, 413, 14, 16, 395, 291, 14, 1652, 2162, 776, 507, 198, 277, 14, 262, 8017, 275, 9352, 14, 362, 3646, 19, 2175, 25314, 5697, 4793, 8, 499, 14, 16, 12, 283, 890, 297, 291, 14, 262, 8017, 12, 291, 14, 1652, 2162, 776, 507, 198, 277, 14, 1652, 2162, 14, 3215, 11728, 459, 262, 8017, 14, 88, 418, 275, 291, 14, 262, 8017, 14, 88, 507, 198, 277, 14, 1652, 2162, 14, 3215, 11728, 459, 262, 8017, 14, 89, 418, 275, 291, 14, 262, 8017, 14, 89, 507, 198, 277, 14, 1652, 2162, 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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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 ]
alx-eu/django
django/contrib/localflavor/de/forms.py
110
3266
""" DE-specific Form helpers """ from __future__ import absolute_import, unicode_literals import re from django.contrib.localflavor.de.de_states import STATE_CHOICES from django.core.validators import EMPTY_VALUES from django.forms import ValidationError from django.forms.fields import Field, RegexField, Select from django.utils.translation import ugettext_lazy as _ id_re = re.compile(r"^(?P<residence>\d{10})(?P<origin>\w{1,3})[-\ ]?(?P<birthday>\d{7})[-\ ]?(?P<validity>\d{7})[-\ ]?(?P<checksum>\d{1})$") class DEZipCodeField(RegexField): default_error_messages = { 'invalid': _('Enter a zip code in the format XXXXX.'), } def __init__(self, max_length=None, min_length=None, *args, **kwargs): super(DEZipCodeField, self).__init__(r'^\d{5}$', max_length, min_length, *args, **kwargs) class DEStateSelect(Select): """ A Select widget that uses a list of DE states as its choices. """ def __init__(self, attrs=None): super(DEStateSelect, self).__init__(attrs, choices=STATE_CHOICES) class DEIdentityCardNumberField(Field): """ A German identity card number. Checks the following rules to determine whether the number is valid: * Conforms to the XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format. * No group consists entirely of zeroes. * Included checksums match calculated checksums Algorithm is documented at http://de.wikipedia.org/wiki/Personalausweis """ default_error_messages = { 'invalid': _('Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.'), } def has_valid_checksum(self, number): given_number, given_checksum = number[:-1], number[-1] calculated_checksum = 0 fragment = "" parameter = 7 for i in range(len(given_number)): fragment = str(int(given_number[i]) * parameter) if fragment.isalnum(): calculated_checksum += int(fragment[-1]) if parameter == 1: parameter = 7 elif parameter == 3: parameter = 1 elif parameter ==7: parameter = 3 return str(calculated_checksum)[-1] == given_checksum def clean(self, value): super(DEIdentityCardNumberField, self).clean(value) if value in EMPTY_VALUES: return '' match = re.match(id_re, value) if not match: raise ValidationError(self.error_messages['invalid']) gd = match.groupdict() residence, origin = gd['residence'], gd['origin'] birthday, validity, checksum = gd['birthday'], gd['validity'], gd['checksum'] if residence == '0000000000' or birthday == '0000000' or validity == '0000000': raise ValidationError(self.error_messages['invalid']) all_digits = "%s%s%s%s" % (residence, birthday, validity, checksum) if not self.has_valid_checksum(residence) or not self.has_valid_checksum(birthday) or \ not self.has_valid_checksum(validity) or not self.has_valid_checksum(all_digits): raise ValidationError(self.error_messages['invalid']) return '%s%s-%s-%s-%s' % (residence, origin, birthday, validity, checksum)
bsd-3-clause
[ 624, 199, 1093, 13, 6100, 8204, 10897, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 2649, 63, 5955, 199, 199, 646, 295, 199, 199, 504, 1639, 14, 2828, 14, 320, 696, 276, 4271, 14, 271, 14, 271, 63, 4981, 492, 11377, 63, 16236, 199, 504, 1639, 14, 1018, 14, 11346, 492, 16589, 63, 15514, 199, 504, 1639, 14, 3351, 492, 8505, 199, 504, 1639, 14, 3351, 14, 955, 492, 5024, 12, 12939, 792, 12, 9496, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 421, 199, 344, 63, 264, 275, 295, 14, 2014, 8, 82, 16136, 2229, 48, 28, 20807, 5606, 3072, 68, 91, 709, 1552, 2229, 48, 28, 6493, 3072, 87, 91, 17, 12, 19, 1552, 1988, 60, 1622, 31, 2229, 48, 28, 15881, 3072, 68, 91, 23, 1552, 1988, 60, 1622, 31, 2229, 48, 28, 31901, 3072, 68, 91, 23, 1552, 1988, 60, 1622, 31, 2229, 48, 28, 8928, 3072, 68, 91, 17, 1552, 22550, 199, 199, 533, 3265, 8674, 3034, 792, 8, 5103, 792, 304, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 8468, 282, 3482, 1233, 315, 314, 1475, 5787, 2483, 8038, 272, 789, 272, 347, 636, 826, 721, 277, 12, 1390, 63, 1267, 29, 403, 12, 1748, 63, 1267, 29, 403, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 1093, 8674, 3034, 792, 12, 291, 2843, 826, 721, 82, 15542, 68, 91, 21, 19204, 288, 1390, 63, 1267, 12, 1748, 63, 1267, 12, 627, 589, 12, 1011, 958, 9, 199, 199, 533, 11758, 84, 323, 5446, 8, 5446, 304, 272, 408, 272, 437, 9496, 3938, 626, 4440, 282, 769, 402, 3265, 6363, 465, 2399, 3415, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 3290, 29, 403, 304, 267, 1613, 8, 4448, 84, 323, 5446, 12, 291, 2843, 826, 721, 3288, 12, 3415, 29, 6689, 63, 16236, 9, 199, 199, 533, 3265, 10193, 13832, 3259, 792, 8, 792, 304, 272, 408, 272, 437, 22261, 1237, 8503, 12564, 1329, 14, 339, 13813, 314, 2569, 4713, 370, 6705, 3775, 314, 1329, 365, 1686, 26, 398, 627, 1448, 3351, 370, 314, 5787, 13312, 13, 6873, 13933, 13, 6873, 13933, 13, 56, 1475, 14, 267, 627, 3091, 1572, 18581, 21926, 402, 4697, 397, 14, 267, 627, 32732, 9040, 83, 1336, 12950, 9040, 83, 339, 23823, 365, 22751, 737, 1455, 921, 271, 14, 13961, 14, 1308, 15, 6797, 15, 7344, 14774, 527, 1129, 374, 272, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 8468, 282, 1686, 22261, 1237, 8503, 12564, 1329, 315, 5787, 13312, 13, 6873, 13933, 13, 6873, 13933, 13, 56, 1475, 8038, 272, 789, 339, 347, 965, 63, 1078, 63, 8928, 8, 277, 12, 1329, 304, 267, 1627, 63, 1955, 12, 1627, 63, 8928, 275, 1329, 4439, 17, 467, 1329, 1988, 17, 61, 267, 12950, 63, 8928, 275, 378, 267, 7956, 275, 3087, 267, 2725, 275, 1520, 398, 367, 284, 315, 1425, 8, 552, 8, 11809, 63, 1955, 2298, 288, 7956, 275, 620, 8, 442, 8, 11809, 63, 1955, 59, 73, 566, 627, 2725, 9, 288, 340, 7956, 14, 28235, 1507, 837, 355, 12950, 63, 8928, 847, 1109, 8, 7677, 1988, 17, 566, 288, 340, 2725, 508, 413, 26, 355, 2725, 275, 1520, 288, 916, 2725, 508, 650, 26, 355, 2725, 275, 413, 288, 916, 2725, 508, 23, 26, 355, 2725, 275, 650, 398, 372, 620, 8, 13494, 972, 63, 8928, 15786, 17, 61, 508, 1627, 63, 8928, 339, 347, 3633, 8, 277, 12, 574, 304, 267, 1613, 8, 1093, 10193, 13832, 3259, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 2125, 267, 1336, 275, 295, 14, 1431, 8, 344, 63, 264, 12, 574, 9, 267, 340, 440, 1336, 26, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 24714, 275, 1336, 14, 20567, 342, 267, 28633, 5606, 12, 6330, 275, 24714, 459, 20807, 5606, 995, 24714, 459, 6493, 418, 267, 21036, 2977, 12, 25667, 12, 9040, 275, 24714, 459, 15881, 995, 24714, 459, 31901, 995, 24714, 459, 8928, 418, 398, 340, 28633, 5606, 508, 283, 20625, 7, 503, 21036, 2977, 508, 283, 9084, 7, 503, 25667, 508, 283, 9084, 356, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 1006, 63, 7022, 275, 2071, 83, 5, 83, 5, 83, 5, 83, 2, 450, 334, 20807, 5606, 12, 21036, 2977, 12, 25667, 12, 9040, 9, 267, 340, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 20807, 5606, 9, 503, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 15881, 9, 503, 971, 288, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 31901, 9, 503, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 452, 63, 7022, 304, 355, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 372, 1543, 83, 5, 83, 3295, 83, 3295, 83, 3295, 83, 7, 450, 334, 20807, 5606, 12, 6330, 12, 21036, 2977, 12, 25667, 12, 9040, 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 ]
[ 199, 1093, 13, 6100, 8204, 10897, 199, 624, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 2649, 63, 5955, 199, 199, 646, 295, 199, 199, 504, 1639, 14, 2828, 14, 320, 696, 276, 4271, 14, 271, 14, 271, 63, 4981, 492, 11377, 63, 16236, 199, 504, 1639, 14, 1018, 14, 11346, 492, 16589, 63, 15514, 199, 504, 1639, 14, 3351, 492, 8505, 199, 504, 1639, 14, 3351, 14, 955, 492, 5024, 12, 12939, 792, 12, 9496, 199, 504, 1639, 14, 1208, 14, 6893, 492, 10366, 63, 6395, 465, 485, 421, 199, 344, 63, 264, 275, 295, 14, 2014, 8, 82, 16136, 2229, 48, 28, 20807, 5606, 3072, 68, 91, 709, 1552, 2229, 48, 28, 6493, 3072, 87, 91, 17, 12, 19, 1552, 1988, 60, 1622, 31, 2229, 48, 28, 15881, 3072, 68, 91, 23, 1552, 1988, 60, 1622, 31, 2229, 48, 28, 31901, 3072, 68, 91, 23, 1552, 1988, 60, 1622, 31, 2229, 48, 28, 8928, 3072, 68, 91, 17, 1552, 22550, 199, 199, 533, 3265, 8674, 3034, 792, 8, 5103, 792, 304, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 8468, 282, 3482, 1233, 315, 314, 1475, 5787, 2483, 8038, 272, 789, 272, 347, 636, 826, 721, 277, 12, 1390, 63, 1267, 29, 403, 12, 1748, 63, 1267, 29, 403, 12, 627, 589, 12, 1011, 958, 304, 267, 1613, 8, 1093, 8674, 3034, 792, 12, 291, 2843, 826, 721, 82, 15542, 68, 91, 21, 19204, 288, 1390, 63, 1267, 12, 1748, 63, 1267, 12, 627, 589, 12, 1011, 958, 9, 199, 199, 533, 11758, 84, 323, 5446, 8, 5446, 304, 272, 408, 272, 437, 9496, 3938, 626, 4440, 282, 769, 402, 3265, 6363, 465, 2399, 3415, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 3290, 29, 403, 304, 267, 1613, 8, 4448, 84, 323, 5446, 12, 291, 2843, 826, 721, 3288, 12, 3415, 29, 6689, 63, 16236, 9, 199, 199, 533, 3265, 10193, 13832, 3259, 792, 8, 792, 304, 272, 408, 272, 437, 22261, 1237, 8503, 12564, 1329, 14, 339, 13813, 314, 2569, 4713, 370, 6705, 3775, 314, 1329, 365, 1686, 26, 398, 627, 1448, 3351, 370, 314, 5787, 13312, 13, 6873, 13933, 13, 6873, 13933, 13, 56, 1475, 14, 267, 627, 3091, 1572, 18581, 21926, 402, 4697, 397, 14, 267, 627, 32732, 9040, 83, 1336, 12950, 9040, 83, 339, 23823, 365, 22751, 737, 1455, 921, 271, 14, 13961, 14, 1308, 15, 6797, 15, 7344, 14774, 527, 1129, 374, 272, 408, 272, 849, 63, 705, 63, 3431, 275, 469, 267, 283, 3197, 356, 4018, 8468, 282, 1686, 22261, 1237, 8503, 12564, 1329, 315, 5787, 13312, 13, 6873, 13933, 13, 6873, 13933, 13, 56, 1475, 8038, 272, 789, 339, 347, 965, 63, 1078, 63, 8928, 8, 277, 12, 1329, 304, 267, 1627, 63, 1955, 12, 1627, 63, 8928, 275, 1329, 4439, 17, 467, 1329, 1988, 17, 61, 267, 12950, 63, 8928, 275, 378, 267, 7956, 275, 3087, 267, 2725, 275, 1520, 398, 367, 284, 315, 1425, 8, 552, 8, 11809, 63, 1955, 2298, 288, 7956, 275, 620, 8, 442, 8, 11809, 63, 1955, 59, 73, 566, 627, 2725, 9, 288, 340, 7956, 14, 28235, 1507, 837, 355, 12950, 63, 8928, 847, 1109, 8, 7677, 1988, 17, 566, 288, 340, 2725, 508, 413, 26, 355, 2725, 275, 1520, 288, 916, 2725, 508, 650, 26, 355, 2725, 275, 413, 288, 916, 2725, 508, 23, 26, 355, 2725, 275, 650, 398, 372, 620, 8, 13494, 972, 63, 8928, 15786, 17, 61, 508, 1627, 63, 8928, 339, 347, 3633, 8, 277, 12, 574, 304, 267, 1613, 8, 1093, 10193, 13832, 3259, 792, 12, 291, 680, 3118, 8, 585, 9, 267, 340, 574, 315, 16589, 63, 15514, 26, 288, 372, 2125, 267, 1336, 275, 295, 14, 1431, 8, 344, 63, 264, 12, 574, 9, 267, 340, 440, 1336, 26, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 24714, 275, 1336, 14, 20567, 342, 267, 28633, 5606, 12, 6330, 275, 24714, 459, 20807, 5606, 995, 24714, 459, 6493, 418, 267, 21036, 2977, 12, 25667, 12, 9040, 275, 24714, 459, 15881, 995, 24714, 459, 31901, 995, 24714, 459, 8928, 418, 398, 340, 28633, 5606, 508, 283, 20625, 7, 503, 21036, 2977, 508, 283, 9084, 7, 503, 25667, 508, 283, 9084, 356, 288, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 1006, 63, 7022, 275, 2071, 83, 5, 83, 5, 83, 5, 83, 2, 450, 334, 20807, 5606, 12, 21036, 2977, 12, 25667, 12, 9040, 9, 267, 340, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 20807, 5606, 9, 503, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 15881, 9, 503, 971, 288, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 31901, 9, 503, 440, 291, 14, 1989, 63, 1078, 63, 8928, 8, 452, 63, 7022, 304, 355, 746, 8505, 8, 277, 14, 705, 63, 3431, 459, 3197, 1105, 398, 372, 1543, 83, 5, 83, 3295, 83, 3295, 83, 3295, 83, 7, 450, 334, 20807, 5606, 12, 6330, 12, 21036, 2977, 12, 25667, 12, 9040, 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, 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, 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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 ]
ychfan/tensorflow
tensorflow/python/debug/wrappers/local_cli_wrapper.py
11
25872
# Copyright 2016 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. # ============================================================================== """Debugger Wrapper Session Consisting of a Local Curses-based CLI.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import argparse import os import shutil import sys import tempfile # Google-internal import(s). from tensorflow.python.debug.cli import analyzer_cli from tensorflow.python.debug.cli import cli_shared from tensorflow.python.debug.cli import command_parser from tensorflow.python.debug.cli import debugger_cli_common from tensorflow.python.debug.cli import profile_analyzer_cli from tensorflow.python.debug.cli import stepper_cli from tensorflow.python.debug.cli import ui_factory from tensorflow.python.debug.lib import debug_data from tensorflow.python.debug.wrappers import framework _DUMP_ROOT_PREFIX = "tfdbg_" class LocalCLIDebugWrapperSession(framework.BaseDebugWrapperSession): """Concrete subclass of BaseDebugWrapperSession implementing a local CLI. This class has all the methods that a `session.Session` object has, in order to support debugging with minimal code changes. Invoking its `run()` method will launch the command-line interface (CLI) of tfdbg. """ def __init__(self, sess, dump_root=None, log_usage=True, ui_type="curses", thread_name_filter=None): """Constructor of LocalCLIDebugWrapperSession. Args: sess: The TensorFlow `Session` object being wrapped. dump_root: (`str`) optional path to the dump root directory. Must be a directory that does not exist or an empty directory. If the directory does not exist, it will be created by the debugger core during debug `run()` calls and removed afterwards. If `None`, the debug dumps will be at tfdbg_<random_string> under the system temp directory. log_usage: (`bool`) whether the usage of this class is to be logged. ui_type: (`str`) requested UI type. Currently supported: (curses | readline) thread_name_filter: Regular-expression white list for thread name. See the doc of `BaseDebugWrapperSession` for details. Raises: ValueError: If dump_root is an existing and non-empty directory or if dump_root is a file. """ if log_usage: pass # No logging for open-source. framework.BaseDebugWrapperSession.__init__( self, sess, thread_name_filter=thread_name_filter) if not dump_root: self._dump_root = tempfile.mktemp(prefix=_DUMP_ROOT_PREFIX) else: if os.path.isfile(dump_root): raise ValueError("dump_root path points to a file: %s" % dump_root) elif os.path.isdir(dump_root) and os.listdir(dump_root): raise ValueError("dump_root path points to a non-empty directory: %s" % dump_root) self._dump_root = dump_root self._initialize_argparsers() # Registered tensor filters. self._tensor_filters = {} # Register frequently-used filter(s). self.add_tensor_filter("has_inf_or_nan", debug_data.has_inf_or_nan) # Below are the state variables of this wrapper object. # _active_tensor_filter: what (if any) tensor filter is in effect. If such # a filter is in effect, this object will call run() method of the # underlying TensorFlow Session object until the filter passes. This is # activated by the "-f" flag of the "run" command. # _run_through_times: keeps track of how many times the wrapper needs to # run through without stopping at the run-end CLI. It is activated by the # "-t" option of the "run" command. # _skip_debug: keeps track of whether the current run should be executed # without debugging. It is activated by the "-n" option of the "run" # command. # # _run_start_response: keeps track what OnRunStartResponse the wrapper # should return at the next run-start callback. If this information is # unavailable (i.e., is None), the run-start CLI will be launched to ask # the user. This is the case, e.g., right before the first run starts. self._active_tensor_filter = None self._active_tensor_filter_run_start_response = None self._run_through_times = 1 self._skip_debug = False self._run_start_response = None self._is_run_start = True self._ui_type = ui_type def _initialize_argparsers(self): self._argparsers = {} ap = argparse.ArgumentParser( description="Run through, with or without debug tensor watching.", usage=argparse.SUPPRESS) ap.add_argument( "-t", "--times", dest="times", type=int, default=1, help="How many Session.run() calls to proceed with.") ap.add_argument( "-n", "--no_debug", dest="no_debug", action="store_true", help="Run through without debug tensor watching.") ap.add_argument( "-f", "--till_filter_pass", dest="till_filter_pass", type=str, default="", help="Run until a tensor in the graph passes the specified filter.") ap.add_argument( "--node_name_filter", dest="node_name_filter", type=str, default="", help="Regular-expression filter for node names to be watched in the " "run, e.g., loss, reshape.*") ap.add_argument( "--op_type_filter", dest="op_type_filter", type=str, default="", help="Regular-expression filter for op type to be watched in the run, " "e.g., (MatMul|Add), Variable.*") ap.add_argument( "--tensor_dtype_filter", dest="tensor_dtype_filter", type=str, default="", help="Regular-expression filter for tensor dtype to be watched in the " "run, e.g., (float32|float64), int.*") ap.add_argument( "-p", "--profile", dest="profile", action="store_true", help="Run and profile TensorFlow graph execution.") self._argparsers["run"] = ap ap = argparse.ArgumentParser( description="Invoke stepper (cont, step, breakpoint, etc.)", usage=argparse.SUPPRESS) self._argparsers["invoke_stepper"] = ap ap = argparse.ArgumentParser( description="Display information about this Session.run() call.", usage=argparse.SUPPRESS) self._argparsers["run_info"] = ap self._argparsers["print_feed"] = command_parser.get_print_tensor_argparser( "Print the value of a feed in feed_dict.") def add_tensor_filter(self, filter_name, tensor_filter): """Add a tensor filter. Args: filter_name: (`str`) name of the filter. tensor_filter: (`callable`) the filter callable. See the doc string of `DebugDumpDir.find()` for more details about its signature. """ self._tensor_filters[filter_name] = tensor_filter def on_session_init(self, request): """Overrides on-session-init callback. Args: request: An instance of `OnSessionInitRequest`. Returns: An instance of `OnSessionInitResponse`. """ return framework.OnSessionInitResponse( framework.OnSessionInitAction.PROCEED) def on_run_start(self, request): """Overrides on-run-start callback. Invoke the CLI to let user choose what action to take: `run` / `invoke_stepper`. Args: request: An instance of `OnRunStartRequest`. Returns: An instance of `OnRunStartResponse`. """ self._is_run_start = True self._update_run_calls_state( request.run_call_count, request.fetches, request.feed_dict, is_callable_runner=request.is_callable_runner) if self._active_tensor_filter: # If we are running until a filter passes, we just need to keep running # with the previous `OnRunStartResponse`. return self._active_tensor_filter_run_start_response self._exit_if_requested_by_user() if self._run_call_count > 1 and not self._skip_debug: if self._run_through_times > 0: # Just run through without debugging. return framework.OnRunStartResponse( framework.OnRunStartAction.NON_DEBUG_RUN, []) elif self._run_through_times == 0: # It is the run at which the run-end CLI will be launched: activate # debugging. return (self._run_start_response or framework.OnRunStartResponse( framework.OnRunStartAction.DEBUG_RUN, self._get_run_debug_urls())) if self._run_start_response is None: self._prep_cli_for_run_start() self._run_start_response = self._launch_cli() if self._active_tensor_filter: self._active_tensor_filter_run_start_response = self._run_start_response if self._run_through_times > 1: self._run_through_times -= 1 self._exit_if_requested_by_user() return self._run_start_response def _exit_if_requested_by_user(self): if self._run_start_response == debugger_cli_common.EXPLICIT_USER_EXIT: # Explicit user "exit" command leads to sys.exit(1). print( "Note: user exited from debugger CLI: Calling sys.exit(1).", file=sys.stderr) sys.exit(1) def _prep_cli_for_run_start(self): """Prepare (but not launch) the CLI for run-start.""" self._run_cli = ui_factory.get_ui(self._ui_type) help_intro = debugger_cli_common.RichTextLines([]) if self._run_call_count == 1: # Show logo at the onset of the first run. help_intro.extend(cli_shared.get_tfdbg_logo()) help_intro.extend(debugger_cli_common.RichTextLines("Upcoming run:")) help_intro.extend(self._run_info) self._run_cli.set_help_intro(help_intro) # Create initial screen output detailing the run. self._title = "run-start: " + self._run_description self._init_command = "run_info" self._title_color = "blue_on_white" def on_run_end(self, request): """Overrides on-run-end callback. Actions taken: 1) Load the debug dump. 2) Bring up the Analyzer CLI. Args: request: An instance of OnSessionInitRequest. Returns: An instance of OnSessionInitResponse. """ self._is_run_start = False if request.performed_action == framework.OnRunStartAction.DEBUG_RUN: partition_graphs = None if request.run_metadata and request.run_metadata.partition_graphs: partition_graphs = request.run_metadata.partition_graphs elif request.client_graph_def: partition_graphs = [request.client_graph_def] if request.tf_error and not os.path.isdir(self._dump_root): # It is possible that the dump root may not exist due to errors that # have occurred prior to graph execution (e.g., invalid device # assignments), in which case we will just raise the exception as the # unwrapped Session does. raise request.tf_error debug_dump = debug_data.DebugDumpDir( self._dump_root, partition_graphs=partition_graphs) debug_dump.set_python_graph(self._sess.graph) passed_filter = None if self._active_tensor_filter: if not debug_dump.find( self._tensor_filters[self._active_tensor_filter], first_n=1): # No dumped tensor passes the filter in this run. Clean up the dump # directory and move on. self._remove_dump_root() return framework.OnRunEndResponse() else: # Some dumped tensor(s) from this run passed the filter. passed_filter = self._active_tensor_filter self._active_tensor_filter = None self._prep_debug_cli_for_run_end( debug_dump, request.tf_error, passed_filter) self._run_start_response = self._launch_cli() # Clean up the dump generated by this run. self._remove_dump_root() elif request.performed_action == framework.OnRunStartAction.PROFILE_RUN: self._prep_profile_cli_for_run_end(self._sess.graph, request.run_metadata) self._run_start_response = self._launch_cli() else: # No debug information to show following a non-debug run() call. self._run_start_response = None # Return placeholder response that currently holds no additional # information. return framework.OnRunEndResponse() def _remove_dump_root(self): if os.path.isdir(self._dump_root): shutil.rmtree(self._dump_root) def _prep_debug_cli_for_run_end(self, debug_dump, tf_error, passed_filter): """Prepare (but not launch) CLI for run-end, with debug dump from the run. Args: debug_dump: (debug_data.DebugDumpDir) The debug dump directory from this run. tf_error: (None or OpError) OpError that happened during the run() call (if any). passed_filter: (None or str) Name of the tensor filter that just passed and caused the preparation of this run-end CLI (if any). """ if tf_error: help_intro = cli_shared.get_error_intro(tf_error) self._init_command = "help" self._title_color = "red_on_white" else: help_intro = None self._init_command = "lt" self._title_color = "black_on_white" if passed_filter is not None: # Some dumped tensor(s) from this run passed the filter. self._init_command = "lt -f %s" % passed_filter self._title_color = "red_on_white" self._run_cli = analyzer_cli.create_analyzer_ui( debug_dump, self._tensor_filters, ui_type=self._ui_type, on_ui_exit=self._remove_dump_root) # Get names of all dumped tensors. dumped_tensor_names = [] for datum in debug_dump.dumped_tensor_data: dumped_tensor_names.append("%s:%d" % (datum.node_name, datum.output_slot)) # Tab completions for command "print_tensors". self._run_cli.register_tab_comp_context(["print_tensor", "pt"], dumped_tensor_names) # Tab completion for commands "node_info", "list_inputs" and # "list_outputs". The list comprehension is used below because nodes() # output can be unicodes and they need to be converted to strs. self._run_cli.register_tab_comp_context( ["node_info", "ni", "list_inputs", "li", "list_outputs", "lo"], [str(node_name) for node_name in debug_dump.nodes()]) # TODO(cais): Reduce API surface area for aliases vis-a-vis tab # completion contexts and registered command handlers. self._title = "run-end: " + self._run_description if help_intro: self._run_cli.set_help_intro(help_intro) def _prep_profile_cli_for_run_end(self, py_graph, run_metadata): self._init_command = "lp" self._run_cli = profile_analyzer_cli.create_profiler_ui( py_graph, run_metadata, ui_type=self._ui_type, config=self._run_cli.config) self._title = "run-end (profiler mode): " + self._run_description def _launch_cli(self): """Launch the interactive command-line interface. Returns: The OnRunStartResponse specified by the user using the "run" command. """ self._register_this_run_info(self._run_cli) response = self._run_cli.run_ui( init_command=self._init_command, title=self._title, title_color=self._title_color) return response def _run_info_handler(self, args, screen_info=None): output = debugger_cli_common.RichTextLines([]) if self._run_call_count == 1: output.extend(cli_shared.get_tfdbg_logo()) output.extend(self._run_info) if (not self._is_run_start and debugger_cli_common.MAIN_MENU_KEY in output.annotations): menu = output.annotations[debugger_cli_common.MAIN_MENU_KEY] if "list_tensors" not in menu.captions(): menu.insert( 0, debugger_cli_common.MenuItem("list_tensors", "list_tensors")) return output def _print_feed_handler(self, args, screen_info=None): np_printoptions = cli_shared.numpy_printoptions_from_screen_info( screen_info) if not self._feed_dict: return cli_shared.error( "The feed_dict of the current run is None or empty.") parsed = self._argparsers["print_feed"].parse_args(args) tensor_name, tensor_slicing = ( command_parser.parse_tensor_name_with_slicing(parsed.tensor_name)) feed_key = None feed_value = None for key in self._feed_dict: key_name = cli_shared.get_graph_element_name(key) if key_name == tensor_name: feed_key = key_name feed_value = self._feed_dict[key] break if feed_key is None: return cli_shared.error( "The feed_dict of the current run does not contain the key %s" % tensor_name) else: return cli_shared.format_tensor( feed_value, feed_key + " (feed)", np_printoptions, print_all=parsed.print_all, tensor_slicing=tensor_slicing, highlight_options=cli_shared.parse_ranges_highlight(parsed.ranges), include_numeric_summary=parsed.numeric_summary) def _run_handler(self, args, screen_info=None): """Command handler for "run" command during on-run-start.""" del screen_info # Currently unused. parsed = self._argparsers["run"].parse_args(args) parsed.node_name_filter = parsed.node_name_filter or None parsed.op_type_filter = parsed.op_type_filter or None parsed.tensor_dtype_filter = parsed.tensor_dtype_filter or None if parsed.profile: raise debugger_cli_common.CommandLineExit( exit_token=framework.OnRunStartResponse( framework.OnRunStartAction.PROFILE_RUN, [])) self._skip_debug = parsed.no_debug self._run_through_times = parsed.times if parsed.times > 1 or parsed.no_debug: # If requested -t times > 1, the very next run will be a non-debug run. action = framework.OnRunStartAction.NON_DEBUG_RUN debug_urls = [] else: action = framework.OnRunStartAction.DEBUG_RUN debug_urls = self._get_run_debug_urls() run_start_response = framework.OnRunStartResponse( action, debug_urls, node_name_regex_whitelist=parsed.node_name_filter, op_type_regex_whitelist=parsed.op_type_filter, tensor_dtype_regex_whitelist=parsed.tensor_dtype_filter) if parsed.till_filter_pass: # For the run-till-filter-pass (run -f) mode, use the DEBUG_RUN # option to access the intermediate tensors, and set the corresponding # state flag of the class itself to True. if parsed.till_filter_pass in self._tensor_filters: action = framework.OnRunStartAction.DEBUG_RUN self._active_tensor_filter = parsed.till_filter_pass self._active_tensor_filter_run_start_response = run_start_response else: # Handle invalid filter name. return debugger_cli_common.RichTextLines( ["ERROR: tensor filter \"%s\" does not exist." % parsed.till_filter_pass]) # Raise CommandLineExit exception to cause the CLI to exit. raise debugger_cli_common.CommandLineExit(exit_token=run_start_response) def _register_this_run_info(self, curses_cli): curses_cli.register_command_handler( "run", self._run_handler, self._argparsers["run"].format_help(), prefix_aliases=["r"]) curses_cli.register_command_handler( "invoke_stepper", self._on_run_start_step_handler, self._argparsers["invoke_stepper"].format_help(), prefix_aliases=["s"]) curses_cli.register_command_handler( "run_info", self._run_info_handler, self._argparsers["run_info"].format_help(), prefix_aliases=["ri"]) curses_cli.register_command_handler( "print_feed", self._print_feed_handler, self._argparsers["print_feed"].format_help(), prefix_aliases=["pf"]) if self._tensor_filters: # Register tab completion for the filter names. curses_cli.register_tab_comp_context(["run", "r"], list(self._tensor_filters.keys())) if self._feed_dict: # Register tab completion for feed_dict keys. feed_keys = [cli_shared.get_graph_element_name(key) for key in self._feed_dict.keys()] curses_cli.register_tab_comp_context(["print_feed", "pf"], feed_keys) def _on_run_start_step_handler(self, args, screen_info=None): """Command handler for "invoke_stepper" command during on-run-start.""" _ = screen_info # Currently unused. # No parsing is currently necessary for invoke_stepper. This may change # in the future when the command has arguments. # Raise CommandLineExit exception to cause the CLI to exit. raise debugger_cli_common.CommandLineExit( exit_token=framework.OnRunStartResponse( framework.OnRunStartAction.INVOKE_STEPPER, [])) def _get_run_debug_urls(self): """Get the debug_urls value for the current run() call. Returns: debug_urls: (list of str) Debug URLs for the current run() call. Currently, the list consists of only one URL that is a file:// URL. """ return ["file://" + self._dump_root] def _update_run_calls_state(self, run_call_count, fetches, feed_dict, is_callable_runner=False): """Update the internal state with regard to run() call history. Args: run_call_count: (int) Number of run() calls that have occurred. fetches: a node/tensor or a list of node/tensor that are the fetches of the run() call. This is the same as the fetches argument to the run() call. feed_dict: None of a dict. This is the feed_dict argument to the run() call. is_callable_runner: (bool) whether a runner returned by Session.make_callable is being run. """ self._run_call_count = run_call_count self._feed_dict = feed_dict self._run_description = cli_shared.get_run_short_description( run_call_count, fetches, feed_dict, is_callable_runner=is_callable_runner) self._run_through_times -= 1 self._run_info = cli_shared.get_run_start_intro( run_call_count, fetches, feed_dict, self._tensor_filters, is_callable_runner=is_callable_runner) def invoke_node_stepper(self, node_stepper, restore_variable_values_on_exit=True): """Overrides method in base class to implement interactive node stepper. Args: node_stepper: (`stepper.NodeStepper`) The underlying NodeStepper API object. restore_variable_values_on_exit: (`bool`) Whether any variables whose values have been altered during this node-stepper invocation should be restored to their old values when this invocation ends. Returns: The same return values as the `Session.run()` call on the same fetches as the NodeStepper. """ stepper = stepper_cli.NodeStepperCLI(node_stepper) # On exiting the node-stepper CLI, the finalize method of the node_stepper # object will be called, ensuring that the state of the graph will be the # same as if the stepping did not happen. # TODO(cais): Perhaps some users will want the effect of the interactive # stepping and value injection to persist. When that happens, make the call # to finalize optional. stepper_ui = ui_factory.get_ui( self._ui_type, on_ui_exit=(node_stepper.restore_variable_values if restore_variable_values_on_exit else None)) stepper_ui.register_command_handler( "list_sorted_nodes", stepper.list_sorted_nodes, stepper.arg_parsers["list_sorted_nodes"].format_help(), prefix_aliases=["lt", "lsn"]) stepper_ui.register_command_handler( "cont", stepper.cont, stepper.arg_parsers["cont"].format_help(), prefix_aliases=["ct", "c"]) stepper_ui.register_command_handler( "step", stepper.step, stepper.arg_parsers["step"].format_help(), prefix_aliases=["st", "s"]) stepper_ui.register_command_handler( "print_tensor", stepper.print_tensor, stepper.arg_parsers["print_tensor"].format_help(), prefix_aliases=["pt"]) stepper_ui.register_command_handler( "inject_value", stepper.inject_value, stepper.arg_parsers["inject_value"].format_help(), prefix_aliases=["inject", "override_value", "override"]) # Register tab completion candidates. stepper_ui.register_tab_comp_context([ "cont", "ct", "c", "pt", "inject_value", "inject", "override_value", "override" ], [str(elem) for elem in node_stepper.sorted_nodes()]) # TODO(cais): Tie up register_tab_comp_context to a single alias to shorten # calls like this. return stepper_ui.run_ui( init_command="lt", title="Node Stepper: " + self._run_description, title_color="blue_on_white")
apache-2.0
[ 3, 1898, 7800, 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, 31521, 21947, 8596, 1448, 11734, 316, 402, 282, 10111, 7319, 874, 13, 6788, 14214, 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, 7534, 199, 646, 747, 199, 646, 5145, 199, 646, 984, 199, 646, 5549, 199, 199, 3, 4475, 13, 4672, 492, 8, 83, 680, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 24608, 63, 2764, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 5053, 63, 5555, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 1414, 63, 2087, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 14958, 63, 2764, 63, 2330, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 4690, 63, 17965, 63, 2764, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 17871, 63, 2764, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 8574, 63, 3702, 199, 504, 3228, 14, 1548, 14, 1757, 14, 773, 492, 3105, 63, 576, 199, 504, 3228, 14, 1548, 14, 1757, 14, 21148, 492, 10059, 421, 199, 63, 26406, 63, 5441, 63, 6351, 275, 298, 3249, 16310, 12172, 421, 199, 533, 10111, 7802, 7084, 4590, 4434, 8, 4857, 14, 1563, 7084, 4590, 4434, 304, 523, 408, 714, 7564, 5516, 402, 3523, 7084, 4590, 4434, 18234, 282, 2257, 14214, 14, 819, 961, 1021, 965, 1006, 314, 3102, 626, 282, 658, 1730, 14, 4434, 64, 909, 965, 12, 315, 1865, 523, 370, 2291, 10201, 543, 13460, 1233, 4493, 14, 30110, 17967, 2399, 658, 1065, 11995, 1083, 523, 911, 10623, 314, 1414, 13, 604, 3217, 334, 7802, 9, 402, 2833, 16310, 14, 523, 408, 819, 347, 636, 826, 721, 277, 12, 2049, 4043, 12, 2049, 5461, 63, 1231, 29, 403, 12, 2049, 943, 63, 3807, 29, 549, 12, 2049, 8574, 63, 466, 628, 12026, 401, 2049, 2462, 63, 354, 63, 1541, 29, 403, 304, 272, 408, 11447, 402, 10111, 7802, 7084, 4590, 4434, 14, 339, 3033, 26, 489, 4043, 26, 710, 9134, 658, 4434, 64, 909, 3769, 8072, 14, 489, 5461, 63, 1231, 26, 13493, 495, 10522, 2716, 931, 370, 314, 5461, 1738, 2082, 14, 9498, 506, 282, 267, 2082, 626, 1630, 440, 2187, 503, 376, 2701, 2082, 14, 982, 314, 2082, 267, 1630, 440, 2187, 12, 652, 911, 506, 2737, 701, 314, 14958, 6170, 5309, 3105, 267, 658, 1065, 11995, 4882, 436, 4829, 26982, 14, 982, 658, 403, 3559, 314, 3105, 16864, 911, 267, 506, 737, 2833, 16310, 27718, 2355, 63, 875, 30, 1334, 314, 2656, 2388, 2082, 14, 489, 943, 63, 3807, 26, 13493, 2245, 10522, 3775, 314, 4503, 402, 642, 1021, 365, 370, 506, 10367, 14, 489, 8574, 63, 466, 26, 13493, 495, 10522, 5839, 14041, 730, 14, 13550, 3748, 26, 267, 334, 12026, 1204, 14441, 9, 489, 2462, 63, 354, 63, 1541, 26, 18528, 13, 5599, 10424, 769, 367, 2462, 536, 14, 1666, 267, 314, 1382, 402, 658, 1563, 7084, 4590, 4434, 64, 367, 2436, 14, 339, 6218, 26, 489, 1722, 26, 982, 5461, 63, 1231, 365, 376, 3411, 436, 2222, 13, 1667, 2082, 503, 340, 267, 5461, 63, 1231, 365, 282, 570, 14, 272, 408, 339, 340, 943, 63, 3807, 26, 489, 986, 221, 327, 3091, 2050, 367, 1551, 13, 1365, 14, 339, 10059, 14, 1563, 7084, 4590, 4434, 855, 826, 721, 267, 291, 12, 4043, 12, 2462, 63, 354, 63, 1541, 29, 2671, 63, 354, 63, 1541, 9, 339, 340, 440, 5461, 63, 1231, 26, 489, 291, 423, 2724, 63, 1231, 275, 5549, 14, 22136, 8, 1861, 3699, 26406, 63, 5441, 63, 6351, 9, 272, 587, 26, 489, 340, 747, 14, 515, 14, 6292, 8, 2724, 63, 1231, 304, 267, 746, 1722, 480, 2724, 63, 1231, 931, 4501, 370, 282, 570, 26, 450, 83, 2, 450, 5461, 63, 1231, 9, 489, 916, 747, 14, 515, 14, 6027, 8, 2724, 63, 1231, 9, 436, 747, 14, 7374, 8, 2724, 63, 1231, 304, 267, 746, 1722, 480, 2724, 63, 1231, 931, 4501, 370, 282, 2222, 13, 1667, 2082, 26, 450, 83, 2, 450, 586, 5461, 63, 1231, 9, 2541, 291, 423, 2724, 63, 1231, 275, 5461, 63, 1231, 339, 291, 423, 8489, 63, 1273, 11531, 342, 339, 327, 5044, 5338, 2345, 4766, 14, 272, 291, 423, 3128, 63, 4273, 275, 1052, 272, 327, 11828, 28914, 590, 13, 2972, 2457, 8, 83, 680, 272, 291, 14, 525, 63, 3128, 63, 1541, 480, 1989, 63, 4904, 63, 269, 63, 4304, 401, 3105, 63, 576, 14, 1989, 63, 4904, 63, 269, 63, 4304, 9, 339, 327, 6423, 674, 787, 314, 1174, 2860, 402, 642, 4975, 909, 14, 272, 327, 485, 2682, 63, 3128, 63, 1541, 26, 4052, 334, 692, 1263, 9, 2345, 2457, 365, 315, 7763, 14, 982, 4066, 272, 327, 257, 282, 2457, 365, 315, 7763, 12, 642, 909, 911, 1240, 1255, 342, 1083, 402, 314, 272, 327, 257, 8793, 9134, 8596, 909, 5133, 314, 2457, 14933, 14, 961, 365, 272, 327, 257, 22225, 701, 314, 3905, 70, 2, 3305, 402, 314, 298, 1065, 2, 1414, 14, 272, 327, 485, 1065, 63, 8304, 63, 4508, 26, 18578, 4426, 402, 4212, 5002, 5431, 314, 4975, 4839, 370, 272, 327, 257, 1255, 4012, 1928, 23599, 737, 314, 1255, 13, 500, 14214, 14, 2779, 365, 22225, 701, 314, 272, 327, 257 ]
[ 1898, 7800, 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, 31521, 21947, 8596, 1448, 11734, 316, 402, 282, 10111, 7319, 874, 13, 6788, 14214, 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, 7534, 199, 646, 747, 199, 646, 5145, 199, 646, 984, 199, 646, 5549, 199, 199, 3, 4475, 13, 4672, 492, 8, 83, 680, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 24608, 63, 2764, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 5053, 63, 5555, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 1414, 63, 2087, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 14958, 63, 2764, 63, 2330, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 4690, 63, 17965, 63, 2764, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 17871, 63, 2764, 199, 504, 3228, 14, 1548, 14, 1757, 14, 2764, 492, 8574, 63, 3702, 199, 504, 3228, 14, 1548, 14, 1757, 14, 773, 492, 3105, 63, 576, 199, 504, 3228, 14, 1548, 14, 1757, 14, 21148, 492, 10059, 421, 199, 63, 26406, 63, 5441, 63, 6351, 275, 298, 3249, 16310, 12172, 421, 199, 533, 10111, 7802, 7084, 4590, 4434, 8, 4857, 14, 1563, 7084, 4590, 4434, 304, 523, 408, 714, 7564, 5516, 402, 3523, 7084, 4590, 4434, 18234, 282, 2257, 14214, 14, 819, 961, 1021, 965, 1006, 314, 3102, 626, 282, 658, 1730, 14, 4434, 64, 909, 965, 12, 315, 1865, 523, 370, 2291, 10201, 543, 13460, 1233, 4493, 14, 30110, 17967, 2399, 658, 1065, 11995, 1083, 523, 911, 10623, 314, 1414, 13, 604, 3217, 334, 7802, 9, 402, 2833, 16310, 14, 523, 408, 819, 347, 636, 826, 721, 277, 12, 2049, 4043, 12, 2049, 5461, 63, 1231, 29, 403, 12, 2049, 943, 63, 3807, 29, 549, 12, 2049, 8574, 63, 466, 628, 12026, 401, 2049, 2462, 63, 354, 63, 1541, 29, 403, 304, 272, 408, 11447, 402, 10111, 7802, 7084, 4590, 4434, 14, 339, 3033, 26, 489, 4043, 26, 710, 9134, 658, 4434, 64, 909, 3769, 8072, 14, 489, 5461, 63, 1231, 26, 13493, 495, 10522, 2716, 931, 370, 314, 5461, 1738, 2082, 14, 9498, 506, 282, 267, 2082, 626, 1630, 440, 2187, 503, 376, 2701, 2082, 14, 982, 314, 2082, 267, 1630, 440, 2187, 12, 652, 911, 506, 2737, 701, 314, 14958, 6170, 5309, 3105, 267, 658, 1065, 11995, 4882, 436, 4829, 26982, 14, 982, 658, 403, 3559, 314, 3105, 16864, 911, 267, 506, 737, 2833, 16310, 27718, 2355, 63, 875, 30, 1334, 314, 2656, 2388, 2082, 14, 489, 943, 63, 3807, 26, 13493, 2245, 10522, 3775, 314, 4503, 402, 642, 1021, 365, 370, 506, 10367, 14, 489, 8574, 63, 466, 26, 13493, 495, 10522, 5839, 14041, 730, 14, 13550, 3748, 26, 267, 334, 12026, 1204, 14441, 9, 489, 2462, 63, 354, 63, 1541, 26, 18528, 13, 5599, 10424, 769, 367, 2462, 536, 14, 1666, 267, 314, 1382, 402, 658, 1563, 7084, 4590, 4434, 64, 367, 2436, 14, 339, 6218, 26, 489, 1722, 26, 982, 5461, 63, 1231, 365, 376, 3411, 436, 2222, 13, 1667, 2082, 503, 340, 267, 5461, 63, 1231, 365, 282, 570, 14, 272, 408, 339, 340, 943, 63, 3807, 26, 489, 986, 221, 327, 3091, 2050, 367, 1551, 13, 1365, 14, 339, 10059, 14, 1563, 7084, 4590, 4434, 855, 826, 721, 267, 291, 12, 4043, 12, 2462, 63, 354, 63, 1541, 29, 2671, 63, 354, 63, 1541, 9, 339, 340, 440, 5461, 63, 1231, 26, 489, 291, 423, 2724, 63, 1231, 275, 5549, 14, 22136, 8, 1861, 3699, 26406, 63, 5441, 63, 6351, 9, 272, 587, 26, 489, 340, 747, 14, 515, 14, 6292, 8, 2724, 63, 1231, 304, 267, 746, 1722, 480, 2724, 63, 1231, 931, 4501, 370, 282, 570, 26, 450, 83, 2, 450, 5461, 63, 1231, 9, 489, 916, 747, 14, 515, 14, 6027, 8, 2724, 63, 1231, 9, 436, 747, 14, 7374, 8, 2724, 63, 1231, 304, 267, 746, 1722, 480, 2724, 63, 1231, 931, 4501, 370, 282, 2222, 13, 1667, 2082, 26, 450, 83, 2, 450, 586, 5461, 63, 1231, 9, 2541, 291, 423, 2724, 63, 1231, 275, 5461, 63, 1231, 339, 291, 423, 8489, 63, 1273, 11531, 342, 339, 327, 5044, 5338, 2345, 4766, 14, 272, 291, 423, 3128, 63, 4273, 275, 1052, 272, 327, 11828, 28914, 590, 13, 2972, 2457, 8, 83, 680, 272, 291, 14, 525, 63, 3128, 63, 1541, 480, 1989, 63, 4904, 63, 269, 63, 4304, 401, 3105, 63, 576, 14, 1989, 63, 4904, 63, 269, 63, 4304, 9, 339, 327, 6423, 674, 787, 314, 1174, 2860, 402, 642, 4975, 909, 14, 272, 327, 485, 2682, 63, 3128, 63, 1541, 26, 4052, 334, 692, 1263, 9, 2345, 2457, 365, 315, 7763, 14, 982, 4066, 272, 327, 257, 282, 2457, 365, 315, 7763, 12, 642, 909, 911, 1240, 1255, 342, 1083, 402, 314, 272, 327, 257, 8793, 9134, 8596, 909, 5133, 314, 2457, 14933, 14, 961, 365, 272, 327, 257, 22225, 701, 314, 3905, 70, 2, 3305, 402, 314, 298, 1065, 2, 1414, 14, 272, 327, 485, 1065, 63, 8304, 63, 4508, 26, 18578, 4426, 402, 4212, 5002, 5431, 314, 4975, 4839, 370, 272, 327, 257, 1255, 4012, 1928, 23599, 737, 314, 1255, 13, 500, 14214, 14, 2779, 365, 22225, 701, 314, 272, 327, 257, 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,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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 ]
jicruz/heroku-bot
lib/youtube_dl/extractor/ruleporn.py
76
1514
from __future__ import unicode_literals from .nuevo import NuevoBaseIE class RulePornIE(NuevoBaseIE): _VALID_URL = r'https?://(?:www\.)?ruleporn\.com/(?:[^/?#&]+/)*(?P<id>[^/?#&]+)' _TEST = { 'url': 'http://ruleporn.com/brunette-nympho-chick-takes-her-boyfriend-in-every-angle/', 'md5': '86861ebc624a1097c7c10eaf06d7d505', 'info_dict': { 'id': '48212', 'display_id': 'brunette-nympho-chick-takes-her-boyfriend-in-every-angle', 'ext': 'mp4', 'title': 'Brunette Nympho Chick Takes Her Boyfriend In Every Angle', 'description': 'md5:6d28be231b981fff1981deaaa03a04d5', 'age_limit': 18, 'duration': 635.1, } } def _real_extract(self, url): display_id = self._match_id(url) webpage = self._download_webpage(url, display_id) video_id = self._search_regex( r'lovehomeporn\.com/embed/(\d+)', webpage, 'video id') title = self._search_regex( r'<h2[^>]+title=(["\'])(?P<url>.+?)\1', webpage, 'title', group='url') description = self._html_search_meta('description', webpage) info = self._extract_nuevo( 'http://lovehomeporn.com/media/nuevo/econfig.php?key=%s&rp=true' % video_id, video_id) info.update({ 'display_id': display_id, 'title': title, 'description': description, 'age_limit': 18 }) return info
gpl-3.0
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 1275, 78, 310, 2392, 492, 653, 310, 2392, 1563, 4332, 421, 199, 533, 11949, 48, 6161, 4332, 8, 46, 310, 2392, 1563, 4332, 304, 272, 485, 5600, 63, 2632, 275, 519, 7, 2859, 24524, 1544, 20316, 2200, 80, 6161, 4537, 957, 32576, 4735, 10197, 3, 6, 2807, 15, 3342, 2229, 48, 28, 344, 13489, 10197, 3, 6, 29716, 272, 485, 2864, 275, 469, 267, 283, 633, 356, 283, 1014, 921, 2200, 80, 6161, 14, 957, 15, 66, 1065, 386, 266, 13, 9745, 311, 526, 13, 335, 2000, 13, 31613, 13, 2523, 13, 656, 89, 23472, 13, 262, 13, 14287, 13, 4593, 3678, 267, 283, 1064, 21, 356, 283, 1184, 16253, 26816, 28062, 65, 709, 2576, 67, 23, 67, 709, 69, 2756, 1690, 68, 23, 68, 13938, 297, 267, 283, 815, 63, 807, 356, 469, 288, 283, 344, 356, 283, 2006, 11722, 297, 288, 283, 2918, 63, 344, 356, 283, 66, 1065, 386, 266, 13, 9745, 311, 526, 13, 335, 2000, 13, 31613, 13, 2523, 13, 656, 89, 23472, 13, 262, 13, 14287, 13, 4593, 297, 288, 283, 832, 356, 283, 311, 20, 297, 288, 283, 1213, 356, 283, 34, 1065, 386, 266, 653, 89, 311, 526, 2799, 2000, 17415, 18769, 5088, 89, 23472, 1010, 18414, 1626, 3845, 297, 288, 283, 1802, 356, 283, 1064, 21, 26, 22, 68, 1651, 1235, 11921, 66, 25, 2835, 18190, 1167, 2835, 271, 11629, 1644, 65, 966, 68, 21, 297, 288, 283, 474, 63, 3097, 356, 6155, 12, 288, 283, 5553, 356, 1227, 1276, 14, 17, 12, 267, 789, 272, 789, 339, 347, 485, 3093, 63, 5005, 8, 277, 12, 1166, 304, 267, 2929, 63, 344, 275, 291, 423, 1431, 63, 344, 8, 633, 9, 398, 9248, 275, 291, 423, 4249, 63, 12022, 8, 633, 12, 2929, 63, 344, 9, 398, 3991, 63, 344, 275, 291, 423, 1733, 63, 3821, 8, 288, 519, 7, 320, 432, 4219, 80, 6161, 4537, 957, 15, 6427, 15, 2961, 68, 14705, 9248, 12, 283, 3722, 1305, 358, 398, 2538, 275, 291, 423, 1733, 63, 3821, 8, 288, 519, 7601, 72, 18, 25524, 1213, 30982, 3212, 1105, 2229, 48, 28, 633, 29587, 2862, 17, 297, 288, 9248, 12, 283, 1213, 297, 1572, 534, 633, 358, 267, 1369, 275, 291, 423, 1360, 63, 1733, 63, 2024, 360, 1802, 297, 9248, 9, 398, 2256, 275, 291, 423, 5005, 63, 78, 310, 2392, 8, 288, 283, 1014, 921, 320, 432, 4219, 80, 6161, 14, 957, 15, 4603, 15, 78, 310, 2392, 15, 69, 888, 14, 8624, 31, 498, 2458, 83, 6, 4599, 29, 2052, 7, 450, 3991, 63, 344, 12, 288, 3991, 63, 344, 9, 267, 2256, 14, 873, 2561, 288, 283, 2918, 63, 344, 356, 2929, 63, 344, 12, 288, 283, 1213, 356, 2538, 12, 288, 283, 1802, 356, 1369, 12, 288, 283, 474, 63, 3097, 356, 6155, 267, 3828, 267, 372, 2256, 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 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 1275, 78, 310, 2392, 492, 653, 310, 2392, 1563, 4332, 421, 199, 533, 11949, 48, 6161, 4332, 8, 46, 310, 2392, 1563, 4332, 304, 272, 485, 5600, 63, 2632, 275, 519, 7, 2859, 24524, 1544, 20316, 2200, 80, 6161, 4537, 957, 32576, 4735, 10197, 3, 6, 2807, 15, 3342, 2229, 48, 28, 344, 13489, 10197, 3, 6, 29716, 272, 485, 2864, 275, 469, 267, 283, 633, 356, 283, 1014, 921, 2200, 80, 6161, 14, 957, 15, 66, 1065, 386, 266, 13, 9745, 311, 526, 13, 335, 2000, 13, 31613, 13, 2523, 13, 656, 89, 23472, 13, 262, 13, 14287, 13, 4593, 3678, 267, 283, 1064, 21, 356, 283, 1184, 16253, 26816, 28062, 65, 709, 2576, 67, 23, 67, 709, 69, 2756, 1690, 68, 23, 68, 13938, 297, 267, 283, 815, 63, 807, 356, 469, 288, 283, 344, 356, 283, 2006, 11722, 297, 288, 283, 2918, 63, 344, 356, 283, 66, 1065, 386, 266, 13, 9745, 311, 526, 13, 335, 2000, 13, 31613, 13, 2523, 13, 656, 89, 23472, 13, 262, 13, 14287, 13, 4593, 297, 288, 283, 832, 356, 283, 311, 20, 297, 288, 283, 1213, 356, 283, 34, 1065, 386, 266, 653, 89, 311, 526, 2799, 2000, 17415, 18769, 5088, 89, 23472, 1010, 18414, 1626, 3845, 297, 288, 283, 1802, 356, 283, 1064, 21, 26, 22, 68, 1651, 1235, 11921, 66, 25, 2835, 18190, 1167, 2835, 271, 11629, 1644, 65, 966, 68, 21, 297, 288, 283, 474, 63, 3097, 356, 6155, 12, 288, 283, 5553, 356, 1227, 1276, 14, 17, 12, 267, 789, 272, 789, 339, 347, 485, 3093, 63, 5005, 8, 277, 12, 1166, 304, 267, 2929, 63, 344, 275, 291, 423, 1431, 63, 344, 8, 633, 9, 398, 9248, 275, 291, 423, 4249, 63, 12022, 8, 633, 12, 2929, 63, 344, 9, 398, 3991, 63, 344, 275, 291, 423, 1733, 63, 3821, 8, 288, 519, 7, 320, 432, 4219, 80, 6161, 4537, 957, 15, 6427, 15, 2961, 68, 14705, 9248, 12, 283, 3722, 1305, 358, 398, 2538, 275, 291, 423, 1733, 63, 3821, 8, 288, 519, 7601, 72, 18, 25524, 1213, 30982, 3212, 1105, 2229, 48, 28, 633, 29587, 2862, 17, 297, 288, 9248, 12, 283, 1213, 297, 1572, 534, 633, 358, 267, 1369, 275, 291, 423, 1360, 63, 1733, 63, 2024, 360, 1802, 297, 9248, 9, 398, 2256, 275, 291, 423, 5005, 63, 78, 310, 2392, 8, 288, 283, 1014, 921, 320, 432, 4219, 80, 6161, 14, 957, 15, 4603, 15, 78, 310, 2392, 15, 69, 888, 14, 8624, 31, 498, 2458, 83, 6, 4599, 29, 2052, 7, 450, 3991, 63, 344, 12, 288, 3991, 63, 344, 9, 267, 2256, 14, 873, 2561, 288, 283, 2918, 63, 344, 356, 2929, 63, 344, 12, 288, 283, 1213, 356, 2538, 12, 288, 283, 1802, 356, 1369, 12, 288, 283, 474, 63, 3097, 356, 6155, 267, 3828, 267, 372, 2256, 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, 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,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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 ]
applexiaohao/three.js
utils/exporters/blender/tests/scripts/review.py
305
3697
import os import json import stat import shutil import argparse os.chdir(os.path.dirname(os.path.realpath(__file__))) os.chdir('..') review = os.path.join(os.getcwd(), 'review') MASK = stat.S_IRWXU|stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH HTML = '''<!doctype html> <html lang='en'> <head> <title>%(title)s</title> <meta charset='utf-8'> <script src='../../../../../../build/three.min.js'></script> <script src='../../../../../../examples/js/controls/OrbitControls.js'></script> <script src='../../scripts/js/review.js'></script> <link href='../../scripts/css/style.css' rel='stylesheet' /> </head> <body> <script> init('%(filename)s'); </script> </body> </html> ''' def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('json') parser.add_argument('-t', '--tag', required=True) return vars(parser.parse_args()) def copy_for_review(tmp_json, tag): tag_dir = os.path.join(review, tag) if not os.path.exists(tag_dir): print('making %s' % tag_dir) os.makedirs(tag_dir) dst_json = os.path.join(tag_dir, '%s.json' % tag) print('moving %s > %s' % (tmp_json, dst_json)) shutil.move(tmp_json, dst_json) create_template(tag_dir, os.path.basename(dst_json)) print('looking for maps...') with open(dst_json) as stream: data = json.load(stream) textures = [] materials = data.get('materials') if data['metadata']['type'] == 'Geometry' and materials: textures.extend(_parse_geometry_materials(materials)) images = data.get('images') if data['metadata']['type'] == 'Object' and images: for each in images: textures.append(each['url']) textures = list(set(textures)) print('found %d maps' % len(textures)) dir_tmp = os.path.dirname(tmp_json) for texture in textures: texture = os.path.join(dir_tmp, texture) dst = os.path.join(tag_dir, os.path.basename(texture)) shutil.move(texture, dst) print('moving %s > %s' % (texture, dst)) if data['metadata']['type'] == 'Object': print('looking for non-embedded geometry') for geometry in data['geometries']: url = geometry.get('url') if not url: continue src = os.path.join(dir_tmp, url) dst = os.path.join(tag_dir, url) print('moving %s > %s' % (src, dst)) shutil.move(src, dst) elif data['metadata']['type'] == 'Geometry': print('looking for external animation files') for key in ('animation', 'morphTargets'): try: value = data[key] except KeyError: continue if not isinstance(value, str): continue src = os.path.join(dir_tmp, value) dst = os.path.join(tag_dir, value) print('moving %s > %s' % (src, dst)) shutil.move(src, dst) def _parse_geometry_materials(materials): maps = ('mapDiffuse', 'mapSpecular', 'mapBump', 'mapLight', 'mapNormal') textures = [] for material in materials: for key in material.keys(): if key in maps: textures.append(material[key]) return textures def create_template(tag_dir, filename): html = HTML % { 'title': filename[:-5].title(), 'filename': filename } html_path = os.path.join(tag_dir, 'index.html') with open(html_path, 'w') as stream: stream.write(html) os.chmod(html_path, MASK) def main(): args = parse_args() copy_for_review(args['json'], args['tag']) if __name__ == '__main__': main()
mit
[ 646, 747, 199, 646, 2022, 199, 646, 5672, 199, 646, 5145, 199, 646, 7534, 421, 199, 736, 14, 8563, 8, 736, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 11091, 3460, 493, 29658, 199, 736, 14, 8563, 24893, 358, 199, 8578, 275, 747, 14, 515, 14, 904, 8, 736, 14, 9458, 1062, 283, 8578, 358, 199, 199, 12880, 275, 5672, 14, 51, 63, 3927, 16783, 53, 92, 3736, 14, 51, 63, 3927, 3975, 48, 92, 3736, 14, 51, 63, 3867, 3975, 48, 92, 3736, 14, 51, 63, 41, 1092, 2080, 92, 3736, 14, 51, 63, 3867, 22949, 199, 199, 4943, 275, 1449, 11230, 6356, 3517, 30, 199, 28, 1360, 6339, 534, 287, 8423, 523, 665, 2993, 30, 272, 665, 1213, 19418, 1213, 9, 83, 1108, 1213, 30, 272, 665, 2024, 5960, 534, 1624, 13, 24, 8423, 272, 665, 1579, 2928, 534, 9707, 9707, 9707, 1506, 15, 10480, 14, 827, 14, 3596, 7, 2957, 1579, 30, 272, 665, 1579, 2928, 534, 9707, 9707, 9707, 8589, 15, 3596, 15, 13658, 15, 2844, 2075, 25457, 14, 3596, 7, 2957, 1579, 30, 272, 665, 1579, 2928, 534, 9707, 6429, 15, 3596, 15, 8578, 14, 3596, 7, 2957, 1579, 30, 272, 665, 1073, 4369, 534, 9707, 6429, 15, 3919, 15, 2487, 14, 3919, 7, 4668, 534, 15479, 7, 7082, 523, 3068, 2993, 30, 523, 665, 2030, 30, 272, 665, 1579, 30, 489, 4205, 24713, 1501, 9, 83, 11339, 272, 3068, 1579, 30, 523, 3068, 2030, 30, 199, 1108, 1360, 30, 199, 2344, 199, 199, 318, 2198, 63, 589, 837, 272, 1798, 275, 7534, 14, 10730, 342, 272, 1798, 14, 525, 63, 2094, 360, 1001, 358, 272, 1798, 14, 525, 63, 2094, 3654, 84, 297, 2850, 1450, 297, 1415, 29, 549, 9, 272, 372, 6802, 8, 2087, 14, 1122, 63, 589, 1012, 421, 199, 318, 1331, 63, 509, 63, 8578, 8, 2791, 63, 1001, 12, 1947, 304, 272, 1947, 63, 694, 275, 747, 14, 515, 14, 904, 8, 8578, 12, 1947, 9, 272, 340, 440, 747, 14, 515, 14, 2444, 8, 1450, 63, 694, 304, 267, 870, 360, 391, 17443, 450, 83, 7, 450, 1947, 63, 694, 9, 267, 747, 14, 8347, 8, 1450, 63, 694, 9, 272, 5042, 63, 1001, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 1543, 83, 14, 1001, 7, 450, 1947, 9, 272, 870, 360, 7665, 450, 83, 690, 450, 83, 7, 450, 334, 2791, 63, 1001, 12, 5042, 63, 1001, 430, 272, 5145, 14, 1185, 8, 2791, 63, 1001, 12, 5042, 63, 1001, 9, 272, 1218, 63, 1160, 8, 1450, 63, 694, 12, 747, 14, 515, 14, 4846, 8, 5119, 63, 1001, 430, 339, 870, 360, 11660, 316, 367, 9033, 15103, 272, 543, 1551, 8, 5119, 63, 1001, 9, 465, 2547, 26, 267, 666, 275, 2022, 14, 912, 8, 1745, 9, 339, 1318, 1482, 275, 942, 272, 8418, 275, 666, 14, 362, 360, 23231, 358, 272, 340, 666, 459, 2343, 2545, 466, 418, 508, 283, 6831, 7, 436, 8418, 26, 267, 1318, 1482, 14, 2880, 1547, 1122, 63, 7660, 63, 23231, 8, 23231, 430, 339, 5935, 275, 666, 14, 362, 360, 4782, 358, 272, 340, 666, 459, 2343, 2545, 466, 418, 508, 283, 1692, 7, 436, 5935, 26, 267, 367, 1924, 315, 5935, 26, 288, 1318, 1482, 14, 740, 8, 10885, 459, 633, 1105, 2286, 1318, 1482, 275, 769, 8, 409, 8, 27541, 430, 272, 870, 360, 4214, 450, 68, 9033, 7, 450, 822, 8, 27541, 430, 272, 2935, 63, 2791, 275, 747, 14, 515, 14, 3475, 8, 2791, 63, 1001, 9, 272, 367, 14855, 315, 1318, 1482, 26, 267, 14855, 275, 747, 14, 515, 14, 904, 8, 694, 63, 2791, 12, 14855, 9, 267, 5042, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 747, 14, 515, 14, 4846, 8, 12611, 430, 267, 5145, 14, 1185, 8, 12611, 12, 5042, 9, 267, 870, 360, 7665, 450, 83, 690, 450, 83, 7, 450, 334, 12611, 12, 5042, 430, 339, 340, 666, 459, 2343, 2545, 466, 418, 508, 283, 1692, 356, 267, 870, 360, 11660, 316, 367, 2222, 13, 18757, 3400, 358, 267, 367, 3400, 315, 666, 459, 21626, 2565, 288, 1166, 275, 3400, 14, 362, 360, 633, 358, 288, 340, 440, 1166, 26, 1980, 288, 2928, 275, 747, 14, 515, 14, 904, 8, 694, 63, 2791, 12, 1166, 9, 288, 5042, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 1166, 9, 288, 870, 360, 7665, 450, 83, 690, 450, 83, 7, 450, 334, 2164, 12, 5042, 430, 288, 5145, 14, 1185, 8, 2164, 12, 5042, 9, 272, 916, 666, 459, 2343, 2545, 466, 418, 508, 283, 6831, 356, 267, 870, 360, 11660, 316, 367, 5957, 24154, 1584, 358, 267, 367, 790, 315, 661, 22228, 297, 283, 10128, 14126, 735, 288, 862, 26, 355, 574, 275, 666, 59, 498, 61, 288, 871, 4067, 26, 355, 1980, 953, 340, 440, 1228, 8, 585, 12, 620, 304, 355, 1980, 953, 2928, 275, 747, 14, 515, 14, 904, 8, 694, 63, 2791, 12, 574, 9, 288, 5042, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 574, 9, 288, 870, 360, 7665, 450, 83, 690, 450, 83, 7, 450, 334, 2164, 12, 5042, 430, 288, 5145, 14, 1185, 8, 2164, 12, 5042, 9, 1467, 199, 199, 318, 485, 1122, 63, 7660, 63, 23231, 8, 23231, 304, 272, 9033, 275, 661, 1130, 10746, 1180, 297, 283, 1130, 5307, 2238, 297, 283, 1130, 34, 1220, 297, 267, 283, 1130, 16393, 297, 283, 1130, 6241, 358, 272, 1318, 1482, 275, 942, 272, 367, 6285, 315, 8418, 26, 267, 367, 790, 315, 6285, 14, 1612, 837, 288, 340, 790, 315, 9033, 26, 355, 1318, 1482, 14, 740, 8, 9820, 59, 498, 566, 272, 372, 1318, 1482, 421, 199, 318, 1218, 63, 1160, 8, 1450, 63, 694, 12, 1788, 304, 272, 3517, 275, 4163, 450, 469, 267, 283, 1213, 356, 1788, 4439, 21, 1055, 1213, 1062, 267, 283, 1501, 356, 1788, 272, 789, 339, 3517, 63, 515, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 283, 1080, 14, 1360, 358, 272, 543, 1551, 8, 1360, 63, 515, 12, 283, 87, 358, 465, 2547, 26, 267, 2547, 14, 952, 8 ]
[ 747, 199, 646, 2022, 199, 646, 5672, 199, 646, 5145, 199, 646, 7534, 421, 199, 736, 14, 8563, 8, 736, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 11091, 3460, 493, 29658, 199, 736, 14, 8563, 24893, 358, 199, 8578, 275, 747, 14, 515, 14, 904, 8, 736, 14, 9458, 1062, 283, 8578, 358, 199, 199, 12880, 275, 5672, 14, 51, 63, 3927, 16783, 53, 92, 3736, 14, 51, 63, 3927, 3975, 48, 92, 3736, 14, 51, 63, 3867, 3975, 48, 92, 3736, 14, 51, 63, 41, 1092, 2080, 92, 3736, 14, 51, 63, 3867, 22949, 199, 199, 4943, 275, 1449, 11230, 6356, 3517, 30, 199, 28, 1360, 6339, 534, 287, 8423, 523, 665, 2993, 30, 272, 665, 1213, 19418, 1213, 9, 83, 1108, 1213, 30, 272, 665, 2024, 5960, 534, 1624, 13, 24, 8423, 272, 665, 1579, 2928, 534, 9707, 9707, 9707, 1506, 15, 10480, 14, 827, 14, 3596, 7, 2957, 1579, 30, 272, 665, 1579, 2928, 534, 9707, 9707, 9707, 8589, 15, 3596, 15, 13658, 15, 2844, 2075, 25457, 14, 3596, 7, 2957, 1579, 30, 272, 665, 1579, 2928, 534, 9707, 6429, 15, 3596, 15, 8578, 14, 3596, 7, 2957, 1579, 30, 272, 665, 1073, 4369, 534, 9707, 6429, 15, 3919, 15, 2487, 14, 3919, 7, 4668, 534, 15479, 7, 7082, 523, 3068, 2993, 30, 523, 665, 2030, 30, 272, 665, 1579, 30, 489, 4205, 24713, 1501, 9, 83, 11339, 272, 3068, 1579, 30, 523, 3068, 2030, 30, 199, 1108, 1360, 30, 199, 2344, 199, 199, 318, 2198, 63, 589, 837, 272, 1798, 275, 7534, 14, 10730, 342, 272, 1798, 14, 525, 63, 2094, 360, 1001, 358, 272, 1798, 14, 525, 63, 2094, 3654, 84, 297, 2850, 1450, 297, 1415, 29, 549, 9, 272, 372, 6802, 8, 2087, 14, 1122, 63, 589, 1012, 421, 199, 318, 1331, 63, 509, 63, 8578, 8, 2791, 63, 1001, 12, 1947, 304, 272, 1947, 63, 694, 275, 747, 14, 515, 14, 904, 8, 8578, 12, 1947, 9, 272, 340, 440, 747, 14, 515, 14, 2444, 8, 1450, 63, 694, 304, 267, 870, 360, 391, 17443, 450, 83, 7, 450, 1947, 63, 694, 9, 267, 747, 14, 8347, 8, 1450, 63, 694, 9, 272, 5042, 63, 1001, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 1543, 83, 14, 1001, 7, 450, 1947, 9, 272, 870, 360, 7665, 450, 83, 690, 450, 83, 7, 450, 334, 2791, 63, 1001, 12, 5042, 63, 1001, 430, 272, 5145, 14, 1185, 8, 2791, 63, 1001, 12, 5042, 63, 1001, 9, 272, 1218, 63, 1160, 8, 1450, 63, 694, 12, 747, 14, 515, 14, 4846, 8, 5119, 63, 1001, 430, 339, 870, 360, 11660, 316, 367, 9033, 15103, 272, 543, 1551, 8, 5119, 63, 1001, 9, 465, 2547, 26, 267, 666, 275, 2022, 14, 912, 8, 1745, 9, 339, 1318, 1482, 275, 942, 272, 8418, 275, 666, 14, 362, 360, 23231, 358, 272, 340, 666, 459, 2343, 2545, 466, 418, 508, 283, 6831, 7, 436, 8418, 26, 267, 1318, 1482, 14, 2880, 1547, 1122, 63, 7660, 63, 23231, 8, 23231, 430, 339, 5935, 275, 666, 14, 362, 360, 4782, 358, 272, 340, 666, 459, 2343, 2545, 466, 418, 508, 283, 1692, 7, 436, 5935, 26, 267, 367, 1924, 315, 5935, 26, 288, 1318, 1482, 14, 740, 8, 10885, 459, 633, 1105, 2286, 1318, 1482, 275, 769, 8, 409, 8, 27541, 430, 272, 870, 360, 4214, 450, 68, 9033, 7, 450, 822, 8, 27541, 430, 272, 2935, 63, 2791, 275, 747, 14, 515, 14, 3475, 8, 2791, 63, 1001, 9, 272, 367, 14855, 315, 1318, 1482, 26, 267, 14855, 275, 747, 14, 515, 14, 904, 8, 694, 63, 2791, 12, 14855, 9, 267, 5042, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 747, 14, 515, 14, 4846, 8, 12611, 430, 267, 5145, 14, 1185, 8, 12611, 12, 5042, 9, 267, 870, 360, 7665, 450, 83, 690, 450, 83, 7, 450, 334, 12611, 12, 5042, 430, 339, 340, 666, 459, 2343, 2545, 466, 418, 508, 283, 1692, 356, 267, 870, 360, 11660, 316, 367, 2222, 13, 18757, 3400, 358, 267, 367, 3400, 315, 666, 459, 21626, 2565, 288, 1166, 275, 3400, 14, 362, 360, 633, 358, 288, 340, 440, 1166, 26, 1980, 288, 2928, 275, 747, 14, 515, 14, 904, 8, 694, 63, 2791, 12, 1166, 9, 288, 5042, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 1166, 9, 288, 870, 360, 7665, 450, 83, 690, 450, 83, 7, 450, 334, 2164, 12, 5042, 430, 288, 5145, 14, 1185, 8, 2164, 12, 5042, 9, 272, 916, 666, 459, 2343, 2545, 466, 418, 508, 283, 6831, 356, 267, 870, 360, 11660, 316, 367, 5957, 24154, 1584, 358, 267, 367, 790, 315, 661, 22228, 297, 283, 10128, 14126, 735, 288, 862, 26, 355, 574, 275, 666, 59, 498, 61, 288, 871, 4067, 26, 355, 1980, 953, 340, 440, 1228, 8, 585, 12, 620, 304, 355, 1980, 953, 2928, 275, 747, 14, 515, 14, 904, 8, 694, 63, 2791, 12, 574, 9, 288, 5042, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 574, 9, 288, 870, 360, 7665, 450, 83, 690, 450, 83, 7, 450, 334, 2164, 12, 5042, 430, 288, 5145, 14, 1185, 8, 2164, 12, 5042, 9, 1467, 199, 199, 318, 485, 1122, 63, 7660, 63, 23231, 8, 23231, 304, 272, 9033, 275, 661, 1130, 10746, 1180, 297, 283, 1130, 5307, 2238, 297, 283, 1130, 34, 1220, 297, 267, 283, 1130, 16393, 297, 283, 1130, 6241, 358, 272, 1318, 1482, 275, 942, 272, 367, 6285, 315, 8418, 26, 267, 367, 790, 315, 6285, 14, 1612, 837, 288, 340, 790, 315, 9033, 26, 355, 1318, 1482, 14, 740, 8, 9820, 59, 498, 566, 272, 372, 1318, 1482, 421, 199, 318, 1218, 63, 1160, 8, 1450, 63, 694, 12, 1788, 304, 272, 3517, 275, 4163, 450, 469, 267, 283, 1213, 356, 1788, 4439, 21, 1055, 1213, 1062, 267, 283, 1501, 356, 1788, 272, 789, 339, 3517, 63, 515, 275, 747, 14, 515, 14, 904, 8, 1450, 63, 694, 12, 283, 1080, 14, 1360, 358, 272, 543, 1551, 8, 1360, 63, 515, 12, 283, 87, 358, 465, 2547, 26, 267, 2547, 14, 952, 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,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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 ]
joseamaya/tambox
almacen/managers.py
1
2042
# -*- coding: utf-8 -*- from django.db import models class DetalleMovimientoManager(models.Manager): def guardar_detalles_con_referencia(self, objs, orden): requerimiento = None if orden.cotizacion is not None: requerimiento = orden.cotizacion.requerimiento for detalle in objs: detalle_orden = detalle.detalle_orden_compra if detalle_orden.detalle_cotizacion is not None: detalle_requerimiento = detalle_orden.detalle_cotizacion.detalle_requerimiento detalle_requerimiento.cantidad_atendida = detalle_requerimiento.cantidad_atendida + detalle.cantidad detalle_requerimiento.establecer_estado_atendido() detalle_requerimiento.save() detalle_orden.cantidad_ingresada = detalle_orden.cantidad_ingresada + detalle.cantidad detalle_orden.establecer_estado() detalle_orden.save() detalle.save() if requerimiento is not None: requerimiento.establecer_estado_atendido() requerimiento.save() orden.establecer_estado() orden.save() def guardar_detalle_con_pedido(self, objs, pedido): for detalle in objs: detalle_pedido = detalle.detalle_pedido detalle_pedido.cantidad_atendida = detalle_pedido.cantidad_atendida + detalle.cantidad detalle_pedido.establecer_estado_atendido() detalle_pedido.save() detalle.save() pedido.establecer_estado_atendido() pedido.save() def guardar_detalles_sin_referencia(self, objs): cont = 1 for detalle in objs: detalle.save() cont = cont + 1 def bulk_create(self, objs, referencia, pedido): if referencia is not None: self.guardar_detalles_con_referencia(objs, referencia) elif pedido is not None: self.guardar_detalle_con_pedido(objs, pedido) else: self.guardar_detalles_sin_referencia(objs)
gpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 221, 199, 504, 1639, 14, 697, 492, 1709, 421, 199, 533, 577, 386, 4598, 3716, 433, 2664, 287, 475, 2988, 8, 992, 14, 2988, 304, 339, 347, 24453, 285, 63, 9886, 279, 2978, 63, 388, 63, 264, 1485, 16521, 8, 277, 12, 13474, 12, 503, 848, 304, 267, 295, 16891, 1017, 24555, 475, 275, 488, 267, 340, 503, 848, 14, 331, 280, 8076, 9718, 365, 440, 488, 26, 288, 295, 16891, 1017, 24555, 475, 275, 503, 848, 14, 331, 280, 8076, 9718, 14, 264, 16891, 1017, 24555, 475, 267, 367, 20894, 4598, 315, 13474, 26, 288, 20894, 4598, 63, 269, 848, 275, 20894, 4598, 14, 9886, 4598, 63, 269, 848, 63, 863, 345, 288, 340, 20894, 4598, 63, 269, 848, 14, 9886, 4598, 63, 331, 280, 8076, 9718, 365, 440, 488, 26, 355, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 275, 20894, 4598, 63, 269, 848, 14, 9886, 4598, 63, 331, 280, 8076, 9718, 14, 9886, 4598, 63, 264, 16891, 1017, 24555, 475, 355, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 14, 2425, 5700, 350, 63, 323, 78, 328, 983, 275, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 14, 2425, 5700, 350, 63, 323, 78, 328, 983, 435, 20894, 4598, 14, 2425, 5700, 350, 355, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 14, 597, 461, 2247, 63, 597, 5129, 63, 323, 78, 328, 1117, 342, 355, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 14, 2117, 342, 288, 20894, 4598, 63, 269, 848, 14, 2425, 5700, 350, 63, 316, 470, 10641, 275, 20894, 4598, 63, 269, 848, 14, 2425, 5700, 350, 63, 316, 470, 10641, 435, 20894, 4598, 14, 2425, 5700, 350, 288, 20894, 4598, 63, 269, 848, 14, 597, 461, 2247, 63, 597, 5129, 342, 288, 20894, 4598, 63, 269, 848, 14, 2117, 342, 288, 20894, 4598, 14, 2117, 342, 267, 340, 295, 16891, 1017, 24555, 475, 365, 440, 488, 26, 288, 295, 16891, 1017, 24555, 475, 14, 597, 461, 2247, 63, 597, 5129, 63, 323, 78, 328, 1117, 342, 288, 295, 16891, 1017, 24555, 475, 14, 2117, 342, 267, 503, 848, 14, 597, 461, 2247, 63, 597, 5129, 342, 267, 503, 848, 14, 2117, 342, 339, 347, 24453, 285, 63, 9886, 4598, 63, 388, 63, 321, 328, 1117, 8, 277, 12, 13474, 12, 4837, 328, 1117, 304, 267, 367, 20894, 4598, 315, 13474, 26, 288, 20894, 4598, 63, 321, 328, 1117, 275, 20894, 4598, 14, 9886, 4598, 63, 321, 328, 1117, 288, 20894, 4598, 63, 321, 328, 1117, 14, 2425, 5700, 350, 63, 323, 78, 328, 983, 275, 20894, 4598, 63, 321, 328, 1117, 14, 2425, 5700, 350, 63, 323, 78, 328, 983, 435, 20894, 4598, 14, 2425, 5700, 350, 288, 20894, 4598, 63, 321, 328, 1117, 14, 597, 461, 2247, 63, 597, 5129, 63, 323, 78, 328, 1117, 342, 288, 20894, 4598, 63, 321, 328, 1117, 14, 2117, 342, 288, 20894, 4598, 14, 2117, 342, 267, 4837, 328, 1117, 14, 597, 461, 2247, 63, 597, 5129, 63, 323, 78, 328, 1117, 342, 267, 4837, 328, 1117, 14, 2117, 342, 339, 347, 24453, 285, 63, 9886, 279, 2978, 63, 5911, 63, 264, 1485, 16521, 8, 277, 12, 13474, 304, 267, 13770, 275, 413, 267, 367, 20894, 4598, 315, 13474, 26, 288, 20894, 4598, 14, 2117, 342, 288, 13770, 275, 13770, 435, 413, 339, 347, 13137, 63, 981, 8, 277, 12, 13474, 12, 295, 1485, 16521, 12, 4837, 328, 1117, 304, 267, 340, 295, 1485, 16521, 365, 440, 488, 26, 288, 291, 14, 15606, 285, 63, 9886, 279, 2978, 63, 388, 63, 264, 1485, 16521, 8, 8718, 12, 295, 1485, 16521, 9, 267, 916, 4837, 328, 1117, 365, 440, 488, 26, 288, 291, 14, 15606, 285, 63, 9886, 4598, 63, 388, 63, 321, 328, 1117, 8, 8718, 12, 4837, 328, 1117, 9, 267, 587, 26, 288, 291, 14, 15606, 285, 63, 9886, 279, 2978, 63, 5911, 63, 264, 1485, 16521, 8, 8718, 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 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 221, 199, 504, 1639, 14, 697, 492, 1709, 421, 199, 533, 577, 386, 4598, 3716, 433, 2664, 287, 475, 2988, 8, 992, 14, 2988, 304, 339, 347, 24453, 285, 63, 9886, 279, 2978, 63, 388, 63, 264, 1485, 16521, 8, 277, 12, 13474, 12, 503, 848, 304, 267, 295, 16891, 1017, 24555, 475, 275, 488, 267, 340, 503, 848, 14, 331, 280, 8076, 9718, 365, 440, 488, 26, 288, 295, 16891, 1017, 24555, 475, 275, 503, 848, 14, 331, 280, 8076, 9718, 14, 264, 16891, 1017, 24555, 475, 267, 367, 20894, 4598, 315, 13474, 26, 288, 20894, 4598, 63, 269, 848, 275, 20894, 4598, 14, 9886, 4598, 63, 269, 848, 63, 863, 345, 288, 340, 20894, 4598, 63, 269, 848, 14, 9886, 4598, 63, 331, 280, 8076, 9718, 365, 440, 488, 26, 355, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 275, 20894, 4598, 63, 269, 848, 14, 9886, 4598, 63, 331, 280, 8076, 9718, 14, 9886, 4598, 63, 264, 16891, 1017, 24555, 475, 355, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 14, 2425, 5700, 350, 63, 323, 78, 328, 983, 275, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 14, 2425, 5700, 350, 63, 323, 78, 328, 983, 435, 20894, 4598, 14, 2425, 5700, 350, 355, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 14, 597, 461, 2247, 63, 597, 5129, 63, 323, 78, 328, 1117, 342, 355, 20894, 4598, 63, 264, 16891, 1017, 24555, 475, 14, 2117, 342, 288, 20894, 4598, 63, 269, 848, 14, 2425, 5700, 350, 63, 316, 470, 10641, 275, 20894, 4598, 63, 269, 848, 14, 2425, 5700, 350, 63, 316, 470, 10641, 435, 20894, 4598, 14, 2425, 5700, 350, 288, 20894, 4598, 63, 269, 848, 14, 597, 461, 2247, 63, 597, 5129, 342, 288, 20894, 4598, 63, 269, 848, 14, 2117, 342, 288, 20894, 4598, 14, 2117, 342, 267, 340, 295, 16891, 1017, 24555, 475, 365, 440, 488, 26, 288, 295, 16891, 1017, 24555, 475, 14, 597, 461, 2247, 63, 597, 5129, 63, 323, 78, 328, 1117, 342, 288, 295, 16891, 1017, 24555, 475, 14, 2117, 342, 267, 503, 848, 14, 597, 461, 2247, 63, 597, 5129, 342, 267, 503, 848, 14, 2117, 342, 339, 347, 24453, 285, 63, 9886, 4598, 63, 388, 63, 321, 328, 1117, 8, 277, 12, 13474, 12, 4837, 328, 1117, 304, 267, 367, 20894, 4598, 315, 13474, 26, 288, 20894, 4598, 63, 321, 328, 1117, 275, 20894, 4598, 14, 9886, 4598, 63, 321, 328, 1117, 288, 20894, 4598, 63, 321, 328, 1117, 14, 2425, 5700, 350, 63, 323, 78, 328, 983, 275, 20894, 4598, 63, 321, 328, 1117, 14, 2425, 5700, 350, 63, 323, 78, 328, 983, 435, 20894, 4598, 14, 2425, 5700, 350, 288, 20894, 4598, 63, 321, 328, 1117, 14, 597, 461, 2247, 63, 597, 5129, 63, 323, 78, 328, 1117, 342, 288, 20894, 4598, 63, 321, 328, 1117, 14, 2117, 342, 288, 20894, 4598, 14, 2117, 342, 267, 4837, 328, 1117, 14, 597, 461, 2247, 63, 597, 5129, 63, 323, 78, 328, 1117, 342, 267, 4837, 328, 1117, 14, 2117, 342, 339, 347, 24453, 285, 63, 9886, 279, 2978, 63, 5911, 63, 264, 1485, 16521, 8, 277, 12, 13474, 304, 267, 13770, 275, 413, 267, 367, 20894, 4598, 315, 13474, 26, 288, 20894, 4598, 14, 2117, 342, 288, 13770, 275, 13770, 435, 413, 339, 347, 13137, 63, 981, 8, 277, 12, 13474, 12, 295, 1485, 16521, 12, 4837, 328, 1117, 304, 267, 340, 295, 1485, 16521, 365, 440, 488, 26, 288, 291, 14, 15606, 285, 63, 9886, 279, 2978, 63, 388, 63, 264, 1485, 16521, 8, 8718, 12, 295, 1485, 16521, 9, 267, 916, 4837, 328, 1117, 365, 440, 488, 26, 288, 291, 14, 15606, 285, 63, 9886, 4598, 63, 388, 63, 321, 328, 1117, 8, 8718, 12, 4837, 328, 1117, 9, 267, 587, 26, 288, 291, 14, 15606, 285, 63, 9886, 279, 2978, 63, 5911, 63, 264, 1485, 16521, 8, 8718, 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, 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, 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