idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
32,700 | def l1_keepalives ( self , state ) : self . _l1_keepalives = state if state : log . info ( 'IOU "{name}" [{id}]: has activated layer 1 keepalive messages' . format ( name = self . _name , id = self . _id ) ) else : log . info ( 'IOU "{name}" [{id}]: has deactivated layer 1 keepalive messages' . format ( name = self . _... | Enables or disables layer 1 keepalive messages . |
32,701 | def _enable_l1_keepalives ( self , command ) : env = os . environ . copy ( ) if "IOURC" not in os . environ : env [ "IOURC" ] = self . iourc_path try : output = yield from gns3server . utils . asyncio . subprocess_check_output ( self . _path , "-h" , cwd = self . working_dir , env = env , stderr = True ) if re . search... | Enables L1 keepalive messages if supported . |
32,702 | def startup_config_content ( self ) : config_file = self . startup_config_file if config_file is None : return None try : with open ( config_file , "rb" ) as f : return f . read ( ) . decode ( "utf-8" , errors = "replace" ) except OSError as e : raise IOUError ( "Can't read startup-config file '{}': {}" . format ( conf... | Returns the content of the current startup - config file . |
32,703 | def startup_config_content ( self , startup_config ) : try : startup_config_path = os . path . join ( self . working_dir , "startup-config.cfg" ) if startup_config is None : startup_config = '' if len ( startup_config ) == 0 and os . path . exists ( startup_config_path ) : return with open ( startup_config_path , 'w+' ... | Update the startup config |
32,704 | def private_config_content ( self ) : config_file = self . private_config_file if config_file is None : return None try : with open ( config_file , "rb" ) as f : return f . read ( ) . decode ( "utf-8" , errors = "replace" ) except OSError as e : raise IOUError ( "Can't read private-config file '{}': {}" . format ( conf... | Returns the content of the current private - config file . |
32,705 | def private_config_content ( self , private_config ) : try : private_config_path = os . path . join ( self . working_dir , "private-config.cfg" ) if private_config is None : private_config = '' if len ( private_config ) == 0 and os . path . exists ( private_config_path ) : return with open ( private_config_path , 'w+' ... | Update the private config |
32,706 | def startup_config_file ( self ) : path = os . path . join ( self . working_dir , 'startup-config.cfg' ) if os . path . exists ( path ) : return path else : return None | Returns the startup - config file for this IOU VM . |
32,707 | def private_config_file ( self ) : path = os . path . join ( self . working_dir , 'private-config.cfg' ) if os . path . exists ( path ) : return path else : return None | Returns the private - config file for this IOU VM . |
32,708 | def relative_startup_config_file ( self ) : path = os . path . join ( self . working_dir , 'startup-config.cfg' ) if os . path . exists ( path ) : return 'startup-config.cfg' else : return None | Returns the startup - config file relative to the project directory . It s compatible with pre 1 . 3 projects . |
32,709 | def relative_private_config_file ( self ) : path = os . path . join ( self . working_dir , 'private-config.cfg' ) if os . path . exists ( path ) : return 'private-config.cfg' else : return None | Returns the private - config file relative to the project directory . |
32,710 | def svg ( self , value ) : if len ( value ) < 500 : self . _svg = value return try : root = ET . fromstring ( value ) except ET . ParseError as e : log . error ( "Can't parse SVG: {}" . format ( e ) ) return ET . register_namespace ( 'xmlns' , "http://www.w3.org/2000/svg" ) ET . register_namespace ( 'xmlns:xlink' , "ht... | Set SVG field value . |
32,711 | def update ( self , ** kwargs ) : svg_changed = False for prop in kwargs : if prop == "drawing_id" : pass elif getattr ( self , prop ) != kwargs [ prop ] : if prop == "svg" : svg_changed = True setattr ( self , prop , kwargs [ prop ] ) data = self . __json__ ( ) if not svg_changed : del data [ "svg" ] self . _project .... | Update the drawing |
32,712 | def create_node ( self , * args , ** kwargs ) : node = yield from super ( ) . create_node ( * args , ** kwargs ) self . _free_mac_ids . setdefault ( node . project . id , list ( range ( 0 , 255 ) ) ) try : self . _used_mac_ids [ node . id ] = self . _free_mac_ids [ node . project . id ] . pop ( 0 ) except IndexError : ... | Creates a new VPCS VM . |
32,713 | def close_node ( self , node_id , * args , ** kwargs ) : node = self . get_node ( node_id ) if node_id in self . _used_mac_ids : i = self . _used_mac_ids [ node_id ] self . _free_mac_ids [ node . project . id ] . insert ( 0 , i ) del self . _used_mac_ids [ node_id ] yield from super ( ) . close_node ( node_id , * args ... | Closes a VPCS VM . |
32,714 | def delete ( self ) : if self . _input_filter or self . _output_filter : yield from self . unbind_filter ( "both" ) yield from self . _hypervisor . send ( "nio delete {}" . format ( self . _name ) ) log . info ( "NIO {name} has been deleted" . format ( name = self . _name ) ) | Deletes this NIO . |
32,715 | def rename ( self , new_name ) : yield from self . _hypervisor . send ( "nio rename {name} {new_name}" . format ( name = self . _name , new_name = new_name ) ) log . info ( "NIO {name} renamed to {new_name}" . format ( name = self . _name , new_name = new_name ) ) self . _name = new_name | Renames this NIO |
32,716 | def bind_filter ( self , direction , filter_name ) : if direction not in self . _dynamips_direction : raise DynamipsError ( "Unknown direction {} to bind filter {}:" . format ( direction , filter_name ) ) dynamips_direction = self . _dynamips_direction [ direction ] yield from self . _hypervisor . send ( "nio bind_filt... | Adds a packet filter to this NIO . Filter freq_drop drops packets . Filter capture captures packets . |
32,717 | def unbind_filter ( self , direction ) : if direction not in self . _dynamips_direction : raise DynamipsError ( "Unknown direction {} to unbind filter:" . format ( direction ) ) dynamips_direction = self . _dynamips_direction [ direction ] yield from self . _hypervisor . send ( "nio unbind_filter {name} {direction}" . ... | Removes packet filter for this NIO . |
32,718 | def setup_filter ( self , direction , options ) : if direction not in self . _dynamips_direction : raise DynamipsError ( "Unknown direction {} to setup filter:" . format ( direction ) ) dynamips_direction = self . _dynamips_direction [ direction ] yield from self . _hypervisor . send ( "nio setup_filter {name} {directi... | Setups a packet filter bound with this NIO . |
32,719 | def get_stats ( self ) : stats = yield from self . _hypervisor . send ( "nio get_stats {}" . format ( self . _name ) ) return stats [ 0 ] | Gets statistics for this NIO . |
32,720 | def set_bandwidth ( self , bandwidth ) : yield from self . _hypervisor . send ( "nio set_bandwidth {name} {bandwidth}" . format ( name = self . _name , bandwidth = bandwidth ) ) self . _bandwidth = bandwidth | Sets bandwidth constraint . |
32,721 | def create ( self ) : data = self . _node_data ( ) data [ "node_id" ] = self . _id if self . _node_type == "docker" : timeout = None else : timeout = 1200 trial = 0 while trial != 6 : try : response = yield from self . _compute . post ( "/projects/{}/{}/nodes" . format ( self . _project . id , self . _node_type ) , dat... | Create the node on the compute server |
32,722 | def update ( self , ** kwargs ) : update_compute = False old_json = self . __json__ ( ) compute_properties = None for prop in kwargs : if getattr ( self , prop ) != kwargs [ prop ] : if prop not in self . CONTROLLER_ONLY_PROPERTIES : update_compute = True if prop == "properties" : compute_properties = kwargs [ prop ] e... | Update the node on the compute server |
32,723 | def parse_node_response ( self , response ) : for key , value in response . items ( ) : if key == "console" : self . _console = value elif key == "node_directory" : self . _node_directory = value elif key == "command_line" : self . _command_line = value elif key == "status" : self . _status = value elif key == "console... | Update the object with the remote node object |
32,724 | def _node_data ( self , properties = None ) : if properties : data = copy . copy ( properties ) else : data = copy . copy ( self . _properties ) mapping = { "base_script_file" : "startup_script" , "startup_config" : "startup_config_content" , "private_config" : "private_config_content" , } for k , v in mapping . items ... | Prepare node data to send to the remote controller |
32,725 | def reload ( self ) : try : yield from self . post ( "/reload" , timeout = 240 ) except asyncio . TimeoutError : raise aiohttp . web . HTTPRequestTimeout ( text = "Timeout when reloading {}" . format ( self . _name ) ) | Suspend a node |
32,726 | def _upload_missing_image ( self , type , img ) : for directory in images_directories ( type ) : image = os . path . join ( directory , img ) if os . path . exists ( image ) : self . project . controller . notification . emit ( "log.info" , { "message" : "Uploading missing image {}" . format ( img ) } ) try : with open... | Search an image on local computer and upload it to remote compute if the image exists |
32,727 | def dynamips_auto_idlepc ( self ) : return ( yield from self . _compute . get ( "/projects/{}/{}/nodes/{}/auto_idlepc" . format ( self . _project . id , self . _node_type , self . _id ) , timeout = 240 ) ) . json | Compute the idle PC for a dynamips node |
32,728 | def get_port ( self , adapter_number , port_number ) : for port in self . ports : if port . adapter_number == adapter_number and port . port_number == port_number : return port return None | Return the port for this adapter_number and port_number or returns None if the port is not found |
32,729 | def set_chassis ( self , chassis ) : yield from self . _hypervisor . send ( 'c1700 set_chassis "{name}" {chassis}' . format ( name = self . _name , chassis = chassis ) ) log . info ( 'Router "{name}" [{id}]: chassis set to {chassis}' . format ( name = self . _name , id = self . _id , chassis = chassis ) ) self . _chass... | Sets the chassis . |
32,730 | def load_topology ( path ) : log . debug ( "Read topology %s" , path ) try : with open ( path , encoding = "utf-8" ) as f : topo = json . load ( f ) except ( OSError , UnicodeDecodeError , ValueError ) as e : raise aiohttp . web . HTTPConflict ( text = "Could not load topology {}: {}" . format ( path , str ( e ) ) ) if... | Open a topology file patch it for last GNS3 release and return it |
32,731 | def _convert_2_0_0 ( topo , topo_path ) : topo [ "revision" ] = 8 for node in topo . get ( "topology" , { } ) . get ( "nodes" , [ ] ) : if "properties" in node : if node [ "node_type" ] == "vpcs" : if "startup_script_path" in node [ "properties" ] : del node [ "properties" ] [ "startup_script_path" ] if "startup_script... | Convert topologies from GNS3 2 . 0 . 0 to 2 . 1 |
32,732 | def _convert_2_0_0_beta_2 ( topo , topo_path ) : topo_dir = os . path . dirname ( topo_path ) topo [ "revision" ] = 7 for node in topo . get ( "topology" , { } ) . get ( "nodes" , [ ] ) : if node [ "node_type" ] == "dynamips" : node_id = node [ "node_id" ] dynamips_id = node [ "properties" ] [ "dynamips_id" ] dynamips_... | Convert topologies from GNS3 2 . 0 . 0 beta 2 to beta 3 . |
32,733 | def _convert_2_0_0_alpha ( topo , topo_path ) : topo [ "revision" ] = 6 for node in topo . get ( "topology" , { } ) . get ( "nodes" , [ ] ) : if node . get ( "console_type" ) == "serial" : node [ "console_type" ] = "telnet" if node [ "node_type" ] in ( "vmware" , "virtualbox" ) : prop = node . get ( "properties" ) if "... | Convert topologies from GNS3 2 . 0 . 0 alpha to 2 . 0 . 0 final . |
32,734 | def _convert_label ( label ) : style = qt_font_to_style ( label . get ( "font" ) , label . get ( "color" ) ) return { "text" : html . escape ( label [ "text" ] ) , "rotation" : 0 , "style" : style , "x" : int ( label [ "x" ] ) , "y" : int ( label [ "y" ] ) } | Convert a label from 1 . X to the new format |
32,735 | def _convert_snapshots ( topo_dir ) : old_snapshots_dir = os . path . join ( topo_dir , "project-files" , "snapshots" ) if os . path . exists ( old_snapshots_dir ) : new_snapshots_dir = os . path . join ( topo_dir , "snapshots" ) os . makedirs ( new_snapshots_dir ) for snapshot in os . listdir ( old_snapshots_dir ) : s... | Convert 1 . x snapshot to the new format |
32,736 | def _convert_qemu_node ( node , old_node ) : if old_node . get ( "properties" , { } ) . get ( "hda_disk_image_md5sum" ) == "8ebc5a6ec53a1c05b7aa101b5ceefe31" : node [ "console" ] = None node [ "console_type" ] = None node [ "node_type" ] = "nat" del old_node [ "properties" ] node [ "properties" ] = { "ports" : [ { "int... | Convert qemu node from 1 . X to 2 . 0 |
32,737 | def open_required ( func ) : def wrapper ( self , * args , ** kwargs ) : if self . _status == "closed" : raise aiohttp . web . HTTPForbidden ( text = "The project is not opened" ) return func ( self , * args , ** kwargs ) return wrapper | Use this decorator to raise an error if the project is not opened |
32,738 | def captures_directory ( self ) : path = os . path . join ( self . _path , "project-files" , "captures" ) os . makedirs ( path , exist_ok = True ) return path | Location of the captures files |
32,739 | def remove_allocated_node_name ( self , name ) : if name in self . _allocated_node_names : self . _allocated_node_names . remove ( name ) | Removes an allocated node name |
32,740 | def update_allocated_node_name ( self , base_name ) : if base_name is None : return None base_name = re . sub ( r"[ ]" , "" , base_name ) if base_name in self . _allocated_node_names : base_name = re . sub ( r"[0-9]+$" , "{0}" , base_name ) if '{0}' in base_name or '{id}' in base_name : for number in range ( 1 , 100000... | Updates a node name or generate a new if no node name is available . |
32,741 | def add_node_from_appliance ( self , appliance_id , x = 0 , y = 0 , compute_id = None ) : try : template = self . controller . appliances [ appliance_id ] . data except KeyError : msg = "Appliance {} doesn't exist" . format ( appliance_id ) log . error ( msg ) raise aiohttp . web . HTTPNotFound ( text = msg ) template ... | Create a node from an appliance |
32,742 | def add_node ( self , compute , name , node_id , dump = True , node_type = None , ** kwargs ) : if node_id in self . _nodes : return self . _nodes [ node_id ] node = Node ( self , compute , name , node_id = node_id , node_type = node_type , ** kwargs ) if compute not in self . _project_created_on_compute : if compute .... | Create a node or return an existing node |
32,743 | def __delete_node_links ( self , node ) : for link in list ( self . _links . values ( ) ) : if node in link . nodes : yield from self . delete_link ( link . id , force_delete = True ) | Delete all link connected to this node . |
32,744 | def get_node ( self , node_id ) : try : return self . _nodes [ node_id ] except KeyError : raise aiohttp . web . HTTPNotFound ( text = "Node ID {} doesn't exist" . format ( node_id ) ) | Return the node or raise a 404 if the node is unknown |
32,745 | def add_drawing ( self , drawing_id = None , dump = True , ** kwargs ) : if drawing_id not in self . _drawings : drawing = Drawing ( self , drawing_id = drawing_id , ** kwargs ) self . _drawings [ drawing . id ] = drawing self . controller . notification . emit ( "drawing.created" , drawing . __json__ ( ) ) if dump : s... | Create an drawing or return an existing drawing |
32,746 | def get_drawing ( self , drawing_id ) : try : return self . _drawings [ drawing_id ] except KeyError : raise aiohttp . web . HTTPNotFound ( text = "Drawing ID {} doesn't exist" . format ( drawing_id ) ) | Return the Drawing or raise a 404 if the drawing is unknown |
32,747 | def add_link ( self , link_id = None , dump = True ) : if link_id and link_id in self . _links : return self . _links [ link_id ] link = UDPLink ( self , link_id = link_id ) self . _links [ link . id ] = link if dump : self . dump ( ) return link | Create a link . By default the link is empty |
32,748 | def get_link ( self , link_id ) : try : return self . _links [ link_id ] except KeyError : raise aiohttp . web . HTTPNotFound ( text = "Link ID {} doesn't exist" . format ( link_id ) ) | Return the Link or raise a 404 if the link is unknown |
32,749 | def get_snapshot ( self , snapshot_id ) : try : return self . _snapshots [ snapshot_id ] except KeyError : raise aiohttp . web . HTTPNotFound ( text = "Snapshot ID {} doesn't exist" . format ( snapshot_id ) ) | Return the snapshot or raise a 404 if the snapshot is unknown |
32,750 | def snapshot ( self , name ) : if name in [ snap . name for snap in self . snapshots . values ( ) ] : raise aiohttp . web_exceptions . HTTPConflict ( text = "The snapshot {} already exist" . format ( name ) ) snapshot = Snapshot ( self , name = name ) try : if os . path . exists ( snapshot . path ) : raise aiohttp . we... | Snapshot the project |
32,751 | def _cleanPictures ( self ) : if not os . path . exists ( self . path ) : return try : pictures = set ( os . listdir ( self . pictures_directory ) ) for drawing in self . _drawings . values ( ) : try : pictures . remove ( drawing . ressource_filename ) except KeyError : pass for pict in pictures : os . remove ( os . pa... | Delete unused images |
32,752 | def delete_on_computes ( self ) : for compute in list ( self . _project_created_on_compute ) : if compute . id != "local" : yield from compute . delete ( "/projects/{}" . format ( self . _id ) ) self . _project_created_on_compute . remove ( compute ) | Delete the project on computes but not on controller |
32,753 | def duplicate ( self , name = None , location = None ) : previous_status = self . _status if self . _status == "closed" : yield from self . open ( ) self . dump ( ) try : with tempfile . TemporaryDirectory ( ) as tmpdir : zipstream = yield from export_project ( self , tmpdir , keep_compute_id = True , allow_all_nodes =... | Duplicate a project |
32,754 | def is_running ( self ) : for node in self . _nodes . values ( ) : if node . status != "stopped" and not node . is_always_running ( ) : return True return False | If a node is started or paused return True |
32,755 | def dump ( self ) : try : topo = project_to_topology ( self ) path = self . _topology_file ( ) log . debug ( "Write %s" , path ) with open ( path + ".tmp" , "w+" , encoding = "utf-8" ) as f : json . dump ( topo , f , indent = 4 , sort_keys = True ) shutil . move ( path + ".tmp" , path ) except OSError as e : raise aioh... | Dump topology to disk |
32,756 | def start_all ( self ) : pool = Pool ( concurrency = 3 ) for node in self . nodes . values ( ) : pool . append ( node . start ) yield from pool . join ( ) | Start all nodes |
32,757 | def stop_all ( self ) : pool = Pool ( concurrency = 3 ) for node in self . nodes . values ( ) : pool . append ( node . stop ) yield from pool . join ( ) | Stop all nodes |
32,758 | def suspend_all ( self ) : pool = Pool ( concurrency = 3 ) for node in self . nodes . values ( ) : pool . append ( node . suspend ) yield from pool . join ( ) | Suspend all nodes |
32,759 | def _get_match ( self , prefix ) : if _cpr_response_re . match ( prefix ) : return Keys . CPRResponse elif _mouse_event_re . match ( prefix ) : return Keys . Vt100MouseEvent try : return ANSI_SEQUENCES [ prefix ] except KeyError : return None | Return the key that maps to this prefix . |
32,760 | def _call_handler ( self , key , insert_text ) : if isinstance ( key , tuple ) : for k in key : self . _call_handler ( k , insert_text ) else : if key == Keys . BracketedPaste : self . _in_bracketed_paste = True self . _paste_buffer = '' else : self . feed_key_callback ( KeyPress ( key , insert_text ) ) | Callback to handler . |
32,761 | def feed ( self , data ) : assert isinstance ( data , six . text_type ) if _DEBUG_RENDERER_INPUT : self . LOG . write ( repr ( data ) . encode ( 'utf-8' ) + b'\n' ) self . LOG . flush ( ) if self . _in_bracketed_paste : self . _paste_buffer += data end_mark = '\x1b[201~' if end_mark in self . _paste_buffer : end_index ... | Feed the input stream . |
32,762 | def query ( self , method , path , data = { } , params = { } ) : response = yield from self . http_query ( method , path , data = data , params = params ) body = yield from response . read ( ) if body and len ( body ) : if response . headers [ 'CONTENT-TYPE' ] == 'application/json' : body = json . loads ( body . decode... | Make a query to the docker daemon and decode the request |
32,763 | def http_query ( self , method , path , data = { } , params = { } , timeout = 300 ) : data = json . dumps ( data ) if timeout is None : timeout = 60 * 60 * 24 * 31 if path == 'version' : url = "http://docker/v1.12/" + path else : url = "http://docker/v" + DOCKER_MINIMUM_API_VERSION + "/" + path try : if path != "versio... | Make a query to the docker daemon |
32,764 | def websocket_query ( self , path , params = { } ) : url = "http://docker/v" + self . _api_version + "/" + path connection = yield from self . _session . ws_connect ( url , origin = "http://docker" , autoping = True ) return connection | Open a websocket connection |
32,765 | def list_images ( self ) : images = [ ] for image in ( yield from self . query ( "GET" , "images/json" , params = { "all" : 0 } ) ) : if image [ 'RepoTags' ] : for tag in image [ 'RepoTags' ] : if tag != "<none>:<none>" : images . append ( { 'image' : tag } ) return sorted ( images , key = lambda i : i [ 'image' ] ) | Gets Docker image list . |
32,766 | def get_kvm_archs ( ) : kvm = [ ] if not os . path . exists ( "/dev/kvm" ) : return kvm arch = platform . machine ( ) if arch == "x86_64" : kvm . append ( "x86_64" ) kvm . append ( "i386" ) elif arch == "i386" : kvm . append ( "i386" ) else : kvm . append ( platform . machine ( ) ) return kvm | Gets a list of architectures for which KVM is available on this server . |
32,767 | def paths_list ( ) : paths = set ( ) try : paths . add ( os . getcwd ( ) ) except FileNotFoundError : log . warning ( "The current working directory doesn't exist" ) if "PATH" in os . environ : paths . update ( os . environ [ "PATH" ] . split ( os . pathsep ) ) else : log . warning ( "The PATH environment variable does... | Gets a folder list of possibly available QEMU binaries on the host . |
32,768 | def binary_list ( archs = None ) : qemus = [ ] for path in Qemu . paths_list ( ) : try : for f in os . listdir ( path ) : if f . endswith ( "-spice" ) : continue if ( f . startswith ( "qemu-system" ) or f . startswith ( "qemu-kvm" ) or f == "qemu" or f == "qemu.exe" ) and os . access ( os . path . join ( path , f ) , o... | Gets QEMU binaries list available on the host . |
32,769 | def img_binary_list ( ) : qemu_imgs = [ ] for path in Qemu . paths_list ( ) : try : for f in os . listdir ( path ) : if ( f == "qemu-img" or f == "qemu-img.exe" ) and os . access ( os . path . join ( path , f ) , os . X_OK ) and os . path . isfile ( os . path . join ( path , f ) ) : qemu_path = os . path . join ( path ... | Gets QEMU - img binaries list available on the host . |
32,770 | def get_qemu_version ( qemu_path ) : if sys . platform . startswith ( "win" ) : version_file = os . path . join ( os . path . dirname ( qemu_path ) , "version.txt" ) if os . path . isfile ( version_file ) : try : with open ( version_file , "rb" ) as file : version = file . read ( ) . decode ( "utf-8" ) . strip ( ) matc... | Gets the Qemu version . |
32,771 | def _get_qemu_img_version ( qemu_img_path ) : try : output = yield from subprocess_check_output ( qemu_img_path , "--version" ) match = re . search ( "version\s+([0-9a-z\-\.]+)" , output ) if match : version = match . group ( 1 ) return version else : raise QemuError ( "Could not determine the Qemu-img version for {}" ... | Gets the Qemu - img version . |
32,772 | def create_disk ( self , qemu_img , path , options ) : try : img_format = options . pop ( "format" ) img_size = options . pop ( "size" ) if not os . path . isabs ( path ) : directory = self . get_images_directory ( ) os . makedirs ( directory , exist_ok = True ) path = os . path . join ( directory , os . path . basenam... | Create a qemu disk with qemu - img |
32,773 | def set_npartitions ( self , npartitions = None ) : if npartitions is None : self . _npartitions = cpu_count ( ) * 2 else : self . _npartitions = npartitions return self | Set the number of partitions to use for dask |
32,774 | def rolling ( self , window , min_periods = None , center = False , win_type = None , on = None , axis = 0 , closed = None ) : kwds = { "window" : window , "min_periods" : min_periods , "center" : center , "win_type" : win_type , "on" : on , "axis" : axis , "closed" : closed , } return Rolling ( self . _obj , self . _n... | Create a swifter rolling object |
32,775 | def apply ( self , func , * args , ** kwds ) : wrapped = self . _wrapped_apply ( func , * args , ** kwds ) n_repeats = 3 timed = timeit . timeit ( wrapped , number = n_repeats ) samp_proc_est = timed / n_repeats est_apply_duration = samp_proc_est / self . _SAMP_SIZE * self . _nrows if est_apply_duration > self . _dask_... | Apply the function to the transformed swifter object |
32,776 | def using_config ( _func = None ) : def decorator ( func ) : @ wraps ( func ) def inner_dec ( * args , ** kwargs ) : g = func . __globals__ var_name = 'config' sentinel = object ( ) oldvalue = g . get ( var_name , sentinel ) g [ var_name ] = apps . get_app_config ( 'django_summernote' ) . config try : res = func ( * ar... | This allows a function to use Summernote configuration as a global variable temporarily . |
32,777 | def uploaded_filepath ( instance , filename ) : ext = filename . split ( '.' ) [ - 1 ] filename = "%s.%s" % ( uuid . uuid4 ( ) , ext ) today = datetime . now ( ) . strftime ( '%Y-%m-%d' ) return os . path . join ( 'django-summernote' , today , filename ) | Returns default filepath for uploaded files . |
32,778 | def get_attachment_model ( ) : try : from . models import AbstractAttachment klass = apps . get_model ( config [ "attachment_model" ] ) if not issubclass ( klass , AbstractAttachment ) : raise ImproperlyConfigured ( "SUMMERNOTE_CONFIG['attachment_model'] refers to model '%s' that is not " "inherited from 'django_summer... | Returns the Attachment model that is active in this project . |
32,779 | def numeric_part ( s ) : m = re_numeric_part . match ( s ) if m : return int ( m . group ( 1 ) ) return None | Returns the leading numeric part of a string . |
32,780 | def literal ( self , o ) : if isinstance ( o , unicode ) : s = self . string_literal ( o . encode ( self . encoding ) ) elif isinstance ( o , bytearray ) : s = self . _bytes_literal ( o ) elif isinstance ( o , bytes ) : if PY2 : s = self . string_literal ( o ) else : s = self . _bytes_literal ( o ) elif isinstance ( o ... | If o is a single object returns an SQL literal as a string . If o is a non - string sequence the items of the sequence are converted and returned as a sequence . |
32,781 | def set_character_set ( self , charset ) : if charset in ( "utf8mb4" , "utf8mb3" ) : py_charset = "utf8" else : py_charset = charset if self . character_set_name ( ) != charset : try : super ( Connection , self ) . set_character_set ( charset ) except AttributeError : if self . _server_version < ( 4 , 1 ) : raise NotSu... | Set the connection character set to charset . The character set can only be changed in MySQL - 4 . 1 and newer . If you try to change the character set from the current value in an older version NotSupportedError will be raised . |
32,782 | def set_sql_mode ( self , sql_mode ) : if self . _server_version < ( 4 , 1 ) : raise NotSupportedError ( "server is too old to set sql_mode" ) self . query ( "SET SESSION sql_mode='%s'" % sql_mode ) self . store_result ( ) | Set the connection sql_mode . See MySQL documentation for legal values . |
32,783 | def close ( self ) : try : if self . connection is None : return while self . nextset ( ) : pass finally : self . connection = None self . _result = None | Close the cursor . No further queries will be possible . |
32,784 | async def fetchrow ( self , * , timeout = None ) : r self . _check_ready ( ) if self . _exhausted : return None recs = await self . _exec ( 1 , timeout ) if len ( recs ) < 1 : self . _exhausted = True return None return recs [ 0 ] | r Return the next row . |
32,785 | def guarded ( meth ) : @ functools . wraps ( meth ) def _check ( self , * args , ** kwargs ) : self . _check_conn_validity ( meth . __name__ ) return meth ( self , * args , ** kwargs ) return _check | A decorator to add a sanity check to ConnectionResource methods . |
32,786 | def start ( self , wait = 60 , * , server_settings = { } , ** opts ) : status = self . get_status ( ) if status == 'running' : return elif status == 'not-initialized' : raise ClusterError ( 'cluster in {!r} has not been initialized' . format ( self . _data_dir ) ) port = opts . pop ( 'port' , None ) if port == 'dynamic... | Start the cluster . |
32,787 | def reload ( self ) : status = self . get_status ( ) if status != 'running' : raise ClusterError ( 'cannot reload: cluster is not running' ) process = subprocess . run ( [ self . _pg_ctl , 'reload' , '-D' , self . _data_dir ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) stderr = process . stderr if proce... | Reload server configuration . |
32,788 | def reset_hba ( self ) : status = self . get_status ( ) if status == 'not-initialized' : raise ClusterError ( 'cannot modify HBA records: cluster is not initialized' ) pg_hba = os . path . join ( self . _data_dir , 'pg_hba.conf' ) try : with open ( pg_hba , 'w' ) : pass except IOError as e : raise ClusterError ( 'canno... | Remove all records from pg_hba . conf . |
32,789 | def add_hba_entry ( self , * , type = 'host' , database , user , address = None , auth_method , auth_options = None ) : status = self . get_status ( ) if status == 'not-initialized' : raise ClusterError ( 'cannot modify HBA records: cluster is not initialized' ) if type not in { 'local' , 'host' , 'hostssl' , 'hostnoss... | Add a record to pg_hba . conf . |
32,790 | async def connect ( dsn = None , * , host = None , port = None , user = None , password = None , passfile = None , database = None , loop = None , timeout = 60 , statement_cache_size = 100 , max_cached_statement_lifetime = 300 , max_cacheable_statement_size = 1024 * 15 , command_timeout = None , ssl = None , connection... | r A coroutine to establish a connection to a PostgreSQL server . |
32,791 | async def add_listener ( self , channel , callback ) : self . _check_open ( ) if channel not in self . _listeners : await self . fetch ( 'LISTEN {}' . format ( utils . _quote_ident ( channel ) ) ) self . _listeners [ channel ] = set ( ) self . _listeners [ channel ] . add ( callback ) | Add a listener for Postgres notifications . |
32,792 | async def remove_listener ( self , channel , callback ) : if self . is_closed ( ) : return if channel not in self . _listeners : return if callback not in self . _listeners [ channel ] : return self . _listeners [ channel ] . remove ( callback ) if not self . _listeners [ channel ] : del self . _listeners [ channel ] a... | Remove a listening callback on the specified channel . |
32,793 | def add_log_listener ( self , callback ) : if self . is_closed ( ) : raise exceptions . InterfaceError ( 'connection is closed' ) self . _log_listeners . add ( callback ) | Add a listener for Postgres log messages . |
32,794 | async def copy_from_table ( self , table_name , * , output , columns = None , schema_name = None , timeout = None , format = None , oids = None , delimiter = None , null = None , header = None , quote = None , escape = None , force_quote = None , encoding = None ) : tabname = utils . _quote_ident ( table_name ) if sche... | Copy table contents to a file or file - like object . |
32,795 | async def copy_from_query ( self , query , * args , output , timeout = None , format = None , oids = None , delimiter = None , null = None , header = None , quote = None , escape = None , force_quote = None , encoding = None ) : opts = self . _format_copy_opts ( format = format , oids = oids , delimiter = delimiter , n... | Copy the results of a query to a file or file - like object . |
32,796 | async def copy_to_table ( self , table_name , * , source , columns = None , schema_name = None , timeout = None , format = None , oids = None , freeze = None , delimiter = None , null = None , header = None , quote = None , escape = None , force_quote = None , force_not_null = None , force_null = None , encoding = None... | Copy data to the specified table . |
32,797 | async def copy_records_to_table ( self , table_name , * , records , columns = None , schema_name = None , timeout = None ) : tabname = utils . _quote_ident ( table_name ) if schema_name : tabname = utils . _quote_ident ( schema_name ) + '.' + tabname if columns : col_list = ', ' . join ( utils . _quote_ident ( c ) for ... | Copy a list of records to the specified table using binary COPY . |
32,798 | async def set_builtin_type_codec ( self , typename , * , schema = 'public' , codec_name , format = None ) : self . _check_open ( ) typeinfo = await self . fetchrow ( introspection . TYPE_BY_NAME , typename , schema ) if not typeinfo : raise exceptions . InterfaceError ( 'unknown type: {}.{}' . format ( schema , typenam... | Set a builtin codec for the specified scalar data type . |
32,799 | async def close ( self , * , timeout = None ) : try : if not self . is_closed ( ) : await self . _protocol . close ( timeout ) except Exception : self . _abort ( ) raise finally : self . _cleanup ( ) | Close the connection gracefully . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.