query stringlengths 5 1.23k | positive stringlengths 53 15.2k | id_ int64 0 252k | task_name stringlengths 87 242 | negative listlengths 20 553 |
|---|---|---|---|---|
Break the filter up into bins and apply a throughput to each bin useful for G141 G102 and other grisms | def bin ( self , n_bins = 1 , pixels_per_bin = None , wave_min = None , wave_max = None ) : # Get wavelength limits if wave_min is not None : self . wave_min = wave_min if wave_max is not None : self . wave_max = wave_max # Trim the wavelength by the given min and max raw_wave = self . raw [ 0 ] whr = np . logical_and ( raw_wave * q . AA >= self . wave_min , raw_wave * q . AA <= self . wave_max ) self . wave = ( raw_wave [ whr ] * q . AA ) . to ( self . wave_units ) self . throughput = self . raw [ 1 ] [ whr ] print ( 'Bandpass trimmed to' , '{} - {}' . format ( self . wave_min , self . wave_max ) ) # Calculate the number of bins and channels pts = len ( self . wave ) if isinstance ( pixels_per_bin , int ) : self . pixels_per_bin = pixels_per_bin self . n_bins = int ( pts / self . pixels_per_bin ) elif isinstance ( n_bins , int ) : self . n_bins = n_bins self . pixels_per_bin = int ( pts / self . n_bins ) else : raise ValueError ( "Please specify 'n_bins' OR 'pixels_per_bin' as integers." ) print ( '{} bins of {} pixels each.' . format ( self . n_bins , self . pixels_per_bin ) ) # Trim throughput edges so that there are an integer number of bins new_len = self . n_bins * self . pixels_per_bin start = ( pts - new_len ) // 2 self . wave = self . wave [ start : new_len + start ] . reshape ( self . n_bins , self . pixels_per_bin ) self . throughput = self . throughput [ start : new_len + start ] . reshape ( self . n_bins , self . pixels_per_bin ) | 11,100 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L326-L376 | [
"def",
"list_locales",
"(",
"self",
")",
"->",
"List",
"[",
"Optional",
"[",
"Text",
"]",
"]",
":",
"locales",
"=",
"list",
"(",
"self",
".",
"dict",
".",
"keys",
"(",
")",
")",
"if",
"not",
"locales",
":",
"locales",
".",
"append",
"(",
"None",
")",
"return",
"locales"
] |
A getter for the wavelength bin centers and average fluxes | def centers ( self ) : # Get the bin centers w_cen = np . nanmean ( self . wave . value , axis = 1 ) f_cen = np . nanmean ( self . throughput , axis = 1 ) return np . asarray ( [ w_cen , f_cen ] ) | 11,101 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L379-L385 | [
"async",
"def",
"process_events_async",
"(",
"self",
",",
"events",
")",
":",
"if",
"events",
":",
"# Synchronize to serialize calls to the processor. The handler is not installed until",
"# after OpenAsync returns, so ProcessEventsAsync cannot conflict with OpenAsync. There",
"# could be a conflict between ProcessEventsAsync and CloseAsync, however. All calls to",
"# CloseAsync are protected by synchronizing too.",
"try",
":",
"last",
"=",
"events",
"[",
"-",
"1",
"]",
"if",
"last",
"is",
"not",
"None",
":",
"self",
".",
"partition_context",
".",
"set_offset_and_sequence_number",
"(",
"last",
")",
"await",
"self",
".",
"processor",
".",
"process_events_async",
"(",
"self",
".",
"partition_context",
",",
"events",
")",
"except",
"Exception",
"as",
"err",
":",
"# pylint: disable=broad-except",
"await",
"self",
".",
"process_error_async",
"(",
"err",
")"
] |
A setter for the flux units | def flux_units ( self , units ) : # Check that the units are valid dtypes = ( q . core . PrefixUnit , q . quantity . Quantity , q . core . CompositeUnit ) if not isinstance ( units , dtypes ) : raise ValueError ( units , "units not understood." ) # Check that the units changed if units != self . flux_units : # Convert to new units sfd = q . spectral_density ( self . wave_eff ) self . zp = self . zp . to ( units , equivalencies = sfd ) # Store new units self . _flux_units = units | 11,102 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L393-L415 | [
"def",
"_EndRecData",
"(",
"fpin",
")",
":",
"# Determine file size",
"fpin",
".",
"seek",
"(",
"0",
",",
"2",
")",
"filesize",
"=",
"fpin",
".",
"tell",
"(",
")",
"# Check to see if this is ZIP file with no archive comment (the",
"# \"end of central directory\" structure should be the last item in the",
"# file if this is the case).",
"try",
":",
"fpin",
".",
"seek",
"(",
"-",
"sizeEndCentDir",
",",
"2",
")",
"except",
"IOError",
":",
"return",
"None",
"data",
"=",
"fpin",
".",
"read",
"(",
")",
"if",
"data",
"[",
"0",
":",
"4",
"]",
"==",
"stringEndArchive",
"and",
"data",
"[",
"-",
"2",
":",
"]",
"==",
"\"\\000\\000\"",
":",
"# the signature is correct and there's no comment, unpack structure",
"endrec",
"=",
"struct",
".",
"unpack",
"(",
"structEndArchive",
",",
"data",
")",
"endrec",
"=",
"list",
"(",
"endrec",
")",
"# Append a blank comment and record start offset",
"endrec",
".",
"append",
"(",
"\"\"",
")",
"endrec",
".",
"append",
"(",
"filesize",
"-",
"sizeEndCentDir",
")",
"# Try to read the \"Zip64 end of central directory\" structure",
"return",
"_EndRecData64",
"(",
"fpin",
",",
"-",
"sizeEndCentDir",
",",
"endrec",
")",
"# Either this is not a ZIP file, or it is a ZIP file with an archive",
"# comment. Search the end of the file for the \"end of central directory\"",
"# record signature. The comment is the last item in the ZIP file and may be",
"# up to 64K long. It is assumed that the \"end of central directory\" magic",
"# number does not appear in the comment.",
"maxCommentStart",
"=",
"max",
"(",
"filesize",
"-",
"(",
"1",
"<<",
"16",
")",
"-",
"sizeEndCentDir",
",",
"0",
")",
"fpin",
".",
"seek",
"(",
"maxCommentStart",
",",
"0",
")",
"data",
"=",
"fpin",
".",
"read",
"(",
")",
"start",
"=",
"data",
".",
"rfind",
"(",
"stringEndArchive",
")",
"if",
"start",
">=",
"0",
":",
"# found the magic number; attempt to unpack and interpret",
"recData",
"=",
"data",
"[",
"start",
":",
"start",
"+",
"sizeEndCentDir",
"]",
"endrec",
"=",
"list",
"(",
"struct",
".",
"unpack",
"(",
"structEndArchive",
",",
"recData",
")",
")",
"comment",
"=",
"data",
"[",
"start",
"+",
"sizeEndCentDir",
":",
"]",
"# check that comment length is correct",
"if",
"endrec",
"[",
"_ECD_COMMENT_SIZE",
"]",
"==",
"len",
"(",
"comment",
")",
":",
"# Append the archive comment and start offset",
"endrec",
".",
"append",
"(",
"comment",
")",
"endrec",
".",
"append",
"(",
"maxCommentStart",
"+",
"start",
")",
"# Try to read the \"Zip64 end of central directory\" structure",
"return",
"_EndRecData64",
"(",
"fpin",
",",
"maxCommentStart",
"+",
"start",
"-",
"filesize",
",",
"endrec",
")",
"# Unable to find a valid end of central directory structure",
"return"
] |
Print a table of info about the current filter | def info ( self , fetch = False ) : # Get the info from the class tp = ( int , bytes , bool , str , float , tuple , list , np . ndarray ) info = [ [ k , str ( v ) ] for k , v in vars ( self ) . items ( ) if isinstance ( v , tp ) and k not in [ 'rsr' , 'raw' , 'centers' ] and not k . startswith ( '_' ) ] # Make the table table = at . Table ( np . asarray ( info ) . reshape ( len ( info ) , 2 ) , names = [ 'Attributes' , 'Values' ] ) # Sort and print table . sort ( 'Attributes' ) if fetch : return table else : table . pprint ( max_width = - 1 , max_lines = - 1 , align = [ '>' , '<' ] ) | 11,103 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L417-L436 | [
"def",
"_send_register_payload",
"(",
"self",
",",
"websocket",
")",
":",
"file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
",",
"HANDSHAKE_FILE_NAME",
")",
"data",
"=",
"codecs",
".",
"open",
"(",
"file",
",",
"'r'",
",",
"'utf-8'",
")",
"raw_handshake",
"=",
"data",
".",
"read",
"(",
")",
"handshake",
"=",
"json",
".",
"loads",
"(",
"raw_handshake",
")",
"handshake",
"[",
"'payload'",
"]",
"[",
"'client-key'",
"]",
"=",
"self",
".",
"client_key",
"yield",
"from",
"websocket",
".",
"send",
"(",
"json",
".",
"dumps",
"(",
"handshake",
")",
")",
"raw_response",
"=",
"yield",
"from",
"websocket",
".",
"recv",
"(",
")",
"response",
"=",
"json",
".",
"loads",
"(",
"raw_response",
")",
"if",
"response",
"[",
"'type'",
"]",
"==",
"'response'",
"and",
"response",
"[",
"'payload'",
"]",
"[",
"'pairingType'",
"]",
"==",
"'PROMPT'",
":",
"raw_response",
"=",
"yield",
"from",
"websocket",
".",
"recv",
"(",
")",
"response",
"=",
"json",
".",
"loads",
"(",
"raw_response",
")",
"if",
"response",
"[",
"'type'",
"]",
"==",
"'registered'",
":",
"self",
".",
"client_key",
"=",
"response",
"[",
"'payload'",
"]",
"[",
"'client-key'",
"]",
"self",
".",
"save_key_file",
"(",
")"
] |
Loads a top hat filter given wavelength min and max values | def load_TopHat ( self , wave_min , wave_max , pixels_per_bin = 100 ) : # Get min, max, effective wavelengths and width self . pixels_per_bin = pixels_per_bin self . n_bins = 1 self . _wave_units = q . AA wave_min = wave_min . to ( self . wave_units ) wave_max = wave_max . to ( self . wave_units ) # Create the RSR curve self . _wave = np . linspace ( wave_min , wave_max , pixels_per_bin ) self . _throughput = np . ones_like ( self . wave ) self . raw = np . array ( [ self . wave . value , self . throughput ] ) # Calculate the effective wavelength wave_eff = ( ( wave_min + wave_max ) / 2. ) . value width = ( wave_max - wave_min ) . value # Add the attributes self . path = '' self . refs = '' self . Band = 'Top Hat' self . CalibrationReference = '' self . FWHM = width self . Facility = '-' self . FilterProfileService = '-' self . MagSys = '-' self . PhotCalID = '' self . PhotSystem = '' self . ProfileReference = '' self . WavelengthMin = wave_min . value self . WavelengthMax = wave_max . value self . WavelengthCen = wave_eff self . WavelengthEff = wave_eff self . WavelengthMean = wave_eff self . WavelengthPeak = wave_eff self . WavelengthPhot = wave_eff self . WavelengthPivot = wave_eff self . WavelengthUCD = '' self . WidthEff = width self . ZeroPoint = 0 self . ZeroPointType = '' self . ZeroPointUnit = 'Jy' self . filterID = 'Top Hat' | 11,104 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L438-L492 | [
"def",
"_get",
"(",
"self",
",",
"url",
")",
":",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"verify",
"=",
"self",
".",
"verify",
",",
"cookies",
"=",
"self",
".",
"cookies",
",",
"timeout",
"=",
"self",
".",
"timeout",
",",
"auth",
"=",
"self",
".",
"_client",
".",
"auth",
"(",
")",
")",
"response",
".",
"raise_for_status",
"(",
")",
"return",
"response",
"except",
"HTTPError",
"as",
"exc",
":",
"if",
"exc",
".",
"response",
".",
"status_code",
"in",
"(",
"404",
",",
"407",
")",
":",
"raise",
"EntityNotFound",
"(",
"url",
")",
"else",
":",
"message",
"=",
"(",
"'Error during request: {url} '",
"'status code:({code}) '",
"'message: {message}'",
")",
".",
"format",
"(",
"url",
"=",
"url",
",",
"code",
"=",
"exc",
".",
"response",
".",
"status_code",
",",
"message",
"=",
"exc",
".",
"response",
".",
"text",
")",
"logging",
".",
"error",
"(",
"message",
")",
"raise",
"ServerError",
"(",
"exc",
".",
"response",
".",
"status_code",
",",
"exc",
".",
"response",
".",
"text",
",",
"message",
")",
"except",
"Timeout",
":",
"message",
"=",
"'Request timed out: {url} timeout: {timeout}'",
"message",
"=",
"message",
".",
"format",
"(",
"url",
"=",
"url",
",",
"timeout",
"=",
"self",
".",
"timeout",
")",
"logging",
".",
"error",
"(",
"message",
")",
"raise",
"ServerError",
"(",
"message",
")",
"except",
"RequestException",
"as",
"exc",
":",
"message",
"=",
"(",
"'Error during request: {url} '",
"'message: {message}'",
")",
".",
"format",
"(",
"url",
"=",
"url",
",",
"message",
"=",
"exc",
")",
"logging",
".",
"error",
"(",
"message",
")",
"raise",
"ServerError",
"(",
"exc",
".",
"args",
"[",
"0",
"]",
"[",
"1",
"]",
".",
"errno",
",",
"exc",
".",
"args",
"[",
"0",
"]",
"[",
"1",
"]",
".",
"strerror",
",",
"message",
")"
] |
Tests for overlap of this filter with a spectrum | def overlap ( self , spectrum ) : swave = self . wave [ np . where ( self . throughput != 0 ) ] s1 , s2 = swave . min ( ) , swave . max ( ) owave = spectrum [ 0 ] o1 , o2 = owave . min ( ) , owave . max ( ) if ( s1 >= o1 and s2 <= o2 ) : ans = 'full' elif ( s2 < o1 ) or ( o2 < s1 ) : ans = 'none' else : ans = 'partial' return ans | 11,105 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L588-L638 | [
"def",
"delete_entity",
"(",
"self",
",",
"entity_id",
",",
"mount_point",
"=",
"DEFAULT_MOUNT_POINT",
")",
":",
"api_path",
"=",
"'/v1/{mount_point}/entity/id/{id}'",
".",
"format",
"(",
"mount_point",
"=",
"mount_point",
",",
"id",
"=",
"entity_id",
",",
")",
"return",
"self",
".",
"_adapter",
".",
"delete",
"(",
"url",
"=",
"api_path",
",",
")"
] |
Plot the filter | def plot ( self , fig = None , draw = True ) : COLORS = color_gen ( 'Category10' ) # Make the figure if fig is None : xlab = 'Wavelength [{}]' . format ( self . wave_units ) ylab = 'Throughput' title = self . filterID fig = figure ( title = title , x_axis_label = xlab , y_axis_label = ylab ) # Plot the raw curve fig . line ( ( self . raw [ 0 ] * q . AA ) . to ( self . wave_units ) , self . raw [ 1 ] , alpha = 0.1 , line_width = 8 , color = 'black' ) # Plot each with bin centers for x , y in self . rsr : fig . line ( x , y , color = next ( COLORS ) , line_width = 2 ) fig . circle ( * self . centers , size = 8 , color = 'black' ) if draw : show ( fig ) else : return fig | 11,106 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L640-L677 | [
"def",
"clean_surface",
"(",
"surface",
",",
"span",
")",
":",
"surface",
"=",
"surface",
".",
"replace",
"(",
"'-'",
",",
"' '",
")",
"no_start",
"=",
"[",
"'and'",
",",
"' '",
"]",
"no_end",
"=",
"[",
"' and'",
",",
"' '",
"]",
"found",
"=",
"True",
"while",
"found",
":",
"found",
"=",
"False",
"for",
"word",
"in",
"no_start",
":",
"if",
"surface",
".",
"lower",
"(",
")",
".",
"startswith",
"(",
"word",
")",
":",
"surface",
"=",
"surface",
"[",
"len",
"(",
"word",
")",
":",
"]",
"span",
"=",
"(",
"span",
"[",
"0",
"]",
"+",
"len",
"(",
"word",
")",
",",
"span",
"[",
"1",
"]",
")",
"found",
"=",
"True",
"for",
"word",
"in",
"no_end",
":",
"if",
"surface",
".",
"lower",
"(",
")",
".",
"endswith",
"(",
"word",
")",
":",
"surface",
"=",
"surface",
"[",
":",
"-",
"len",
"(",
"word",
")",
"]",
"span",
"=",
"(",
"span",
"[",
"0",
"]",
",",
"span",
"[",
"1",
"]",
"-",
"len",
"(",
"word",
")",
")",
"found",
"=",
"True",
"if",
"not",
"surface",
":",
"return",
"None",
",",
"None",
"split",
"=",
"surface",
".",
"lower",
"(",
")",
".",
"split",
"(",
")",
"if",
"split",
"[",
"0",
"]",
"in",
"[",
"'one'",
",",
"'a'",
",",
"'an'",
"]",
"and",
"len",
"(",
"split",
")",
">",
"1",
"and",
"split",
"[",
"1",
"]",
"in",
"r",
".",
"UNITS",
"+",
"r",
".",
"TENS",
":",
"span",
"=",
"(",
"span",
"[",
"0",
"]",
"+",
"len",
"(",
"surface",
".",
"split",
"(",
")",
"[",
"0",
"]",
")",
"+",
"1",
",",
"span",
"[",
"1",
"]",
")",
"surface",
"=",
"' '",
".",
"join",
"(",
"surface",
".",
"split",
"(",
")",
"[",
"1",
":",
"]",
")",
"return",
"surface",
",",
"span"
] |
A setter for the throughput | def throughput ( self , points ) : # Test shape if not points . shape == self . wave . shape : raise ValueError ( "Throughput and wavelength must be same shape." ) self . _throughput = points | 11,107 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L692-L704 | [
"def",
"receive",
"(",
"uuid",
",",
"source",
")",
":",
"ret",
"=",
"{",
"}",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"source",
")",
":",
"ret",
"[",
"'Error'",
"]",
"=",
"'Source must be a directory or host'",
"return",
"ret",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"os",
".",
"path",
".",
"join",
"(",
"source",
",",
"'{0}.vmdata'",
".",
"format",
"(",
"uuid",
")",
")",
")",
":",
"ret",
"[",
"'Error'",
"]",
"=",
"'Unknow vm with uuid in {0}'",
".",
"format",
"(",
"source",
")",
"return",
"ret",
"# vmadm receive",
"cmd",
"=",
"'vmadm receive < {source}'",
".",
"format",
"(",
"source",
"=",
"os",
".",
"path",
".",
"join",
"(",
"source",
",",
"'{0}.vmdata'",
".",
"format",
"(",
"uuid",
")",
")",
")",
"res",
"=",
"__salt__",
"[",
"'cmd.run_all'",
"]",
"(",
"cmd",
",",
"python_shell",
"=",
"True",
")",
"retcode",
"=",
"res",
"[",
"'retcode'",
"]",
"if",
"retcode",
"!=",
"0",
"and",
"not",
"res",
"[",
"'stderr'",
"]",
".",
"endswith",
"(",
"'datasets'",
")",
":",
"ret",
"[",
"'Error'",
"]",
"=",
"res",
"[",
"'stderr'",
"]",
"if",
"'stderr'",
"in",
"res",
"else",
"_exit_status",
"(",
"retcode",
")",
"return",
"ret",
"vmobj",
"=",
"get",
"(",
"uuid",
")",
"if",
"'datasets'",
"not",
"in",
"vmobj",
":",
"return",
"True",
"log",
".",
"warning",
"(",
"'one or more datasets detected, this is not supported!'",
")",
"log",
".",
"warning",
"(",
"'trying to restore datasets, mountpoints will need to be set again...'",
")",
"for",
"dataset",
"in",
"vmobj",
"[",
"'datasets'",
"]",
":",
"name",
"=",
"dataset",
".",
"split",
"(",
"'/'",
")",
"name",
"=",
"name",
"[",
"-",
"1",
"]",
"cmd",
"=",
"'zfs receive {dataset} < {source}'",
".",
"format",
"(",
"dataset",
"=",
"dataset",
",",
"source",
"=",
"os",
".",
"path",
".",
"join",
"(",
"source",
",",
"'{0}-{1}.zfsds'",
".",
"format",
"(",
"uuid",
",",
"name",
")",
")",
")",
"res",
"=",
"__salt__",
"[",
"'cmd.run_all'",
"]",
"(",
"cmd",
",",
"python_shell",
"=",
"True",
")",
"retcode",
"=",
"res",
"[",
"'retcode'",
"]",
"if",
"retcode",
"!=",
"0",
":",
"ret",
"[",
"'Error'",
"]",
"=",
"res",
"[",
"'stderr'",
"]",
"if",
"'stderr'",
"in",
"res",
"else",
"_exit_status",
"(",
"retcode",
")",
"return",
"ret",
"cmd",
"=",
"'vmadm install {0}'",
".",
"format",
"(",
"uuid",
")",
"res",
"=",
"__salt__",
"[",
"'cmd.run_all'",
"]",
"(",
"cmd",
",",
"python_shell",
"=",
"True",
")",
"retcode",
"=",
"res",
"[",
"'retcode'",
"]",
"if",
"retcode",
"!=",
"0",
"and",
"not",
"res",
"[",
"'stderr'",
"]",
".",
"endswith",
"(",
"'datasets'",
")",
":",
"ret",
"[",
"'Error'",
"]",
"=",
"res",
"[",
"'stderr'",
"]",
"if",
"'stderr'",
"in",
"res",
"else",
"_exit_status",
"(",
"retcode",
")",
"return",
"ret",
"return",
"True"
] |
A setter for the wavelength | def wave ( self , wavelength ) : # Test units if not isinstance ( wavelength , q . quantity . Quantity ) : raise ValueError ( "Wavelength must be in length units." ) self . _wave = wavelength self . wave_units = wavelength . unit | 11,108 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L712-L725 | [
"def",
"close",
"(",
"self",
")",
":",
"publish",
"=",
"False",
"exporterid",
"=",
"rsid",
"=",
"exception",
"=",
"export_ref",
"=",
"ed",
"=",
"None",
"with",
"self",
".",
"__lock",
":",
"if",
"not",
"self",
".",
"__closed",
":",
"exporterid",
"=",
"self",
".",
"__exportref",
".",
"get_export_container_id",
"(",
")",
"export_ref",
"=",
"self",
".",
"__exportref",
"rsid",
"=",
"self",
".",
"__exportref",
".",
"get_remoteservice_id",
"(",
")",
"ed",
"=",
"self",
".",
"__exportref",
".",
"get_description",
"(",
")",
"exception",
"=",
"self",
".",
"__exportref",
".",
"get_exception",
"(",
")",
"self",
".",
"__closed",
"=",
"True",
"publish",
"=",
"self",
".",
"__exportref",
".",
"close",
"(",
"self",
")",
"self",
".",
"__exportref",
"=",
"None",
"# pylint: disable=W0212",
"if",
"publish",
"and",
"export_ref",
"and",
"self",
".",
"__rsa",
":",
"self",
".",
"__rsa",
".",
"_publish_event",
"(",
"RemoteServiceAdminEvent",
".",
"fromexportunreg",
"(",
"self",
".",
"__rsa",
".",
"_get_bundle",
"(",
")",
",",
"exporterid",
",",
"rsid",
",",
"export_ref",
",",
"exception",
",",
"ed",
",",
")",
")",
"self",
".",
"__rsa",
"=",
"None"
] |
A setter for the wavelength units | def wave_units ( self , units ) : # Make sure it's length units if not units . is_equivalent ( q . m ) : raise ValueError ( units , ": New wavelength units must be a length." ) # Update the units self . _wave_units = units # Update all the wavelength values self . _wave = self . wave . to ( self . wave_units ) . round ( 5 ) self . wave_min = self . wave_min . to ( self . wave_units ) . round ( 5 ) self . wave_max = self . wave_max . to ( self . wave_units ) . round ( 5 ) self . wave_eff = self . wave_eff . to ( self . wave_units ) . round ( 5 ) self . wave_center = self . wave_center . to ( self . wave_units ) . round ( 5 ) self . wave_mean = self . wave_mean . to ( self . wave_units ) . round ( 5 ) self . wave_peak = self . wave_peak . to ( self . wave_units ) . round ( 5 ) self . wave_phot = self . wave_phot . to ( self . wave_units ) . round ( 5 ) self . wave_pivot = self . wave_pivot . to ( self . wave_units ) . round ( 5 ) self . width_eff = self . width_eff . to ( self . wave_units ) . round ( 5 ) self . fwhm = self . fwhm . to ( self . wave_units ) . round ( 5 ) | 11,109 | https://github.com/hover2pi/svo_filters/blob/f0587c4908baf636d4bdf030fa95029e8f31b975/svo_filters/svo.py#L733-L760 | [
"def",
"close",
"(",
"self",
")",
":",
"publish",
"=",
"False",
"exporterid",
"=",
"rsid",
"=",
"exception",
"=",
"export_ref",
"=",
"ed",
"=",
"None",
"with",
"self",
".",
"__lock",
":",
"if",
"not",
"self",
".",
"__closed",
":",
"exporterid",
"=",
"self",
".",
"__exportref",
".",
"get_export_container_id",
"(",
")",
"export_ref",
"=",
"self",
".",
"__exportref",
"rsid",
"=",
"self",
".",
"__exportref",
".",
"get_remoteservice_id",
"(",
")",
"ed",
"=",
"self",
".",
"__exportref",
".",
"get_description",
"(",
")",
"exception",
"=",
"self",
".",
"__exportref",
".",
"get_exception",
"(",
")",
"self",
".",
"__closed",
"=",
"True",
"publish",
"=",
"self",
".",
"__exportref",
".",
"close",
"(",
"self",
")",
"self",
".",
"__exportref",
"=",
"None",
"# pylint: disable=W0212",
"if",
"publish",
"and",
"export_ref",
"and",
"self",
".",
"__rsa",
":",
"self",
".",
"__rsa",
".",
"_publish_event",
"(",
"RemoteServiceAdminEvent",
".",
"fromexportunreg",
"(",
"self",
".",
"__rsa",
".",
"_get_bundle",
"(",
")",
",",
"exporterid",
",",
"rsid",
",",
"export_ref",
",",
"exception",
",",
"ed",
",",
")",
")",
"self",
".",
"__rsa",
"=",
"None"
] |
Clears out all the actions and items from this toolbar . | def clear ( self ) : # clear the actions from this widget
for act in self . actions ( ) : act . setParent ( None ) act . deleteLater ( ) # clear the labels from this widget
for lbl in self . actionLabels ( ) : lbl . close ( ) lbl . deleteLater ( ) | 11,110 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xdocktoolbar.py#L242-L254 | [
"def",
"dispatch",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"REG_VALIDATION_STR",
"not",
"in",
"request",
".",
"session",
":",
"return",
"HttpResponseRedirect",
"(",
"reverse",
"(",
"'registration'",
")",
")",
"try",
":",
"self",
".",
"temporaryRegistration",
"=",
"TemporaryRegistration",
".",
"objects",
".",
"get",
"(",
"id",
"=",
"self",
".",
"request",
".",
"session",
"[",
"REG_VALIDATION_STR",
"]",
".",
"get",
"(",
"'temporaryRegistrationId'",
")",
")",
"except",
"ObjectDoesNotExist",
":",
"messages",
".",
"error",
"(",
"request",
",",
"_",
"(",
"'Invalid registration identifier passed to sign-up form.'",
")",
")",
"return",
"HttpResponseRedirect",
"(",
"reverse",
"(",
"'registration'",
")",
")",
"expiry",
"=",
"parse_datetime",
"(",
"self",
".",
"request",
".",
"session",
"[",
"REG_VALIDATION_STR",
"]",
".",
"get",
"(",
"'temporaryRegistrationExpiry'",
",",
"''",
")",
",",
")",
"if",
"not",
"expiry",
"or",
"expiry",
"<",
"timezone",
".",
"now",
"(",
")",
":",
"messages",
".",
"info",
"(",
"request",
",",
"_",
"(",
"'Your registration session has expired. Please try again.'",
")",
")",
"return",
"HttpResponseRedirect",
"(",
"reverse",
"(",
"'registration'",
")",
")",
"return",
"super",
"(",
"StudentInfoView",
",",
"self",
")",
".",
"dispatch",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] |
Resizes the dock toolbar to the minimum sizes . | def resizeToMinimum ( self ) : offset = self . padding ( ) min_size = self . minimumPixmapSize ( ) if self . position ( ) in ( XDockToolbar . Position . East , XDockToolbar . Position . West ) : self . resize ( min_size . width ( ) + offset , self . height ( ) ) elif self . position ( ) in ( XDockToolbar . Position . North , XDockToolbar . Position . South ) : self . resize ( self . width ( ) , min_size . height ( ) + offset ) | 11,111 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xdocktoolbar.py#L490-L503 | [
"def",
"ttl",
"(",
"self",
")",
":",
"# result is self ts",
"result",
"=",
"getattr",
"(",
"self",
",",
"Annotation",
".",
"__TS",
",",
"None",
")",
"# if result is not None",
"if",
"result",
"is",
"not",
"None",
":",
"# result is now - result",
"now",
"=",
"time",
"(",
")",
"result",
"=",
"result",
"-",
"now",
"return",
"result"
] |
Unholds the action from being blocked on the leave event . | def unholdAction ( self ) : self . _actionHeld = False point = self . mapFromGlobal ( QCursor . pos ( ) ) self . setCurrentAction ( self . actionAt ( point ) ) | 11,112 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xdocktoolbar.py#L741-L748 | [
"def",
"external_metadata",
"(",
"self",
",",
"datasource_type",
"=",
"None",
",",
"datasource_id",
"=",
"None",
")",
":",
"if",
"datasource_type",
"==",
"'druid'",
":",
"datasource",
"=",
"ConnectorRegistry",
".",
"get_datasource",
"(",
"datasource_type",
",",
"datasource_id",
",",
"db",
".",
"session",
")",
"elif",
"datasource_type",
"==",
"'table'",
":",
"database",
"=",
"(",
"db",
".",
"session",
".",
"query",
"(",
"Database",
")",
".",
"filter_by",
"(",
"id",
"=",
"request",
".",
"args",
".",
"get",
"(",
"'db_id'",
")",
")",
".",
"one",
"(",
")",
")",
"Table",
"=",
"ConnectorRegistry",
".",
"sources",
"[",
"'table'",
"]",
"datasource",
"=",
"Table",
"(",
"database",
"=",
"database",
",",
"table_name",
"=",
"request",
".",
"args",
".",
"get",
"(",
"'table_name'",
")",
",",
"schema",
"=",
"request",
".",
"args",
".",
"get",
"(",
"'schema'",
")",
"or",
"None",
",",
")",
"external_metadata",
"=",
"datasource",
".",
"external_metadata",
"(",
")",
"return",
"self",
".",
"json_response",
"(",
"external_metadata",
")"
] |
Applies the scheme to the current application . | def apply ( self ) : font = self . value ( 'font' ) try : font . setPointSize ( self . value ( 'fontSize' ) ) # errors in linux for some reason
except TypeError : pass palette = self . value ( 'colorSet' ) . palette ( ) if ( unwrapVariant ( QApplication . instance ( ) . property ( 'useScheme' ) ) ) : QApplication . instance ( ) . setFont ( font ) QApplication . instance ( ) . setPalette ( palette ) # hack to support MDI Areas
for widget in QApplication . topLevelWidgets ( ) : for area in widget . findChildren ( QMdiArea ) : area . setPalette ( palette ) else : logger . debug ( 'The application doesnt have the useScheme property.' ) | 11,113 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/xscheme.py#L38-L62 | [
"def",
"listrecords",
"(",
"*",
"*",
"kwargs",
")",
":",
"record_dumper",
"=",
"serializer",
"(",
"kwargs",
"[",
"'metadataPrefix'",
"]",
")",
"e_tree",
",",
"e_listrecords",
"=",
"verb",
"(",
"*",
"*",
"kwargs",
")",
"result",
"=",
"get_records",
"(",
"*",
"*",
"kwargs",
")",
"for",
"record",
"in",
"result",
".",
"items",
":",
"pid",
"=",
"oaiid_fetcher",
"(",
"record",
"[",
"'id'",
"]",
",",
"record",
"[",
"'json'",
"]",
"[",
"'_source'",
"]",
")",
"e_record",
"=",
"SubElement",
"(",
"e_listrecords",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'record'",
")",
")",
"header",
"(",
"e_record",
",",
"identifier",
"=",
"pid",
".",
"pid_value",
",",
"datestamp",
"=",
"record",
"[",
"'updated'",
"]",
",",
"sets",
"=",
"record",
"[",
"'json'",
"]",
"[",
"'_source'",
"]",
".",
"get",
"(",
"'_oai'",
",",
"{",
"}",
")",
".",
"get",
"(",
"'sets'",
",",
"[",
"]",
")",
",",
")",
"e_metadata",
"=",
"SubElement",
"(",
"e_record",
",",
"etree",
".",
"QName",
"(",
"NS_OAIPMH",
",",
"'metadata'",
")",
")",
"e_metadata",
".",
"append",
"(",
"record_dumper",
"(",
"pid",
",",
"record",
"[",
"'json'",
"]",
")",
")",
"resumption_token",
"(",
"e_listrecords",
",",
"result",
",",
"*",
"*",
"kwargs",
")",
"return",
"e_tree"
] |
Resets the values to the current application information . | def reset ( self ) : self . setValue ( 'colorSet' , XPaletteColorSet ( ) ) self . setValue ( 'font' , QApplication . font ( ) ) self . setValue ( 'fontSize' , QApplication . font ( ) . pointSize ( ) ) | 11,114 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/xscheme.py#L64-L70 | [
"def",
"remove_group",
"(",
"self",
",",
"groupname",
")",
":",
"# implementation based on",
"# https://docs.atlassian.com/jira/REST/ondemand/#d2e5173",
"url",
"=",
"self",
".",
"_options",
"[",
"'server'",
"]",
"+",
"'/rest/api/latest/group'",
"x",
"=",
"{",
"'groupname'",
":",
"groupname",
"}",
"self",
".",
"_session",
".",
"delete",
"(",
"url",
",",
"params",
"=",
"x",
")",
"return",
"True"
] |
Prompts the user to select an attachment to add to this edit . | def pickAttachment ( self ) : filename = QFileDialog . getOpenFileName ( self . window ( ) , 'Select Attachment' , '' , 'All Files (*.*)' ) if type ( filename ) == tuple : filename = nativestring ( filename [ 0 ] ) filename = nativestring ( filename ) if filename : self . addAttachment ( os . path . basename ( filename ) , filename ) | 11,115 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xcommentedit.py#L145-L159 | [
"def",
"display",
"(",
"self",
")",
":",
"self",
".",
"pretty",
"(",
"self",
".",
"_timings",
",",
"'Raw Redis Commands'",
")",
"print",
"(",
")",
"for",
"key",
",",
"value",
"in",
"self",
".",
"_commands",
".",
"items",
"(",
")",
":",
"self",
".",
"pretty",
"(",
"value",
",",
"'Qless \"%s\" Command'",
"%",
"key",
")",
"print",
"(",
")"
] |
Resizes this toolbar based on the contents of its text . | def resizeToContents ( self ) : if self . _toolbar . isVisible ( ) : doc = self . document ( ) h = doc . documentLayout ( ) . documentSize ( ) . height ( ) offset = 34 # update the attachments edit
edit = self . _attachmentsEdit if self . _attachments : edit . move ( 2 , self . height ( ) - edit . height ( ) - 31 ) edit . setTags ( sorted ( self . _attachments . keys ( ) ) ) edit . show ( ) offset = 34 + edit . height ( ) else : edit . hide ( ) offset = 34 self . setFixedHeight ( h + offset ) self . _toolbar . move ( 2 , self . height ( ) - 32 ) else : super ( XCommentEdit , self ) . resizeToContents ( ) | 11,116 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xcommentedit.py#L183-L208 | [
"def",
"get_enroll",
"(",
"self",
")",
":",
"devices",
"=",
"[",
"DeviceRegistration",
".",
"wrap",
"(",
"device",
")",
"for",
"device",
"in",
"self",
".",
"__get_u2f_devices",
"(",
")",
"]",
"enroll",
"=",
"start_register",
"(",
"self",
".",
"__appid",
",",
"devices",
")",
"enroll",
"[",
"'status'",
"]",
"=",
"'ok'",
"session",
"[",
"'_u2f_enroll_'",
"]",
"=",
"enroll",
".",
"json",
"return",
"enroll"
] |
Inspects the Raft configuration | async def configuration ( self , * , dc = None , consistency = None ) : response = await self . _api . get ( "/v1/operator/raft/configuration" , params = { "dc" : dc } , consistency = consistency ) return response . body | 11,117 | https://github.com/johnnoone/aioconsul/blob/02f7a529d7dc2e49bed942111067aa5faf320e90/aioconsul/client/operator_endpoint.py#L7-L72 | [
"def",
"render_to_response",
"(",
"self",
",",
"context",
",",
"*",
"*",
"response_kwargs",
")",
":",
"serializer",
"=",
"PollPublicSerializer",
"(",
"self",
".",
"object",
")",
"response",
"=",
"HttpResponse",
"(",
"json",
".",
"dumps",
"(",
"serializer",
".",
"data",
")",
",",
"content_type",
"=",
"\"application/json\"",
")",
"if",
"\"HTTP_ORIGIN\"",
"in",
"self",
".",
"request",
".",
"META",
":",
"response",
"[",
"\"Access-Control-Allow-Origin\"",
"]",
"=",
"self",
".",
"request",
".",
"META",
"[",
"\"HTTP_ORIGIN\"",
"]",
"response",
"[",
"\"Access-Control-Allow-Credentials\"",
"]",
"=",
"'true'",
"return",
"response"
] |
Remove the server with given address from the Raft configuration | async def peer_delete ( self , * , dc = None , address ) : address = extract_attr ( address , keys = [ "Address" ] ) params = { "dc" : dc , "address" : address } response = await self . _api . delete ( "/v1/operator/raft/peer" , params = params ) return response . status < 400 | 11,118 | https://github.com/johnnoone/aioconsul/blob/02f7a529d7dc2e49bed942111067aa5faf320e90/aioconsul/client/operator_endpoint.py#L74-L93 | [
"def",
"uninstall_handle_input",
"(",
"self",
")",
":",
"if",
"self",
".",
"hooked",
"is",
"None",
":",
"return",
"ctypes",
".",
"windll",
".",
"user32",
".",
"UnhookWindowsHookEx",
"(",
"self",
".",
"hooked",
")",
"self",
".",
"hooked",
"=",
"None"
] |
Automatically lays out the contents for this widget . | def autoLayout ( self ) : try : direction = self . currentSlide ( ) . scene ( ) . direction ( ) except AttributeError : direction = QtGui . QBoxLayout . TopToBottom size = self . size ( ) self . _slideshow . resize ( size ) prev = self . _previousButton next = self . _nextButton if direction == QtGui . QBoxLayout . BottomToTop : y = 9 else : y = size . height ( ) - prev . height ( ) - 9 prev . move ( 9 , y ) next . move ( size . width ( ) - next . width ( ) - 9 , y ) # update the layout for the slides
for i in range ( self . _slideshow . count ( ) ) : widget = self . _slideshow . widget ( i ) widget . scene ( ) . autoLayout ( size ) | 11,119 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xwalkthroughwidget/xwalkthroughwidget.py#L113-L139 | [
"def",
"canonicalize",
"(",
"method",
",",
"resource",
",",
"query_parameters",
",",
"headers",
")",
":",
"headers",
",",
"_",
"=",
"get_canonical_headers",
"(",
"headers",
")",
"if",
"method",
"==",
"\"RESUMABLE\"",
":",
"method",
"=",
"\"POST\"",
"headers",
".",
"append",
"(",
"\"x-goog-resumable:start\"",
")",
"if",
"query_parameters",
"is",
"None",
":",
"return",
"_Canonical",
"(",
"method",
",",
"resource",
",",
"[",
"]",
",",
"headers",
")",
"normalized_qp",
"=",
"sorted",
"(",
"(",
"key",
".",
"lower",
"(",
")",
",",
"value",
"and",
"value",
".",
"strip",
"(",
")",
"or",
"\"\"",
")",
"for",
"key",
",",
"value",
"in",
"query_parameters",
".",
"items",
"(",
")",
")",
"encoded_qp",
"=",
"six",
".",
"moves",
".",
"urllib",
".",
"parse",
".",
"urlencode",
"(",
"normalized_qp",
")",
"canonical_resource",
"=",
"\"{}?{}\"",
".",
"format",
"(",
"resource",
",",
"encoded_qp",
")",
"return",
"_Canonical",
"(",
"method",
",",
"canonical_resource",
",",
"normalized_qp",
",",
"headers",
")"
] |
Moves to the next slide or finishes the walkthrough . | def goForward ( self ) : if self . _slideshow . currentIndex ( ) == self . _slideshow . count ( ) - 1 : self . finished . emit ( ) else : self . _slideshow . slideInNext ( ) | 11,120 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xwalkthroughwidget/xwalkthroughwidget.py#L187-L194 | [
"def",
"init_poolmanager",
"(",
"self",
",",
"connections",
",",
"maxsize",
",",
"block",
"=",
"DEFAULT_POOLBLOCK",
",",
"*",
"*",
"pool_kwargs",
")",
":",
"# save these values for pickling",
"self",
".",
"_pool_connections",
"=",
"connections",
"self",
".",
"_pool_maxsize",
"=",
"maxsize",
"self",
".",
"_pool_block",
"=",
"block",
"self",
".",
"poolmanager",
"=",
"PoolManager",
"(",
"num_pools",
"=",
"connections",
",",
"maxsize",
"=",
"maxsize",
",",
"block",
"=",
"block",
",",
"strict",
"=",
"True",
",",
"*",
"*",
"pool_kwargs",
")"
] |
Updates the interface to show the selection buttons . | def updateUi ( self ) : index = self . _slideshow . currentIndex ( ) count = self . _slideshow . count ( ) self . _previousButton . setVisible ( index != 0 ) self . _nextButton . setText ( 'Finish' if index == count - 1 else 'Next' ) self . autoLayout ( ) | 11,121 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xwalkthroughwidget/xwalkthroughwidget.py#L247-L256 | [
"def",
"create_weight",
"(",
"self",
",",
"weight",
",",
"date",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"_build_url",
"(",
"'my'",
",",
"'body'",
",",
"'weight'",
")",
"data",
"=",
"{",
"'weightInKilograms'",
":",
"weight",
"}",
"if",
"date",
":",
"if",
"not",
"date",
".",
"is_aware",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"provided date is not timezone aware\"",
")",
"data",
".",
"update",
"(",
"date",
"=",
"date",
".",
"isoformat",
"(",
")",
")",
"headers",
"=",
"{",
"'Content-Type'",
":",
"'application/json; charset=utf8'",
"}",
"r",
"=",
"self",
".",
"session",
".",
"post",
"(",
"url",
",",
"data",
"=",
"json",
".",
"dumps",
"(",
"data",
")",
",",
"headers",
"=",
"headers",
")",
"r",
".",
"raise_for_status",
"(",
")",
"return",
"r"
] |
Do a fuzzy match for prop in the dictionary taking into account unit suffix . | def parse_unit ( prop , dictionary , dt = None ) : # add the observation's time try : dt = timezone . parse_datetime ( dictionary . get ( 'date_time' ) ) except TypeError : dt = None # 'prop' is a stub of the property's attribute key, so search for matches matches = [ k for k in dictionary . keys ( ) if prop in k ] try : value = dictionary [ matches [ 0 ] ] unit = re . search ( r' \(([^)]+)\)' , matches [ 0 ] ) except IndexError : # No matches: fail out return None # Sometimes we get a list of values (e.g. waves) if ';' in value : # Ignore empty values values = [ val for val in value . split ( ';' ) if val != '' ] if unit : return [ Observation ( v , unit . group ( 1 ) , dt ) for v in values ] else : return values # Sometimes there's no value! Sometimes there's no unit! if not value or not unit : return value or None return Observation ( value , unit . group ( 1 ) , dt ) | 11,122 | https://github.com/fitnr/buoyant/blob/ef7a74f9ebd4774629508ccf2c9abb43aa0235c9/buoyant/buoy.py#L37-L70 | [
"def",
"_read_header",
"(",
"self",
")",
":",
"self",
".",
"_fh",
".",
"seek",
"(",
"0",
")",
"buf",
"=",
"self",
".",
"_fh",
".",
"read",
"(",
"4",
"*",
"2",
")",
"fc",
",",
"dc",
"=",
"struct",
".",
"unpack",
"(",
"\"<II\"",
",",
"buf",
")",
"return",
"fc",
",",
"dc"
] |
Clears all the container for this query widget . | def clear ( self ) : for i in range ( self . count ( ) ) : widget = self . widget ( i ) if widget is not None : widget . close ( ) widget . setParent ( None ) widget . deleteLater ( ) | 11,123 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbquerywidget/xorbquerywidget.py#L78-L87 | [
"def",
"read",
"(",
"self",
",",
"len",
"=",
"1024",
",",
"buffer",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
".",
"_wrap_socket_library_call",
"(",
"lambda",
":",
"SSL_read",
"(",
"self",
".",
"_ssl",
".",
"value",
",",
"len",
",",
"buffer",
")",
",",
"ERR_READ_TIMEOUT",
")",
"except",
"openssl_error",
"(",
")",
"as",
"err",
":",
"if",
"err",
".",
"ssl_error",
"==",
"SSL_ERROR_SYSCALL",
"and",
"err",
".",
"result",
"==",
"-",
"1",
":",
"raise_ssl_error",
"(",
"ERR_PORT_UNREACHABLE",
",",
"err",
")",
"raise"
] |
Cleans up all containers to the right of the current one . | def cleanupContainers ( self ) : for i in range ( self . count ( ) - 1 , self . currentIndex ( ) , - 1 ) : widget = self . widget ( i ) widget . close ( ) widget . setParent ( None ) widget . deleteLater ( ) | 11,124 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbquerywidget/xorbquerywidget.py#L89-L97 | [
"def",
"clean_text",
"(",
"self",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"normalize_url",
"(",
"url",
")",
"except",
"UnicodeDecodeError",
":",
"log",
".",
"warning",
"(",
"\"Invalid URL: %r\"",
",",
"url",
")"
] |
Removes the current query container . | def exitContainer ( self ) : try : entry = self . _compoundStack . pop ( ) except IndexError : return container = self . currentContainer ( ) entry . setQuery ( container . query ( ) ) self . slideInPrev ( ) | 11,125 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbquerywidget/xorbquerywidget.py#L143-L155 | [
"def",
"readme_verify",
"(",
")",
":",
"expected",
"=",
"populate_readme",
"(",
"REVISION",
",",
"RTD_VERSION",
")",
"# Actually get the stored contents.",
"with",
"open",
"(",
"README_FILE",
",",
"\"r\"",
")",
"as",
"file_obj",
":",
"contents",
"=",
"file_obj",
".",
"read",
"(",
")",
"if",
"contents",
"!=",
"expected",
":",
"err_msg",
"=",
"\"\\n\"",
"+",
"get_diff",
"(",
"contents",
",",
"expected",
",",
"\"README.rst.actual\"",
",",
"\"README.rst.expected\"",
")",
"raise",
"ValueError",
"(",
"err_msg",
")",
"else",
":",
"print",
"(",
"\"README contents are as expected.\"",
")"
] |
Rebuilds the interface for this widget based on the current model . | def rebuild ( self ) : self . setUpdatesEnabled ( False ) self . blockSignals ( True ) # clear out all the subwidgets for this widget
for child in self . findChildren ( QObject ) : child . setParent ( None ) child . deleteLater ( ) # load up all the interface for this widget
schema = self . schema ( ) if ( schema ) : self . setEnabled ( True ) uifile = self . uiFile ( ) # load a user defined file
if ( uifile ) : projexui . loadUi ( '' , self , uifile ) for widget in self . findChildren ( XOrbColumnEdit ) : columnName = widget . columnName ( ) column = schema . column ( columnName ) if ( column ) : widget . setColumn ( column ) else : logger . debug ( '%s is not a valid column of %s' % ( columnName , schema . name ( ) ) ) # dynamically load files
else : layout = QFormLayout ( ) layout . setContentsMargins ( 0 , 0 , 0 , 0 ) columns = schema . columns ( ) columns . sort ( key = lambda x : x . displayName ( ) ) record = self . record ( ) for column in columns : # ignore protected columns
if ( column . name ( ) . startswith ( '_' ) ) : continue label = column . displayName ( ) coltype = column . columnType ( ) name = column . name ( ) # create the column edit widget
widget = XOrbColumnEdit ( self ) widget . setObjectName ( 'ui_' + name ) widget . setColumnName ( name ) widget . setColumnType ( coltype ) widget . setColumn ( column ) layout . addRow ( QLabel ( label , self ) , widget ) self . setLayout ( layout ) self . adjustSize ( ) self . setWindowTitle ( 'Edit %s' % schema . name ( ) ) else : self . setEnabled ( False ) self . setUpdatesEnabled ( True ) self . blockSignals ( False ) | 11,126 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbrecordedit.py#L78-L146 | [
"def",
"update",
"(",
"request",
")",
":",
"session",
"=",
"yield",
"from",
"app",
".",
"ps",
".",
"session",
".",
"load",
"(",
"request",
")",
"session",
"[",
"'random'",
"]",
"=",
"random",
".",
"random",
"(",
")",
"return",
"session"
] |
Saves the values from the editor to the system . | def save ( self ) : schema = self . schema ( ) if ( not schema ) : self . saved . emit ( ) return record = self . record ( ) if not record : record = self . _model ( ) # validate the information
save_data = [ ] column_edits = self . findChildren ( XOrbColumnEdit ) for widget in column_edits : columnName = widget . columnName ( ) column = schema . column ( columnName ) if ( not column ) : logger . warning ( '%s is not a valid column of %s.' % ( columnName , schema . name ( ) ) ) continue value = widget . value ( ) if ( value == IGNORED ) : continue # check for required columns
if ( column . required ( ) and not value ) : name = column . displayName ( ) QMessageBox . information ( self , 'Missing Required Field' , '%s is a required field.' % name ) return # check for unique columns
elif ( column . unique ( ) ) : # check for uniqueness
query = Q ( column . name ( ) ) == value if ( record . isRecord ( ) ) : query &= Q ( self . _model ) != record columns = self . _model . schema ( ) . primaryColumns ( ) result = self . _model . select ( columns = columns , where = query ) if ( result . total ( ) ) : QMessageBox . information ( self , 'Duplicate Entry' , '%s already exists.' % value ) return save_data . append ( ( column , value ) ) # record the properties for the record
for column , value in save_data : record . setRecordValue ( column . name ( ) , value ) self . _record = record self . saved . emit ( ) | 11,127 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbrecordedit.py#L149-L210 | [
"def",
"api_auth",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"_decorator",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"authentication",
"=",
"APIAuthentication",
"(",
"request",
")",
"if",
"authentication",
".",
"authenticate",
"(",
")",
":",
"return",
"func",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"raise",
"Http404",
"return",
"_decorator"
] |
Emits the editing finished signals for this widget . | def acceptText ( self ) : if not self . signalsBlocked ( ) : self . textEntered . emit ( self . toPlainText ( ) ) self . htmlEntered . emit ( self . toHtml ( ) ) self . returnPressed . emit ( ) | 11,128 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xtextedit.py#L51-L58 | [
"def",
"prior_const",
"(",
"C",
",",
"alpha",
"=",
"0.001",
")",
":",
"if",
"isdense",
"(",
"C",
")",
":",
"return",
"sparse",
".",
"prior",
".",
"prior_const",
"(",
"C",
",",
"alpha",
"=",
"alpha",
")",
"else",
":",
"warnings",
".",
"warn",
"(",
"\"Prior will be a dense matrix for sparse input\"",
")",
"return",
"sparse",
".",
"prior",
".",
"prior_const",
"(",
"C",
",",
"alpha",
"=",
"alpha",
")"
] |
Clears the text for this edit and resizes the toolbar information . | def clear ( self ) : super ( XTextEdit , self ) . clear ( ) self . textEntered . emit ( '' ) self . htmlEntered . emit ( '' ) if self . autoResizeToContents ( ) : self . resizeToContents ( ) | 11,129 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xtextedit.py#L70-L80 | [
"def",
"render_unregistered",
"(",
"error",
"=",
"None",
")",
":",
"return",
"template",
"(",
"read_index_template",
"(",
")",
",",
"registered",
"=",
"False",
",",
"error",
"=",
"error",
",",
"seeder_data",
"=",
"None",
",",
"url_id",
"=",
"None",
",",
")"
] |
Pastes text from the clipboard into this edit . | def paste ( self ) : html = QApplication . clipboard ( ) . text ( ) if not self . isRichTextEditEnabled ( ) : self . insertPlainText ( projex . text . toAscii ( html ) ) else : super ( XTextEdit , self ) . paste ( ) | 11,130 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xtextedit.py#L198-L206 | [
"def",
"remove_stale_javascripts",
"(",
"portal",
")",
":",
"logger",
".",
"info",
"(",
"\"Removing stale javascripts ...\"",
")",
"for",
"js",
"in",
"JAVASCRIPTS_TO_REMOVE",
":",
"logger",
".",
"info",
"(",
"\"Unregistering JS %s\"",
"%",
"js",
")",
"portal",
".",
"portal_javascripts",
".",
"unregisterResource",
"(",
"js",
")"
] |
Resizes this widget to fit the contents of its text . | def resizeToContents ( self ) : doc = self . document ( ) h = doc . documentLayout ( ) . documentSize ( ) . height ( ) self . setFixedHeight ( h + 4 ) | 11,131 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xtextedit.py#L231-L237 | [
"def",
"delete",
"(",
"self",
",",
"subscription_id",
",",
"data",
"=",
"None",
")",
":",
"if",
"not",
"subscription_id",
"or",
"not",
"subscription_id",
".",
"startswith",
"(",
"self",
".",
"RESOURCE_ID_PREFIX",
")",
":",
"raise",
"IdentifierError",
"(",
"\"Invalid subscription ID: '{id}'. A subscription ID should start with '{prefix}'.\"",
".",
"format",
"(",
"id",
"=",
"subscription_id",
",",
"prefix",
"=",
"self",
".",
"RESOURCE_ID_PREFIX",
")",
")",
"result",
"=",
"super",
"(",
"CustomerSubscriptions",
",",
"self",
")",
".",
"delete",
"(",
"subscription_id",
",",
"data",
")",
"return",
"self",
".",
"get_resource_object",
"(",
"result",
")"
] |
Matches the collapsed state for this groupbox . | def matchCollapsedState ( self ) : collapsed = not self . isChecked ( ) if self . _inverted : collapsed = not collapsed if ( not self . isCollapsible ( ) or not collapsed ) : for child in self . children ( ) : if ( not isinstance ( child , QWidget ) ) : continue child . show ( ) self . setMaximumHeight ( MAX_INT ) self . adjustSize ( ) if ( self . parent ( ) ) : self . parent ( ) . adjustSize ( ) else : self . setMaximumHeight ( self . collapsedHeight ( ) ) for child in self . children ( ) : if ( not isinstance ( child , QWidget ) ) : continue child . hide ( ) | 11,132 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xgroupbox.py#L99-L126 | [
"def",
"reissue",
"(",
"csr_file",
",",
"certificate_id",
",",
"web_server_type",
",",
"approver_email",
"=",
"None",
",",
"http_dc_validation",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"__get_certificates",
"(",
"'namecheap.ssl.reissue'",
",",
"\"SSLReissueResult\"",
",",
"csr_file",
",",
"certificate_id",
",",
"web_server_type",
",",
"approver_email",
",",
"http_dc_validation",
",",
"kwargs",
")"
] |
Delayed qt loader . | def import_qt ( glbls ) : if 'QtCore' in glbls : return from projexui . qt import QtCore , QtGui , wrapVariant , uic from projexui . widgets . xloggersplashscreen import XLoggerSplashScreen glbls [ 'QtCore' ] = QtCore glbls [ 'QtGui' ] = QtGui glbls [ 'wrapVariant' ] = wrapVariant glbls [ 'uic' ] = uic glbls [ 'XLoggerSplashScreen' ] = XLoggerSplashScreen | 11,133 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/xcommands.py#L255-L267 | [
"def",
"delete_attribute_group",
"(",
"group_id",
",",
"*",
"*",
"kwargs",
")",
":",
"user_id",
"=",
"kwargs",
"[",
"'user_id'",
"]",
"try",
":",
"group_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"AttrGroup",
")",
".",
"filter",
"(",
"AttrGroup",
".",
"id",
"==",
"group_id",
")",
".",
"one",
"(",
")",
"group_i",
".",
"project",
".",
"check_write_permission",
"(",
"user_id",
")",
"db",
".",
"DBSession",
".",
"delete",
"(",
"group_i",
")",
"db",
".",
"DBSession",
".",
"flush",
"(",
")",
"log",
".",
"info",
"(",
"\"Group %s in project %s deleted\"",
",",
"group_i",
".",
"id",
",",
"group_i",
".",
"project_id",
")",
"except",
"NoResultFound",
":",
"raise",
"HydraError",
"(",
"'No Attribute Group %s was found'",
",",
"group_id",
")",
"return",
"'OK'"
] |
Mostly used by payloads | def encode_value ( value , flags = None , base64 = False ) : if flags : # still a no-operation logger . debug ( "Flag %s encoding not implemented yet" % flags ) if not isinstance ( value , bytes ) : raise ValueError ( "value must be bytes" ) return b64encode ( value ) if base64 else value | 11,134 | https://github.com/johnnoone/aioconsul/blob/02f7a529d7dc2e49bed942111067aa5faf320e90/aioconsul/encoders/__init__.py#L8-L16 | [
"def",
"editLogSettings",
"(",
"self",
",",
"logLocation",
",",
"logLevel",
"=",
"\"WARNING\"",
",",
"maxLogFileAge",
"=",
"90",
")",
":",
"url",
"=",
"self",
".",
"_url",
"+",
"\"/settings/edit\"",
"params",
"=",
"{",
"\"f\"",
":",
"\"json\"",
",",
"\"logDir\"",
":",
"logLocation",
",",
"\"logLevel\"",
":",
"logLevel",
",",
"\"maxLogFileAge\"",
":",
"maxLogFileAge",
"}",
"return",
"self",
".",
"_post",
"(",
"url",
"=",
"url",
",",
"param_dict",
"=",
"params",
",",
"securityHandler",
"=",
"self",
".",
"_securityHandler",
",",
"proxy_url",
"=",
"self",
".",
"_proxy_url",
",",
"proxy_port",
"=",
"self",
".",
"_proxy_port",
")"
] |
Cleans up post - animation . | def _finishAnimation ( self ) : self . setCurrentIndex ( self . _nextIndex ) self . widget ( self . _lastIndex ) . hide ( ) self . widget ( self . _lastIndex ) . move ( self . _lastPoint ) self . _active = False if not self . signalsBlocked ( ) : self . animationFinished . emit ( ) | 11,135 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xstackedwidget.py#L66-L76 | [
"def",
"user_deleted_from_site_event",
"(",
"event",
")",
":",
"userid",
"=",
"event",
".",
"principal",
"catalog",
"=",
"api",
".",
"portal",
".",
"get_tool",
"(",
"'portal_catalog'",
")",
"query",
"=",
"{",
"'object_provides'",
":",
"WORKSPACE_INTERFACE",
"}",
"query",
"[",
"'workspace_members'",
"]",
"=",
"userid",
"workspaces",
"=",
"[",
"IWorkspace",
"(",
"b",
".",
"_unrestrictedGetObject",
"(",
")",
")",
"for",
"b",
"in",
"catalog",
".",
"unrestrictedSearchResults",
"(",
"query",
")",
"]",
"for",
"workspace",
"in",
"workspaces",
":",
"workspace",
".",
"remove_from_team",
"(",
"userid",
")"
] |
Clears out the widgets from this stack . | def clear ( self ) : for i in range ( self . count ( ) - 1 , - 1 , - 1 ) : w = self . widget ( i ) if w : self . removeWidget ( w ) w . close ( ) w . deleteLater ( ) | 11,136 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xstackedwidget.py#L86-L95 | [
"def",
"getDefaultItems",
"(",
"self",
")",
":",
"return",
"[",
"RtiRegItem",
"(",
"'HDF-5 file'",
",",
"'argos.repo.rtiplugins.hdf5.H5pyFileRti'",
",",
"extensions",
"=",
"[",
"'hdf5'",
",",
"'h5'",
",",
"'h5e'",
",",
"'he5'",
",",
"'nc'",
"]",
")",
",",
"# hdf extension is for HDF-4",
"RtiRegItem",
"(",
"'MATLAB file'",
",",
"'argos.repo.rtiplugins.scipyio.MatlabFileRti'",
",",
"extensions",
"=",
"[",
"'mat'",
"]",
")",
",",
"RtiRegItem",
"(",
"'NetCDF file'",
",",
"'argos.repo.rtiplugins.ncdf.NcdfFileRti'",
",",
"#extensions=['nc', 'nc3', 'nc4']),",
"extensions",
"=",
"[",
"'nc'",
",",
"'nc4'",
"]",
")",
",",
"#extensions=[]),",
"RtiRegItem",
"(",
"'NumPy binary file'",
",",
"'argos.repo.rtiplugins.numpyio.NumpyBinaryFileRti'",
",",
"extensions",
"=",
"[",
"'npy'",
"]",
")",
",",
"RtiRegItem",
"(",
"'NumPy compressed file'",
",",
"'argos.repo.rtiplugins.numpyio.NumpyCompressedFileRti'",
",",
"extensions",
"=",
"[",
"'npz'",
"]",
")",
",",
"RtiRegItem",
"(",
"'NumPy text file'",
",",
"'argos.repo.rtiplugins.numpyio.NumpyTextFileRti'",
",",
"#extensions=['txt', 'text']),",
"extensions",
"=",
"[",
"'dat'",
"]",
")",
",",
"RtiRegItem",
"(",
"'IDL save file'",
",",
"'argos.repo.rtiplugins.scipyio.IdlSaveFileRti'",
",",
"extensions",
"=",
"[",
"'sav'",
"]",
")",
",",
"RtiRegItem",
"(",
"'Pandas CSV file'",
",",
"'argos.repo.rtiplugins.pandasio.PandasCsvFileRti'",
",",
"extensions",
"=",
"[",
"'csv'",
"]",
")",
",",
"RtiRegItem",
"(",
"'Pillow image'",
",",
"'argos.repo.rtiplugins.pillowio.PillowFileRti'",
",",
"extensions",
"=",
"[",
"'bmp'",
",",
"'eps'",
",",
"'im'",
",",
"'gif'",
",",
"'jpg'",
",",
"'jpeg'",
",",
"'msp'",
",",
"'pcx'",
",",
"'png'",
",",
"'ppm'",
",",
"'spi'",
",",
"'tif'",
",",
"'tiff'",
",",
"'xbm'",
",",
"'xv'",
"]",
")",
",",
"RtiRegItem",
"(",
"'Wav file'",
",",
"'argos.repo.rtiplugins.scipyio.WavFileRti'",
",",
"extensions",
"=",
"[",
"'wav'",
"]",
")",
"]"
] |
OpenVPN status list method | def list ( conf ) : try : config = init_config ( conf ) conn = get_conn ( config . get ( 'DEFAULT' , 'statusdb' ) ) cur = conn . cursor ( ) sqlstr = '''select * from client_status order by ctime desc ''' cur . execute ( sqlstr ) result = cur . fetchall ( ) conn . commit ( ) conn . close ( ) for r in result : print r except Exception , e : traceback . print_exc ( ) | 11,137 | https://github.com/talkincode/txradius/blob/b86fdbc9be41183680b82b07d3a8e8ea10926e01/txradius/openvpn/statusdb.py#L130-L145 | [
"def",
"_add_new_repo",
"(",
"repo",
",",
"properties",
")",
":",
"repostr",
"=",
"'# '",
"if",
"not",
"properties",
".",
"get",
"(",
"'enabled'",
")",
"else",
"''",
"repostr",
"+=",
"'src/gz '",
"if",
"properties",
".",
"get",
"(",
"'compressed'",
")",
"else",
"'src '",
"if",
"' '",
"in",
"repo",
":",
"repostr",
"+=",
"'\"'",
"+",
"repo",
"+",
"'\" '",
"else",
":",
"repostr",
"+=",
"repo",
"+",
"' '",
"repostr",
"+=",
"properties",
".",
"get",
"(",
"'uri'",
")",
"repostr",
"=",
"_set_trusted_option_if_needed",
"(",
"repostr",
",",
"properties",
".",
"get",
"(",
"'trusted'",
")",
")",
"repostr",
"+=",
"'\\n'",
"conffile",
"=",
"os",
".",
"path",
".",
"join",
"(",
"OPKG_CONFDIR",
",",
"repo",
"+",
"'.conf'",
")",
"with",
"salt",
".",
"utils",
".",
"files",
".",
"fopen",
"(",
"conffile",
",",
"'a'",
")",
"as",
"fhandle",
":",
"fhandle",
".",
"write",
"(",
"salt",
".",
"utils",
".",
"stringutils",
".",
"to_str",
"(",
"repostr",
")",
")"
] |
OpenVPN status initdb method | def cli ( conf ) : try : config = init_config ( conf ) debug = config . getboolean ( 'DEFAULT' , 'debug' ) conn = get_conn ( config . get ( 'DEFAULT' , 'statusdb' ) ) cur = conn . cursor ( ) sqlstr = '''create table client_status
(session_id text PRIMARY KEY, username text, userip text,
realip text, realport int,ctime int,
inbytes int, outbytes int,
acct_interval int, session_timeout int, uptime int)
''' try : cur . execute ( 'drop table client_status' ) except : pass cur . execute ( sqlstr ) print 'flush client status database' conn . commit ( ) conn . close ( ) except : traceback . print_exc ( ) | 11,138 | https://github.com/talkincode/txradius/blob/b86fdbc9be41183680b82b07d3a8e8ea10926e01/txradius/openvpn/statusdb.py#L150-L173 | [
"def",
"extract_files",
"(",
"files",
")",
":",
"expanded_files",
"=",
"[",
"]",
"legal_extensions",
"=",
"[",
"\".md\"",
",",
"\".txt\"",
",",
"\".rtf\"",
",",
"\".html\"",
",",
"\".tex\"",
",",
"\".markdown\"",
"]",
"for",
"f",
"in",
"files",
":",
"# If it's a directory, recursively walk through it and find the files.",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"f",
")",
":",
"for",
"dir_",
",",
"_",
",",
"filenames",
"in",
"os",
".",
"walk",
"(",
"f",
")",
":",
"for",
"filename",
"in",
"filenames",
":",
"fn",
",",
"file_extension",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"if",
"file_extension",
"in",
"legal_extensions",
":",
"joined_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dir_",
",",
"filename",
")",
"expanded_files",
".",
"append",
"(",
"joined_file",
")",
"# Otherwise add the file directly.",
"else",
":",
"expanded_files",
".",
"append",
"(",
"f",
")",
"return",
"expanded_files"
] |
Registers a new local service . | async def register ( self , service ) : response = await self . _api . put ( "/v1/agent/service/register" , data = service ) return response . status == 200 | 11,139 | https://github.com/johnnoone/aioconsul/blob/02f7a529d7dc2e49bed942111067aa5faf320e90/aioconsul/client/services_endpoint.py#L31-L116 | [
"def",
"_create_comparison_method",
"(",
"cls",
",",
"op",
")",
":",
"def",
"wrapper",
"(",
"self",
",",
"other",
")",
":",
"if",
"isinstance",
"(",
"other",
",",
"ABCSeries",
")",
":",
"# the arrays defer to Series for comparison ops but the indexes",
"# don't, so we have to unwrap here.",
"other",
"=",
"other",
".",
"_values",
"result",
"=",
"op",
"(",
"self",
".",
"_data",
",",
"maybe_unwrap_index",
"(",
"other",
")",
")",
"return",
"result",
"wrapper",
".",
"__doc__",
"=",
"op",
".",
"__doc__",
"wrapper",
".",
"__name__",
"=",
"'__{}__'",
".",
"format",
"(",
"op",
".",
"__name__",
")",
"return",
"wrapper"
] |
Deregisters a local service | async def deregister ( self , service ) : service_id = extract_attr ( service , keys = [ "ServiceID" , "ID" ] ) response = await self . _api . get ( "/v1/agent/service/deregister" , service_id ) return response . status == 200 | 11,140 | https://github.com/johnnoone/aioconsul/blob/02f7a529d7dc2e49bed942111067aa5faf320e90/aioconsul/client/services_endpoint.py#L118-L133 | [
"def",
"enum",
"(",
"option",
",",
"*",
"options",
")",
":",
"options",
"=",
"(",
"option",
",",
")",
"+",
"options",
"rangeob",
"=",
"range",
"(",
"len",
"(",
"options",
")",
")",
"try",
":",
"inttype",
"=",
"_inttypes",
"[",
"int",
"(",
"np",
".",
"log2",
"(",
"len",
"(",
"options",
")",
"-",
"1",
")",
")",
"//",
"8",
"]",
"except",
"IndexError",
":",
"raise",
"OverflowError",
"(",
"'Cannot store enums with more than sys.maxsize elements, got %d'",
"%",
"len",
"(",
"options",
")",
",",
")",
"class",
"_enum",
"(",
"Structure",
")",
":",
"_fields_",
"=",
"[",
"(",
"o",
",",
"inttype",
")",
"for",
"o",
"in",
"options",
"]",
"def",
"__iter__",
"(",
"self",
")",
":",
"return",
"iter",
"(",
"rangeob",
")",
"def",
"__contains__",
"(",
"self",
",",
"value",
")",
":",
"return",
"0",
"<=",
"value",
"<",
"len",
"(",
"options",
")",
"def",
"__repr__",
"(",
"self",
")",
":",
"return",
"'<enum: %s>'",
"%",
"(",
"(",
"'%d fields'",
"%",
"len",
"(",
"options",
")",
")",
"if",
"len",
"(",
"options",
")",
">",
"10",
"else",
"repr",
"(",
"options",
")",
")",
"return",
"_enum",
"(",
"*",
"rangeob",
")"
] |
Enters maintenance mode for service | async def disable ( self , service , * , reason = None ) : return await self . maintenance ( service , False , reason = reason ) | 11,141 | https://github.com/johnnoone/aioconsul/blob/02f7a529d7dc2e49bed942111067aa5faf320e90/aioconsul/client/services_endpoint.py#L135-L152 | [
"def",
"memory_read64",
"(",
"self",
",",
"addr",
",",
"num_long_words",
")",
":",
"buf_size",
"=",
"num_long_words",
"buf",
"=",
"(",
"ctypes",
".",
"c_ulonglong",
"*",
"buf_size",
")",
"(",
")",
"units_read",
"=",
"self",
".",
"_dll",
".",
"JLINKARM_ReadMemU64",
"(",
"addr",
",",
"buf_size",
",",
"buf",
",",
"0",
")",
"if",
"units_read",
"<",
"0",
":",
"raise",
"errors",
".",
"JLinkException",
"(",
"units_read",
")",
"return",
"buf",
"[",
":",
"units_read",
"]"
] |
Resumes normal operation for service | async def enable ( self , service , * , reason = None ) : return await self . maintenance ( service , False , reason = reason ) | 11,142 | https://github.com/johnnoone/aioconsul/blob/02f7a529d7dc2e49bed942111067aa5faf320e90/aioconsul/client/services_endpoint.py#L154-L164 | [
"def",
"_getImageSize",
"(",
"filename",
")",
":",
"result",
"=",
"None",
"file",
"=",
"open",
"(",
"filename",
",",
"'rb'",
")",
"if",
"file",
".",
"read",
"(",
"8",
")",
"==",
"b'\\x89PNG\\r\\n\\x1a\\n'",
":",
"# PNG",
"while",
"1",
":",
"length",
",",
"=",
"_struct",
".",
"unpack",
"(",
"'>i'",
",",
"file",
".",
"read",
"(",
"4",
")",
")",
"chunkID",
"=",
"file",
".",
"read",
"(",
"4",
")",
"if",
"chunkID",
"==",
"''",
":",
"# EOF",
"break",
"if",
"chunkID",
"==",
"b'IHDR'",
":",
"# return width, height",
"result",
"=",
"_struct",
".",
"unpack",
"(",
"'>ii'",
",",
"file",
".",
"read",
"(",
"8",
")",
")",
"break",
"file",
".",
"seek",
"(",
"4",
"+",
"length",
",",
"1",
")",
"file",
".",
"close",
"(",
")",
"return",
"result",
"file",
".",
"seek",
"(",
"0",
")",
"if",
"file",
".",
"read",
"(",
"8",
")",
"==",
"b'BM'",
":",
"# Bitmap",
"file",
".",
"seek",
"(",
"18",
",",
"0",
")",
"# skip to size data",
"result",
"=",
"_struct",
".",
"unpack",
"(",
"'<ii'",
",",
"file",
".",
"read",
"(",
"8",
")",
")",
"file",
".",
"close",
"(",
")",
"return",
"result"
] |
3 . 3 . Generating 128 - bit Session Keys | def mppe_chap2_gen_keys ( password , nt_response ) : password_hash = mschap . nt_password_hash ( password ) password_hash_hash = mschap . hash_nt_password_hash ( password_hash ) master_key = get_master_key ( password_hash_hash , nt_response ) master_send_key = get_asymetric_start_key ( master_key , 16 , True , True ) master_recv_key = get_asymetric_start_key ( master_key , 16 , False , True ) return master_send_key , master_recv_key | 11,143 | https://github.com/talkincode/txradius/blob/b86fdbc9be41183680b82b07d3a8e8ea10926e01/txradius/mschap/mppe.py#L45-L93 | [
"def",
"async_or_fail",
"(",
"self",
",",
"*",
"*",
"options",
")",
":",
"args",
"=",
"options",
".",
"pop",
"(",
"\"args\"",
",",
"None",
")",
"kwargs",
"=",
"options",
".",
"pop",
"(",
"\"kwargs\"",
",",
"None",
")",
"possible_broker_errors",
"=",
"self",
".",
"_get_possible_broker_errors_tuple",
"(",
")",
"try",
":",
"return",
"self",
".",
"apply_async",
"(",
"args",
",",
"kwargs",
",",
"*",
"*",
"options",
")",
"except",
"possible_broker_errors",
"as",
"e",
":",
"return",
"self",
".",
"simulate_async_error",
"(",
"e",
")"
] |
The connection raw sql query when select table show table to fetch records it is compatible the dbi execute method . | def query ( self , sql , args = None , many = None , as_dict = False ) : con = self . pool . pop ( ) c = None try : c = con . cursor ( as_dict ) LOGGER . debug ( "Query sql: " + sql + " args:" + str ( args ) ) c . execute ( sql , args ) if many and many > 0 : return self . _yield ( con , c , many ) else : return c . fetchall ( ) except Exception as e : LOGGER . error ( "Error Qeury on %s" , str ( e ) ) raise DBError ( e . args [ 0 ] , e . args [ 1 ] ) finally : many or ( c and c . close ( ) ) many or ( con and self . pool . push ( con ) ) | 11,144 | https://github.com/whiteclover/dbpy/blob/3d9ce85f55cfb39cced22081e525f79581b26b3a/db/_db.py#L85-L112 | [
"def",
"invort",
"(",
"m",
")",
":",
"m",
"=",
"stypes",
".",
"toDoubleMatrix",
"(",
"m",
")",
"mout",
"=",
"stypes",
".",
"emptyDoubleMatrix",
"(",
")",
"libspice",
".",
"invort_c",
"(",
"m",
",",
"mout",
")",
"return",
"stypes",
".",
"cMatrixToNumpy",
"(",
"mout",
")"
] |
Get connection class by adapter | def connection_class ( self , adapter ) : if self . adapters . get ( adapter ) : return self . adapters [ adapter ] try : class_prefix = getattr ( __import__ ( 'db.' + adapter , globals ( ) , locals ( ) , [ '__class_prefix__' ] ) , '__class_prefix__' ) driver = self . _import_class ( 'db.' + adapter + '.connection.' + class_prefix + 'Connection' ) except ImportError : raise DBError ( "Must install adapter `%s` or doesn't support" % ( adapter ) ) self . adapters [ adapter ] = driver return driver | 11,145 | https://github.com/whiteclover/dbpy/blob/3d9ce85f55cfb39cced22081e525f79581b26b3a/db/_db.py#L164-L179 | [
"def",
"encode",
"(",
"self",
",",
"frame",
":",
"Frame",
")",
"->",
"Frame",
":",
"# Skip control frames.",
"if",
"frame",
".",
"opcode",
"in",
"CTRL_OPCODES",
":",
"return",
"frame",
"# Since we always encode and never fragment messages, there's no logic",
"# similar to decode() here at this time.",
"if",
"frame",
".",
"opcode",
"!=",
"OP_CONT",
":",
"# Re-initialize per-message decoder.",
"if",
"self",
".",
"local_no_context_takeover",
":",
"self",
".",
"encoder",
"=",
"zlib",
".",
"compressobj",
"(",
"wbits",
"=",
"-",
"self",
".",
"local_max_window_bits",
",",
"*",
"*",
"self",
".",
"compress_settings",
")",
"# Compress data frames.",
"data",
"=",
"self",
".",
"encoder",
".",
"compress",
"(",
"frame",
".",
"data",
")",
"+",
"self",
".",
"encoder",
".",
"flush",
"(",
"zlib",
".",
"Z_SYNC_FLUSH",
")",
"if",
"frame",
".",
"fin",
"and",
"data",
".",
"endswith",
"(",
"_EMPTY_UNCOMPRESSED_BLOCK",
")",
":",
"data",
"=",
"data",
"[",
":",
"-",
"4",
"]",
"# Allow garbage collection of the encoder if it won't be reused.",
"if",
"frame",
".",
"fin",
"and",
"self",
".",
"local_no_context_takeover",
":",
"del",
"self",
".",
"encoder",
"return",
"frame",
".",
"_replace",
"(",
"data",
"=",
"data",
",",
"rsv1",
"=",
"True",
")"
] |
Get dialect sql class by adapter | def dialect_class ( self , adapter ) : if self . dialects . get ( adapter ) : return self . dialects [ adapter ] try : class_prefix = getattr ( __import__ ( 'db.' + adapter , globals ( ) , locals ( ) , [ '__class_prefix__' ] ) , '__class_prefix__' ) driver = self . _import_class ( 'db.' + adapter + '.dialect.' + class_prefix + 'Dialect' ) except ImportError : raise DBError ( "Must install adapter `%s` or doesn't support" % ( adapter ) ) self . dialects [ adapter ] = driver return driver | 11,146 | https://github.com/whiteclover/dbpy/blob/3d9ce85f55cfb39cced22081e525f79581b26b3a/db/_db.py#L181-L196 | [
"def",
"write_data",
"(",
"self",
",",
"data",
",",
"file_datetime",
")",
":",
"with",
"self",
".",
"__lock",
":",
"assert",
"data",
"is",
"not",
"None",
"absolute_file_path",
"=",
"self",
".",
"__file_path",
"#logging.debug(\"WRITE data file %s for %s\", absolute_file_path, key)",
"make_directory_if_needed",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"absolute_file_path",
")",
")",
"properties",
"=",
"self",
".",
"read_properties",
"(",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"absolute_file_path",
")",
"else",
"dict",
"(",
")",
"write_zip",
"(",
"absolute_file_path",
",",
"data",
",",
"properties",
")",
"# convert to utc time.",
"tz_minutes",
"=",
"Utility",
".",
"local_utcoffset_minutes",
"(",
"file_datetime",
")",
"timestamp",
"=",
"calendar",
".",
"timegm",
"(",
"file_datetime",
".",
"timetuple",
"(",
")",
")",
"-",
"tz_minutes",
"*",
"60",
"os",
".",
"utime",
"(",
"absolute_file_path",
",",
"(",
"time",
".",
"time",
"(",
")",
",",
"timestamp",
")",
")"
] |
Import class by module dot split string | def _import_class ( self , module2cls ) : d = module2cls . rfind ( "." ) classname = module2cls [ d + 1 : len ( module2cls ) ] m = __import__ ( module2cls [ 0 : d ] , globals ( ) , locals ( ) , [ classname ] ) return getattr ( m , classname ) | 11,147 | https://github.com/whiteclover/dbpy/blob/3d9ce85f55cfb39cced22081e525f79581b26b3a/db/_db.py#L198-L203 | [
"def",
"_write_cpr",
"(",
"self",
",",
"f",
",",
"cType",
",",
"parameter",
")",
"->",
"int",
":",
"f",
".",
"seek",
"(",
"0",
",",
"2",
")",
"byte_loc",
"=",
"f",
".",
"tell",
"(",
")",
"block_size",
"=",
"CDF",
".",
"CPR_BASE_SIZE64",
"+",
"4",
"section_type",
"=",
"CDF",
".",
"CPR_",
"rfuA",
"=",
"0",
"pCount",
"=",
"1",
"cpr",
"=",
"bytearray",
"(",
"block_size",
")",
"cpr",
"[",
"0",
":",
"8",
"]",
"=",
"struct",
".",
"pack",
"(",
"'>q'",
",",
"block_size",
")",
"cpr",
"[",
"8",
":",
"12",
"]",
"=",
"struct",
".",
"pack",
"(",
"'>i'",
",",
"section_type",
")",
"cpr",
"[",
"12",
":",
"16",
"]",
"=",
"struct",
".",
"pack",
"(",
"'>i'",
",",
"cType",
")",
"cpr",
"[",
"16",
":",
"20",
"]",
"=",
"struct",
".",
"pack",
"(",
"'>i'",
",",
"rfuA",
")",
"cpr",
"[",
"20",
":",
"24",
"]",
"=",
"struct",
".",
"pack",
"(",
"'>i'",
",",
"pCount",
")",
"cpr",
"[",
"24",
":",
"28",
"]",
"=",
"struct",
".",
"pack",
"(",
"'>i'",
",",
"parameter",
")",
"f",
".",
"write",
"(",
"cpr",
")",
"return",
"byte_loc"
] |
Rebuilds the tracker item . | def rebuild ( self , gridRect ) : scene = self . scene ( ) if ( not scene ) : return self . setVisible ( gridRect . contains ( self . pos ( ) ) ) self . setZValue ( 100 ) path = QPainterPath ( ) path . moveTo ( 0 , 0 ) path . lineTo ( 0 , gridRect . height ( ) ) tip = '' tip_point = None self . _ellipses = [ ] items = scene . collidingItems ( self ) self . _basePath = QPainterPath ( path ) for item in items : item_path = item . path ( ) found = None for y in range ( int ( gridRect . top ( ) ) , int ( gridRect . bottom ( ) ) ) : point = QPointF ( self . pos ( ) . x ( ) , y ) if ( item_path . contains ( point ) ) : found = QPointF ( 0 , y - self . pos ( ) . y ( ) ) break if ( found ) : path . addEllipse ( found , 6 , 6 ) self . _ellipses . append ( found ) # update the value information
value = scene . valueAt ( self . mapToScene ( found ) ) tip_point = self . mapToScene ( found ) hruler = scene . horizontalRuler ( ) vruler = scene . verticalRuler ( ) x_value = hruler . formatValue ( value [ 0 ] ) y_value = vruler . formatValue ( value [ 1 ] ) tip = '<b>x:</b> %s<br/><b>y:</b> %s' % ( x_value , y_value ) self . setPath ( path ) self . setVisible ( True ) # show the popup widget
if ( tip ) : anchor = XPopupWidget . Anchor . RightCenter widget = self . scene ( ) . chartWidget ( ) tip_point = widget . mapToGlobal ( widget . mapFromScene ( tip_point ) ) XPopupWidget . showToolTip ( tip , anchor = anchor , parent = widget , point = tip_point , foreground = QColor ( 'blue' ) , background = QColor ( 148 , 148 , 255 ) ) | 11,148 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xchartwidget/xcharttrackeritem.py#L65-L124 | [
"def",
"merge_config",
"(",
"self",
",",
"user_config",
")",
":",
"# provisioanlly update the default configurations with the user preferences",
"temp_data_config",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"data_config",
")",
".",
"update",
"(",
"user_config",
")",
"temp_model_config",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"model_config",
")",
".",
"update",
"(",
"user_config",
")",
"temp_conversation_config",
"=",
"copy",
".",
"deepcopy",
"(",
"self",
".",
"conversation_config",
")",
".",
"update",
"(",
"user_config",
")",
"# if the new configurations validate, apply them",
"if",
"validate_data_config",
"(",
"temp_data_config",
")",
":",
"self",
".",
"data_config",
"=",
"temp_data_config",
"if",
"validate_model_config",
"(",
"temp_model_config",
")",
":",
"self",
".",
"model_config",
"=",
"temp_model_config",
"if",
"validate_conversation_config",
"(",
"temp_conversation_config",
")",
":",
"self",
".",
"conversation_config",
"=",
"temp_conversation_config"
] |
If a valid access token is in memory returns it Else feches a new token and returns it | def get_access_token ( self ) : if self . token_info and not self . is_token_expired ( self . token_info ) : return self . token_info [ 'access_token' ] token_info = self . _request_access_token ( ) token_info = self . _add_custom_values_to_token_info ( token_info ) self . token_info = token_info return self . token_info [ 'access_token' ] | 11,149 | https://github.com/ReneNulschDE/mercedesmejsonpy/blob/0618a0b49d6bb46599d11a8f66dc8d08d112ceec/mercedesmejsonpy/oauth.py#L56-L67 | [
"def",
"match_key",
"(",
"self",
")",
"->",
"Tuple",
"[",
"bool",
",",
"bool",
",",
"int",
",",
"List",
"[",
"WeightedPart",
"]",
"]",
":",
"if",
"self",
".",
"map",
"is",
"None",
":",
"raise",
"RuntimeError",
"(",
"f\"{self!r} is not bound to a Map\"",
")",
"complex_rule",
"=",
"any",
"(",
"weight",
".",
"converter",
"for",
"weight",
"in",
"self",
".",
"_weights",
")",
"return",
"(",
"not",
"bool",
"(",
"self",
".",
"defaults",
")",
",",
"complex_rule",
",",
"-",
"len",
"(",
"self",
".",
"_weights",
")",
",",
"self",
".",
"_weights",
")"
] |
Gets client credentials access token | def _request_access_token ( self ) : payload = { 'grant_type' : 'authorization_code' , 'code' : code , 'redirect_uri' : self . redirect_uri } headers = _make_authorization_headers ( self . client_id , self . client_secret ) response = requests . post ( self . OAUTH_TOKEN_URL , data = payload , headers = headers , verify = LOGIN_VERIFY_SSL_CERT ) if response . status_code is not 200 : raise MercedesMeAuthError ( response . reason ) token_info = response . json ( ) return token_info | 11,150 | https://github.com/ReneNulschDE/mercedesmejsonpy/blob/0618a0b49d6bb46599d11a8f66dc8d08d112ceec/mercedesmejsonpy/oauth.py#L69-L85 | [
"def",
"_match_directories",
"(",
"self",
",",
"entries",
",",
"root",
",",
"regex_string",
")",
":",
"self",
".",
"log",
"(",
"u\"Matching directory names in paged hierarchy\"",
")",
"self",
".",
"log",
"(",
"[",
"u\"Matching within '%s'\"",
",",
"root",
"]",
")",
"self",
".",
"log",
"(",
"[",
"u\"Matching regex '%s'\"",
",",
"regex_string",
"]",
")",
"regex",
"=",
"re",
".",
"compile",
"(",
"r\"\"",
"+",
"regex_string",
")",
"directories",
"=",
"set",
"(",
")",
"root_len",
"=",
"len",
"(",
"root",
")",
"for",
"entry",
"in",
"entries",
":",
"# look only inside root dir",
"if",
"entry",
".",
"startswith",
"(",
"root",
")",
":",
"self",
".",
"log",
"(",
"[",
"u\"Examining '%s'\"",
",",
"entry",
"]",
")",
"# remove common prefix root/",
"entry",
"=",
"entry",
"[",
"root_len",
"+",
"1",
":",
"]",
"# split path",
"entry_splitted",
"=",
"entry",
".",
"split",
"(",
"os",
".",
"sep",
")",
"# match regex",
"if",
"(",
"(",
"len",
"(",
"entry_splitted",
")",
">=",
"2",
")",
"and",
"(",
"re",
".",
"match",
"(",
"regex",
",",
"entry_splitted",
"[",
"0",
"]",
")",
"is",
"not",
"None",
")",
")",
":",
"directories",
".",
"add",
"(",
"entry_splitted",
"[",
"0",
"]",
")",
"self",
".",
"log",
"(",
"[",
"u\"Match: '%s'\"",
",",
"entry_splitted",
"[",
"0",
"]",
"]",
")",
"else",
":",
"self",
".",
"log",
"(",
"[",
"u\"No match: '%s'\"",
",",
"entry",
"]",
")",
"return",
"sorted",
"(",
"directories",
")"
] |
Gets a cached auth token | def get_cached_token ( self ) : token_info = None if self . cache_path : try : f = open ( self . cache_path ) token_info_string = f . read ( ) f . close ( ) token_info = json . loads ( token_info_string ) if self . is_token_expired ( token_info ) : token_info = self . refresh_access_token ( token_info [ 'refresh_token' ] ) except IOError : pass return token_info | 11,151 | https://github.com/ReneNulschDE/mercedesmejsonpy/blob/0618a0b49d6bb46599d11a8f66dc8d08d112ceec/mercedesmejsonpy/oauth.py#L126-L142 | [
"def",
"run_normalization",
"(",
"self",
")",
":",
"for",
"index",
",",
"media_file",
"in",
"enumerate",
"(",
"tqdm",
"(",
"self",
".",
"media_files",
",",
"desc",
"=",
"\"File\"",
",",
"disable",
"=",
"not",
"self",
".",
"progress",
",",
"position",
"=",
"0",
")",
")",
":",
"logger",
".",
"info",
"(",
"\"Normalizing file {} ({} of {})\"",
".",
"format",
"(",
"media_file",
",",
"index",
"+",
"1",
",",
"self",
".",
"file_count",
")",
")",
"media_file",
".",
"run_normalization",
"(",
")",
"logger",
".",
"info",
"(",
"\"Normalized file written to {}\"",
".",
"format",
"(",
"media_file",
".",
"output_file",
")",
")"
] |
Gets the URL to use to authorize this app | def get_authorize_url ( self , state = None ) : payload = { 'client_id' : self . client_id , 'response_type' : 'code' , 'redirect_uri' : self . redirect_uri , 'scope' : self . scope } urlparams = urllib . parse . urlencode ( payload ) return "%s?%s" % ( self . OAUTH_AUTHORIZE_URL , urlparams ) | 11,152 | https://github.com/ReneNulschDE/mercedesmejsonpy/blob/0618a0b49d6bb46599d11a8f66dc8d08d112ceec/mercedesmejsonpy/oauth.py#L156-L166 | [
"def",
"list_attachments",
"(",
"fullname",
")",
":",
"parent",
",",
"filename",
"=",
"os",
".",
"path",
".",
"split",
"(",
"fullname",
")",
"filename_without_ext",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"attachments",
"=",
"[",
"]",
"for",
"found_filename",
"in",
"os",
".",
"listdir",
"(",
"parent",
")",
":",
"found_filename_without_ext",
",",
"_",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"found_filename",
")",
"if",
"filename_without_ext",
"==",
"found_filename_without_ext",
"and",
"found_filename",
"!=",
"filename",
":",
"attachments",
".",
"append",
"(",
"os",
".",
"path",
".",
"join",
"(",
"parent",
",",
"found_filename",
")",
")",
"return",
"attachments"
] |
Gets the access token for the app given the code | def get_access_token ( self , code ) : payload = { 'redirect_uri' : self . redirect_uri , 'code' : code , 'grant_type' : 'authorization_code' } headers = self . _make_authorization_headers ( ) response = requests . post ( self . OAUTH_TOKEN_URL , data = payload , headers = headers , verify = LOGIN_VERIFY_SSL_CERT ) if response . status_code is not 200 : raise MercedesMeAuthError ( response . reason ) token_info = response . json ( ) token_info = self . _add_custom_values_to_token_info ( token_info ) self . _save_token_info ( token_info ) return token_info | 11,153 | https://github.com/ReneNulschDE/mercedesmejsonpy/blob/0618a0b49d6bb46599d11a8f66dc8d08d112ceec/mercedesmejsonpy/oauth.py#L183-L203 | [
"def",
"reindex_multifiles",
"(",
"portal",
")",
":",
"logger",
".",
"info",
"(",
"\"Reindexing Multifiles ...\"",
")",
"brains",
"=",
"api",
".",
"search",
"(",
"dict",
"(",
"portal_type",
"=",
"\"Multifile\"",
")",
",",
"\"bika_setup_catalog\"",
")",
"total",
"=",
"len",
"(",
"brains",
")",
"for",
"num",
",",
"brain",
"in",
"enumerate",
"(",
"brains",
")",
":",
"if",
"num",
"%",
"100",
"==",
"0",
":",
"logger",
".",
"info",
"(",
"\"Reindexing Multifile: {0}/{1}\"",
".",
"format",
"(",
"num",
",",
"total",
")",
")",
"obj",
"=",
"api",
".",
"get_object",
"(",
"brain",
")",
"obj",
".",
"reindexObject",
"(",
")"
] |
Store some values that aren t directly provided by a Web API response . | def _add_custom_values_to_token_info ( self , token_info ) : token_info [ 'expires_at' ] = int ( time . time ( ) ) + token_info [ 'expires_in' ] token_info [ 'scope' ] = self . scope return token_info | 11,154 | https://github.com/ReneNulschDE/mercedesmejsonpy/blob/0618a0b49d6bb46599d11a8f66dc8d08d112ceec/mercedesmejsonpy/oauth.py#L226-L233 | [
"def",
"_open_ds_from_store",
"(",
"fname",
",",
"store_mod",
"=",
"None",
",",
"store_cls",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"fname",
",",
"xr",
".",
"Dataset",
")",
":",
"return",
"fname",
"if",
"not",
"isstring",
"(",
"fname",
")",
":",
"try",
":",
"# test iterable",
"fname",
"[",
"0",
"]",
"except",
"TypeError",
":",
"pass",
"else",
":",
"if",
"store_mod",
"is",
"not",
"None",
"and",
"store_cls",
"is",
"not",
"None",
":",
"if",
"isstring",
"(",
"store_mod",
")",
":",
"store_mod",
"=",
"repeat",
"(",
"store_mod",
")",
"if",
"isstring",
"(",
"store_cls",
")",
":",
"store_cls",
"=",
"repeat",
"(",
"store_cls",
")",
"fname",
"=",
"[",
"_open_store",
"(",
"sm",
",",
"sc",
",",
"f",
")",
"for",
"sm",
",",
"sc",
",",
"f",
"in",
"zip",
"(",
"store_mod",
",",
"store_cls",
",",
"fname",
")",
"]",
"kwargs",
"[",
"'engine'",
"]",
"=",
"None",
"kwargs",
"[",
"'lock'",
"]",
"=",
"False",
"return",
"open_mfdataset",
"(",
"fname",
",",
"*",
"*",
"kwargs",
")",
"if",
"store_mod",
"is",
"not",
"None",
"and",
"store_cls",
"is",
"not",
"None",
":",
"fname",
"=",
"_open_store",
"(",
"store_mod",
",",
"store_cls",
",",
"fname",
")",
"return",
"open_dataset",
"(",
"fname",
",",
"*",
"*",
"kwargs",
")"
] |
Clears the actions for this widget . | def clear ( self , autoBuild = True ) : for action in self . _actionGroup . actions ( ) : self . _actionGroup . removeAction ( action ) action = QAction ( '' , self ) action . setObjectName ( 'place_holder' ) self . _actionGroup . addAction ( action ) if autoBuild : self . rebuild ( ) | 11,155 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xsplitbutton.py#L187-L198 | [
"def",
"external_metadata",
"(",
"self",
",",
"datasource_type",
"=",
"None",
",",
"datasource_id",
"=",
"None",
")",
":",
"if",
"datasource_type",
"==",
"'druid'",
":",
"datasource",
"=",
"ConnectorRegistry",
".",
"get_datasource",
"(",
"datasource_type",
",",
"datasource_id",
",",
"db",
".",
"session",
")",
"elif",
"datasource_type",
"==",
"'table'",
":",
"database",
"=",
"(",
"db",
".",
"session",
".",
"query",
"(",
"Database",
")",
".",
"filter_by",
"(",
"id",
"=",
"request",
".",
"args",
".",
"get",
"(",
"'db_id'",
")",
")",
".",
"one",
"(",
")",
")",
"Table",
"=",
"ConnectorRegistry",
".",
"sources",
"[",
"'table'",
"]",
"datasource",
"=",
"Table",
"(",
"database",
"=",
"database",
",",
"table_name",
"=",
"request",
".",
"args",
".",
"get",
"(",
"'table_name'",
")",
",",
"schema",
"=",
"request",
".",
"args",
".",
"get",
"(",
"'schema'",
")",
"or",
"None",
",",
")",
"external_metadata",
"=",
"datasource",
".",
"external_metadata",
"(",
")",
"return",
"self",
".",
"json_response",
"(",
"external_metadata",
")"
] |
Copies the current filepath contents to the current clipboard . | def copyFilepath ( self ) : clipboard = QApplication . instance ( ) . clipboard ( ) clipboard . setText ( self . filepath ( ) ) clipboard . setText ( self . filepath ( ) , clipboard . Selection ) | 11,156 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xfilepathedit.py#L136-L142 | [
"def",
"ttl",
"(",
"self",
",",
"value",
")",
":",
"# get timer",
"timer",
"=",
"getattr",
"(",
"self",
",",
"Annotation",
".",
"__TIMER",
",",
"None",
")",
"# if timer is running, stop the timer",
"if",
"timer",
"is",
"not",
"None",
":",
"timer",
".",
"cancel",
"(",
")",
"# initialize timestamp",
"timestamp",
"=",
"None",
"# if value is None",
"if",
"value",
"is",
"None",
":",
"# nonify timer",
"timer",
"=",
"None",
"else",
":",
"# else, renew a timer",
"# get timestamp",
"timestamp",
"=",
"time",
"(",
")",
"+",
"value",
"# start a new timer",
"timer",
"=",
"Timer",
"(",
"value",
",",
"self",
".",
"__del__",
")",
"timer",
".",
"start",
"(",
")",
"# set/update attributes",
"setattr",
"(",
"self",
",",
"Annotation",
".",
"__TIMER",
",",
"timer",
")",
"setattr",
"(",
"self",
",",
"Annotation",
".",
"__TS",
",",
"timestamp",
")"
] |
Prompts the user to select a filepath from the system based on the \ current filepath mode . | def pickFilepath ( self ) : mode = self . filepathMode ( ) filepath = '' filepaths = [ ] curr_dir = nativestring ( self . _filepathEdit . text ( ) ) if ( not curr_dir ) : curr_dir = QDir . currentPath ( ) if mode == XFilepathEdit . Mode . SaveFile : filepath = QFileDialog . getSaveFileName ( self , self . windowTitle ( ) , curr_dir , self . filepathTypes ( ) ) elif mode == XFilepathEdit . Mode . OpenFile : filepath = QFileDialog . getOpenFileName ( self , self . windowTitle ( ) , curr_dir , self . filepathTypes ( ) ) elif mode == XFilepathEdit . Mode . OpenFiles : filepaths = QFileDialog . getOpenFileNames ( self , self . windowTitle ( ) , curr_dir , self . filepathTypes ( ) ) else : filepath = QFileDialog . getExistingDirectory ( self , self . windowTitle ( ) , curr_dir ) if filepath : if type ( filepath ) == tuple : filepath = filepath [ 0 ] self . setFilepath ( nativestring ( filepath ) ) elif filepaths : self . setFilepaths ( map ( str , filepaths ) ) | 11,157 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xfilepathedit.py#L322-L363 | [
"def",
"remove_zone_record",
"(",
"self",
",",
"id",
",",
"domain",
",",
"subdomain",
"=",
"None",
")",
":",
"if",
"subdomain",
"is",
"None",
":",
"subdomain",
"=",
"\"@\"",
"_validate_int",
"(",
"\"id\"",
",",
"id",
")",
"self",
".",
"_call",
"(",
"\"removeZoneRecord\"",
",",
"domain",
",",
"subdomain",
",",
"id",
")"
] |
Popups a menu for this widget . | def showMenu ( self , pos ) : menu = QMenu ( self ) menu . setAttribute ( Qt . WA_DeleteOnClose ) menu . addAction ( 'Clear' ) . triggered . connect ( self . clearFilepath ) menu . addSeparator ( ) menu . addAction ( 'Copy Filepath' ) . triggered . connect ( self . copyFilepath ) menu . exec_ ( self . mapToGlobal ( pos ) ) | 11,158 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xfilepathedit.py#L519-L529 | [
"def",
"read_frames",
"(",
"cls",
",",
"reader",
")",
":",
"rval",
"=",
"deque",
"(",
")",
"while",
"True",
":",
"frame_start_pos",
"=",
"reader",
".",
"tell",
"(",
")",
"try",
":",
"frame",
"=",
"Frame",
".",
"_read_frame",
"(",
"reader",
")",
"except",
"Reader",
".",
"BufferUnderflow",
":",
"# No more data in the stream",
"frame",
"=",
"None",
"except",
"Reader",
".",
"ReaderError",
"as",
"e",
":",
"# Some other format error",
"raise",
"Frame",
".",
"FormatError",
",",
"str",
"(",
"e",
")",
",",
"sys",
".",
"exc_info",
"(",
")",
"[",
"-",
"1",
"]",
"except",
"struct",
".",
"error",
"as",
"e",
":",
"raise",
"Frame",
".",
"FormatError",
",",
"str",
"(",
"e",
")",
",",
"sys",
".",
"exc_info",
"(",
")",
"[",
"-",
"1",
"]",
"if",
"frame",
"is",
"None",
":",
"reader",
".",
"seek",
"(",
"frame_start_pos",
")",
"break",
"rval",
".",
"append",
"(",
"frame",
")",
"return",
"rval"
] |
Alters the color scheme based on the validation settings . | def validateFilepath ( self ) : if ( not self . isValidated ( ) ) : return valid = self . isValid ( ) if ( not valid ) : fg = self . invalidForeground ( ) bg = self . invalidBackground ( ) else : fg = self . validForeground ( ) bg = self . validBackground ( ) palette = self . palette ( ) palette . setColor ( palette . Base , bg ) palette . setColor ( palette . Text , fg ) self . _filepathEdit . setPalette ( palette ) | 11,159 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xfilepathedit.py#L547-L565 | [
"def",
"read_file",
"(",
"self",
",",
"file",
":",
"Union",
"[",
"IO",
",",
"asyncio",
".",
"StreamWriter",
"]",
"=",
"None",
")",
":",
"if",
"file",
":",
"file_is_async",
"=",
"hasattr",
"(",
"file",
",",
"'drain'",
")",
"while",
"True",
":",
"data",
"=",
"yield",
"from",
"self",
".",
"_connection",
".",
"read",
"(",
"4096",
")",
"if",
"not",
"data",
":",
"break",
"if",
"file",
":",
"file",
".",
"write",
"(",
"data",
")",
"if",
"file_is_async",
":",
"yield",
"from",
"file",
".",
"drain",
"(",
")",
"self",
".",
"_data_event_dispatcher",
".",
"notify_read",
"(",
"data",
")"
] |
Clears the information for this edit . | def clear ( self ) : self . uiQueryTXT . setText ( '' ) self . uiQueryTREE . clear ( ) self . uiGroupingTXT . setText ( '' ) self . uiSortingTXT . setText ( '' ) | 11,160 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbrecordsetedit/xorbrecordsetedit.py#L216-L223 | [
"def",
"remove_stale_javascripts",
"(",
"portal",
")",
":",
"logger",
".",
"info",
"(",
"\"Removing stale javascripts ...\"",
")",
"for",
"js",
"in",
"JAVASCRIPTS_TO_REMOVE",
":",
"logger",
".",
"info",
"(",
"\"Unregistering JS %s\"",
"%",
"js",
")",
"portal",
".",
"portal_javascripts",
".",
"unregisterResource",
"(",
"js",
")"
] |
Saves the changes from the ui to this widgets record instance . | def save ( self ) : record = self . record ( ) if not record : logger . warning ( 'No record has been defined for %s.' % self ) return False if not self . signalsBlocked ( ) : self . aboutToSaveRecord . emit ( record ) self . aboutToSave . emit ( ) values = self . saveValues ( ) # ignore columns that are the same (fixes bugs in encrypted columns)
check = values . copy ( ) for column_name , value in check . items ( ) : try : equals = value == record . recordValue ( column_name ) except UnicodeWarning : equals = False if equals : check . pop ( column_name ) # check to see if nothing has changed
if not check and record . isRecord ( ) : if not self . signalsBlocked ( ) : self . recordSaved . emit ( record ) self . saved . emit ( ) self . _saveSignalBlocked = False else : self . _saveSignalBlocked = True if self . autoCommitOnSave ( ) : status , result = record . commit ( ) if status == 'errored' : if 'db_error' in result : msg = nativestring ( result [ 'db_error' ] ) else : msg = 'An unknown database error has occurred.' QMessageBox . information ( self , 'Commit Error' , msg ) return False return True # validate the modified values
success , msg = record . validateValues ( check ) if ( not success ) : QMessageBox . information ( None , 'Could Not Save' , msg ) return False record . setRecordValues ( * * values ) success , msg = record . validateRecord ( ) if not success : QMessageBox . information ( None , 'Could Not Save' , msg ) return False if ( self . autoCommitOnSave ( ) ) : result = record . commit ( ) if 'errored' in result : QMessageBox . information ( None , 'Could Not Save' , msg ) return False if ( not self . signalsBlocked ( ) ) : self . recordSaved . emit ( record ) self . saved . emit ( ) self . _saveSignalBlocked = False else : self . _saveSignalBlocked = True return True | 11,161 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbrecordwidget.py#L201-L275 | [
"def",
"_get_certificate",
"(",
"cert_url",
")",
":",
"global",
"_cache",
"if",
"cert_url",
"in",
"_cache",
":",
"cert",
"=",
"_cache",
"[",
"cert_url",
"]",
"if",
"cert",
".",
"has_expired",
"(",
")",
":",
"_cache",
"=",
"{",
"}",
"else",
":",
"return",
"cert",
"url",
"=",
"urlparse",
"(",
"cert_url",
")",
"host",
"=",
"url",
".",
"netloc",
".",
"lower",
"(",
")",
"path",
"=",
"posixpath",
".",
"normpath",
"(",
"url",
".",
"path",
")",
"# Sanity check location so we don't get some random person's cert.",
"if",
"url",
".",
"scheme",
"!=",
"'https'",
"or",
"host",
"not",
"in",
"[",
"'s3.amazonaws.com'",
",",
"'s3.amazonaws.com:443'",
"]",
"or",
"not",
"path",
".",
"startswith",
"(",
"'/echo.api/'",
")",
":",
"log",
".",
"error",
"(",
"'invalid cert location %s'",
",",
"cert_url",
")",
"return",
"resp",
"=",
"urlopen",
"(",
"cert_url",
")",
"if",
"resp",
".",
"getcode",
"(",
")",
"!=",
"200",
":",
"log",
".",
"error",
"(",
"'failed to download certificate'",
")",
"return",
"cert",
"=",
"crypto",
".",
"load_certificate",
"(",
"crypto",
".",
"FILETYPE_PEM",
",",
"resp",
".",
"read",
"(",
")",
")",
"if",
"cert",
".",
"has_expired",
"(",
")",
"or",
"cert",
".",
"get_subject",
"(",
")",
".",
"CN",
"!=",
"'echo-api.amazon.com'",
":",
"log",
".",
"error",
"(",
"'certificate expired or invalid'",
")",
"return",
"_cache",
"[",
"cert_url",
"]",
"=",
"cert",
"return",
"cert"
] |
Adds a dynamic namespace element to the end of the Namespace . | def add_dynamic_element ( self , name , description ) : self . _pb . add ( Name = name , Description = description , Value = "*" ) return self | 11,162 | https://github.com/intelsdi-x/snap-plugin-lib-py/blob/8da5d00ac5f9d2b48a7239563ac7788209891ca4/snap_plugin/v1/namespace.py#L71-L90 | [
"def",
"load_projects",
"(",
"self",
")",
":",
"server_config",
"=",
"Config",
".",
"instance",
"(",
")",
".",
"get_section_config",
"(",
"\"Server\"",
")",
"projects_path",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"server_config",
".",
"get",
"(",
"\"projects_path\"",
",",
"\"~/GNS3/projects\"",
")",
")",
"os",
".",
"makedirs",
"(",
"projects_path",
",",
"exist_ok",
"=",
"True",
")",
"try",
":",
"for",
"project_path",
"in",
"os",
".",
"listdir",
"(",
"projects_path",
")",
":",
"project_dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"projects_path",
",",
"project_path",
")",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"project_dir",
")",
":",
"for",
"file",
"in",
"os",
".",
"listdir",
"(",
"project_dir",
")",
":",
"if",
"file",
".",
"endswith",
"(",
"\".gns3\"",
")",
":",
"try",
":",
"yield",
"from",
"self",
".",
"load_project",
"(",
"os",
".",
"path",
".",
"join",
"(",
"project_dir",
",",
"file",
")",
",",
"load",
"=",
"False",
")",
"except",
"(",
"aiohttp",
".",
"web_exceptions",
".",
"HTTPConflict",
",",
"NotImplementedError",
")",
":",
"pass",
"# Skip not compatible projects",
"except",
"OSError",
"as",
"e",
":",
"log",
".",
"error",
"(",
"str",
"(",
"e",
")",
")"
] |
Starts and returns a Selenium webdriver object for Chrome . | def Chrome ( headless = False , user_agent = None , profile_path = None ) : chromedriver = drivers . ChromeDriver ( headless , user_agent , profile_path ) return chromedriver . driver | 11,163 | https://github.com/SkullTech/webdriver-start/blob/26285fd84c4deaf8906828e0ec0758a650b7ba49/wdstart/webdriver.py#L9-L31 | [
"def",
"cfg",
"(",
"self",
")",
":",
"config",
"=",
"LStruct",
"(",
"self",
".",
"defaults",
")",
"module",
"=",
"config",
"[",
"'CONFIG'",
"]",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"CONFIGURATION_ENVIRON_VARIABLE",
",",
"config",
"[",
"'CONFIG'",
"]",
")",
"if",
"module",
":",
"try",
":",
"module",
"=",
"import_module",
"(",
"module",
")",
"config",
".",
"update",
"(",
"{",
"name",
":",
"getattr",
"(",
"module",
",",
"name",
")",
"for",
"name",
"in",
"dir",
"(",
"module",
")",
"if",
"name",
"==",
"name",
".",
"upper",
"(",
")",
"and",
"not",
"name",
".",
"startswith",
"(",
"'_'",
")",
"}",
")",
"except",
"ImportError",
"as",
"exc",
":",
"config",
".",
"CONFIG",
"=",
"None",
"self",
".",
"logger",
".",
"error",
"(",
"\"Error importing %s: %s\"",
",",
"module",
",",
"exc",
")",
"# Patch configuration from ENV",
"for",
"name",
"in",
"config",
":",
"if",
"name",
".",
"startswith",
"(",
"'_'",
")",
"or",
"name",
"!=",
"name",
".",
"upper",
"(",
")",
"or",
"name",
"not",
"in",
"os",
".",
"environ",
":",
"continue",
"try",
":",
"config",
"[",
"name",
"]",
"=",
"json",
".",
"loads",
"(",
"os",
".",
"environ",
"[",
"name",
"]",
")",
"except",
"ValueError",
":",
"pass",
"return",
"config"
] |
Starts and returns a Selenium webdriver object for Firefox . | def Firefox ( headless = False , user_agent = None , profile_path = None ) : firefoxdriver = drivers . FirefoxDriver ( headless , user_agent , profile_path ) return firefoxdriver . driver | 11,164 | https://github.com/SkullTech/webdriver-start/blob/26285fd84c4deaf8906828e0ec0758a650b7ba49/wdstart/webdriver.py#L34-L56 | [
"def",
"push_to_server",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"customer_profile_id",
":",
"try",
":",
"self",
".",
"customer_profile",
"=",
"CustomerProfile",
".",
"objects",
".",
"get",
"(",
"customer",
"=",
"self",
".",
"customer",
")",
"except",
"CustomerProfile",
".",
"DoesNotExist",
":",
"pass",
"if",
"self",
".",
"payment_profile_id",
":",
"response",
"=",
"update_payment_profile",
"(",
"self",
".",
"customer_profile",
".",
"profile_id",
",",
"self",
".",
"payment_profile_id",
",",
"self",
".",
"raw_data",
",",
"self",
".",
"raw_data",
",",
")",
"response",
".",
"raise_if_error",
"(",
")",
"elif",
"self",
".",
"customer_profile_id",
":",
"output",
"=",
"create_payment_profile",
"(",
"self",
".",
"customer_profile",
".",
"profile_id",
",",
"self",
".",
"raw_data",
",",
"self",
".",
"raw_data",
",",
")",
"response",
"=",
"output",
"[",
"'response'",
"]",
"response",
".",
"raise_if_error",
"(",
")",
"self",
".",
"payment_profile_id",
"=",
"output",
"[",
"'payment_profile_id'",
"]",
"else",
":",
"output",
"=",
"add_profile",
"(",
"self",
".",
"customer",
".",
"id",
",",
"self",
".",
"raw_data",
",",
"self",
".",
"raw_data",
",",
")",
"response",
"=",
"output",
"[",
"'response'",
"]",
"response",
".",
"raise_if_error",
"(",
")",
"self",
".",
"customer_profile",
"=",
"CustomerProfile",
".",
"objects",
".",
"create",
"(",
"customer",
"=",
"self",
".",
"customer",
",",
"profile_id",
"=",
"output",
"[",
"'profile_id'",
"]",
",",
"sync",
"=",
"False",
",",
")",
"self",
".",
"payment_profile_id",
"=",
"output",
"[",
"'payment_profile_ids'",
"]",
"[",
"0",
"]"
] |
Cancels the current lookup . | def cancel ( self ) : if self . _running : self . interrupt ( ) self . _running = False self . _cancelled = True self . loadingFinished . emit ( ) | 11,165 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/xorblookupworker.py#L56-L64 | [
"def",
"experimental",
"(",
"message",
")",
":",
"def",
"f__",
"(",
"f",
")",
":",
"def",
"f_",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"warnings",
"import",
"warn",
"warn",
"(",
"message",
",",
"category",
"=",
"ExperimentalWarning",
",",
"stacklevel",
"=",
"2",
")",
"return",
"f",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"f_",
".",
"__name__",
"=",
"f",
".",
"__name__",
"f_",
".",
"__doc__",
"=",
"f",
".",
"__doc__",
"f_",
".",
"__dict__",
".",
"update",
"(",
"f",
".",
"__dict__",
")",
"return",
"f_",
"return",
"f__"
] |
Loads the records for this instance in a batched mode . | def loadBatch ( self , records ) : try : curr_batch = records [ : self . batchSize ( ) ] next_batch = records [ self . batchSize ( ) : ] curr_records = list ( curr_batch ) if self . _preloadColumns : for record in curr_records : record . recordValues ( self . _preloadColumns ) if len ( curr_records ) == self . batchSize ( ) : self . loadedRecords [ object , object ] . emit ( curr_records , next_batch ) else : self . loadedRecords [ object ] . emit ( curr_records ) except ConnectionLostError : self . connectionLost . emit ( ) except Interruption : pass | 11,166 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/xorblookupworker.py#L104-L127 | [
"def",
"make_crossroad_router",
"(",
"source",
",",
"drain",
"=",
"False",
")",
":",
"sink_observer",
"=",
"None",
"def",
"on_sink_subscribe",
"(",
"observer",
")",
":",
"nonlocal",
"sink_observer",
"sink_observer",
"=",
"observer",
"def",
"dispose",
"(",
")",
":",
"nonlocal",
"sink_observer",
"sink_observer",
"=",
"None",
"return",
"dispose",
"def",
"route_crossroad",
"(",
"request",
")",
":",
"def",
"on_response_subscribe",
"(",
"observer",
")",
":",
"def",
"on_next_source",
"(",
"i",
")",
":",
"if",
"type",
"(",
"i",
")",
"is",
"cyclotron",
".",
"Drain",
":",
"observer",
".",
"on_completed",
"(",
")",
"else",
":",
"observer",
".",
"on_next",
"(",
"i",
")",
"source_disposable",
"=",
"source",
".",
"subscribe",
"(",
"on_next",
"=",
"on_next_source",
",",
"on_error",
"=",
"lambda",
"e",
":",
"observer",
".",
"on_error",
"(",
"e",
")",
",",
"on_completed",
"=",
"lambda",
":",
"observer",
".",
"on_completed",
"(",
")",
")",
"def",
"on_next_request",
"(",
"i",
")",
":",
"if",
"sink_observer",
"is",
"not",
"None",
":",
"sink_observer",
".",
"on_next",
"(",
"i",
")",
"def",
"on_request_completed",
"(",
")",
":",
"if",
"sink_observer",
"is",
"not",
"None",
":",
"if",
"drain",
"is",
"True",
":",
"sink_observer",
".",
"on_next",
"(",
"cyclotron",
".",
"Drain",
"(",
")",
")",
"else",
":",
"sink_observer",
".",
"on_completed",
"(",
")",
"request_disposable",
"=",
"request",
".",
"subscribe",
"(",
"on_next",
"=",
"on_next_request",
",",
"on_error",
"=",
"observer",
".",
"on_error",
",",
"on_completed",
"=",
"on_request_completed",
")",
"def",
"dispose",
"(",
")",
":",
"source_disposable",
".",
"dispose",
"(",
")",
"request_disposable",
".",
"dispose",
"(",
")",
"return",
"dispose",
"return",
"Observable",
".",
"create",
"(",
"on_response_subscribe",
")",
"return",
"Observable",
".",
"create",
"(",
"on_sink_subscribe",
")",
",",
"route_crossroad"
] |
Names by which the instance can be retrieved . | def names ( self ) : if getattr ( self , 'key' , None ) is None : result = [ ] else : result = [ self . key ] if hasattr ( self , 'aliases' ) : result . extend ( self . aliases ) return result | 11,167 | https://github.com/xflr6/fileconfig/blob/473d65f6442eb1ac49ada0b6e56cab45f8018c15/fileconfig/bases.py#L27-L35 | [
"def",
"fmt_border",
"(",
"self",
",",
"dimensions",
",",
"t",
"=",
"'m'",
",",
"border_style",
"=",
"'utf8.a'",
",",
"border_formating",
"=",
"{",
"}",
")",
":",
"cells",
"=",
"[",
"]",
"for",
"column",
"in",
"dimensions",
":",
"cells",
".",
"append",
"(",
"self",
".",
"bchar",
"(",
"'h'",
",",
"t",
",",
"border_style",
")",
"*",
"(",
"dimensions",
"[",
"column",
"]",
"+",
"2",
")",
")",
"border",
"=",
"'{}{}{}'",
".",
"format",
"(",
"self",
".",
"bchar",
"(",
"'l'",
",",
"t",
",",
"border_style",
")",
",",
"self",
".",
"bchar",
"(",
"'m'",
",",
"t",
",",
"border_style",
")",
".",
"join",
"(",
"cells",
")",
",",
"self",
".",
"bchar",
"(",
"'r'",
",",
"t",
",",
"border_style",
")",
")",
"return",
"self",
".",
"fmt_text",
"(",
"border",
",",
"*",
"*",
"border_formating",
")"
] |
Updates the layout for the graphics within this scene . | def autoLayout ( self , size = None ) : if size is None : size = self . _view . size ( ) self . setSceneRect ( 0 , 0 , size . width ( ) , size . height ( ) ) for item in self . items ( ) : if isinstance ( item , XWalkthroughGraphic ) : item . autoLayout ( size ) | 11,168 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xwalkthroughwidget/xwalkthroughscene.py#L46-L56 | [
"def",
"ekssum",
"(",
"handle",
",",
"segno",
")",
":",
"handle",
"=",
"ctypes",
".",
"c_int",
"(",
"handle",
")",
"segno",
"=",
"ctypes",
".",
"c_int",
"(",
"segno",
")",
"segsum",
"=",
"stypes",
".",
"SpiceEKSegSum",
"(",
")",
"libspice",
".",
"ekssum_c",
"(",
"handle",
",",
"segno",
",",
"ctypes",
".",
"byref",
"(",
"segsum",
")",
")",
"return",
"segsum"
] |
Prepares the items for display . | def prepare ( self ) : for item in self . items ( ) : if isinstance ( item , XWalkthroughGraphic ) : item . prepare ( ) | 11,169 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xwalkthroughwidget/xwalkthroughscene.py#L83-L89 | [
"def",
"get",
"(",
"self",
",",
"file_lines",
",",
"index",
")",
":",
"line",
"=",
"file_lines",
"[",
"index",
"]",
"start_index",
"=",
"line",
".",
"find",
"(",
"'# '",
")",
"+",
"2",
"# Start index for header text",
"start_tag",
"=",
"line",
".",
"rfind",
"(",
"self",
".",
"_open",
")",
"# Start index of AnchorHub tag",
"end_tag",
"=",
"line",
".",
"rfind",
"(",
"self",
".",
"_close",
")",
"# End index of AnchorHub tag",
"# The magic '+1' below knocks out the hash '#' character from extraction",
"tag",
"=",
"line",
"[",
"start_tag",
"+",
"len",
"(",
"self",
".",
"_open",
")",
"+",
"1",
":",
"end_tag",
"]",
"string",
"=",
"line",
"[",
"start_index",
":",
"start_tag",
"]",
"return",
"[",
"tag",
",",
"string",
"]"
] |
Lays out this widget within the graphics scene . | def autoLayout ( self , size ) : # update the children alignment
direction = self . property ( 'direction' , QtGui . QBoxLayout . TopToBottom ) x = 0 y = 0 base_off_x = 0 base_off_y = 0 for i , child in enumerate ( self . childItems ( ) ) : off_x = 6 + child . boundingRect ( ) . width ( ) off_y = 6 + child . boundingRect ( ) . height ( ) if direction == QtGui . QBoxLayout . TopToBottom : child . setPos ( x , y ) y += off_y elif direction == QtGui . QBoxLayout . BottomToTop : y -= off_y child . setPos ( x , y ) if not base_off_y : base_off_y = off_y elif direction == QtGui . QBoxLayout . LeftToRight : child . setPos ( x , y ) x += off_x else : x -= off_x child . setPos ( x , y ) if not base_off_x : base_off_x = off_x #----------------------------------------------------------------------
pos = self . property ( 'pos' ) align = self . property ( 'align' ) offset = self . property ( 'offset' ) rect = self . boundingRect ( ) if pos : x = pos . x ( ) y = pos . y ( ) elif align == QtCore . Qt . AlignCenter : x = ( size . width ( ) - rect . width ( ) ) / 2.0 y = ( size . height ( ) - rect . height ( ) ) / 2.0 else : if align & QtCore . Qt . AlignLeft : x = 0 elif align & QtCore . Qt . AlignRight : x = ( size . width ( ) - rect . width ( ) ) else : x = ( size . width ( ) - rect . width ( ) ) / 2.0 if align & QtCore . Qt . AlignTop : y = 0 elif align & QtCore . Qt . AlignBottom : y = ( size . height ( ) - rect . height ( ) ) else : y = ( size . height ( ) - rect . height ( ) ) / 2.0 if offset : x += offset . x ( ) y += offset . y ( ) x += base_off_x y += base_off_y self . setPos ( x , y ) | 11,170 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xwalkthroughwidget/xwalkthroughgraphics.py#L105-L177 | [
"def",
"__parseThunks",
"(",
"self",
",",
"thunkRVA",
",",
"importSection",
")",
":",
"offset",
"=",
"to_offset",
"(",
"thunkRVA",
",",
"importSection",
")",
"table_offset",
"=",
"0",
"thunks",
"=",
"[",
"]",
"while",
"True",
":",
"thunk",
"=",
"IMAGE_THUNK_DATA",
".",
"from_buffer",
"(",
"importSection",
".",
"raw",
",",
"offset",
")",
"offset",
"+=",
"sizeof",
"(",
"IMAGE_THUNK_DATA",
")",
"if",
"thunk",
".",
"Ordinal",
"==",
"0",
":",
"break",
"thunkData",
"=",
"ThunkData",
"(",
"header",
"=",
"thunk",
",",
"rva",
"=",
"table_offset",
"+",
"thunkRVA",
",",
"ordinal",
"=",
"None",
",",
"importByName",
"=",
"None",
")",
"if",
"to_offset",
"(",
"thunk",
".",
"AddressOfData",
",",
"importSection",
")",
">",
"0",
"and",
"to_offset",
"(",
"thunk",
".",
"AddressOfData",
",",
"importSection",
")",
"<",
"len",
"(",
"self",
".",
"_bytes",
")",
":",
"self",
".",
"__parseThunkData",
"(",
"thunkData",
",",
"importSection",
")",
"thunks",
".",
"append",
"(",
"thunkData",
")",
"table_offset",
"+=",
"4",
"return",
"thunks"
] |
Prepares this graphic item to be displayed . | def prepare ( self ) : text = self . property ( 'caption' ) if text : capw = int ( self . property ( 'caption_width' , 0 ) ) item = self . addText ( text , capw ) | 11,171 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xwalkthroughwidget/xwalkthroughgraphics.py#L209-L216 | [
"def",
"register",
"(",
"self",
",",
"resource",
",",
"event",
",",
"trigger",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
"AristaTrunkDriver",
",",
"self",
")",
".",
"register",
"(",
"resource",
",",
"event",
",",
"trigger",
",",
"kwargs",
")",
"registry",
".",
"subscribe",
"(",
"self",
".",
"subport_create",
",",
"resources",
".",
"SUBPORTS",
",",
"events",
".",
"AFTER_CREATE",
")",
"registry",
".",
"subscribe",
"(",
"self",
".",
"subport_delete",
",",
"resources",
".",
"SUBPORTS",
",",
"events",
".",
"AFTER_DELETE",
")",
"registry",
".",
"subscribe",
"(",
"self",
".",
"trunk_create",
",",
"resources",
".",
"TRUNK",
",",
"events",
".",
"AFTER_CREATE",
")",
"registry",
".",
"subscribe",
"(",
"self",
".",
"trunk_update",
",",
"resources",
".",
"TRUNK",
",",
"events",
".",
"AFTER_UPDATE",
")",
"registry",
".",
"subscribe",
"(",
"self",
".",
"trunk_delete",
",",
"resources",
".",
"TRUNK",
",",
"events",
".",
"AFTER_DELETE",
")",
"self",
".",
"core_plugin",
"=",
"directory",
".",
"get_plugin",
"(",
")",
"LOG",
".",
"debug",
"(",
"\"Arista trunk driver initialized.\"",
")"
] |
Prepares the information for this graphic . | def prepare ( self ) : # determine if we already have a snapshot setup
pixmap = self . property ( 'pixmap' ) if pixmap is not None : return super ( XWalkthroughSnapshot , self ) . prepare ( ) # otherwise, setup the snapshot
widget = self . property ( 'widget' ) if type ( widget ) in ( unicode , str ) : widget = self . findReference ( widget ) if not widget : return super ( XWalkthroughSnapshot , self ) . prepare ( ) # test if this is an overlay option
if self . property ( 'overlay' ) and widget . parent ( ) : ref = self . referenceWidget ( ) if ref == widget : pos = QtCore . QPoint ( 0 , 0 ) else : glbl_pos = widget . mapToGlobal ( QtCore . QPoint ( 0 , 0 ) ) pos = ref . mapFromGlobal ( glbl_pos ) self . setProperty ( 'pos' , pos ) # crop out the options
crop = self . property ( 'crop' , QtCore . QRect ( 0 , 0 , 0 , 0 ) ) if crop : rect = widget . rect ( ) if crop . width ( ) : rect . setWidth ( crop . width ( ) ) if crop . height ( ) : rect . setHeight ( crop . height ( ) ) if crop . x ( ) : rect . setX ( rect . width ( ) - crop . x ( ) ) if crop . y ( ) : rect . setY ( rect . height ( ) - crop . y ( ) ) pixmap = QtGui . QPixmap . grabWidget ( widget , rect ) else : pixmap = QtGui . QPixmap . grabWidget ( widget ) scaled = self . property ( 'scaled' ) if scaled : pixmap = pixmap . scaled ( pixmap . width ( ) * scaled , pixmap . height ( ) * scaled , QtCore . Qt . KeepAspectRatio , QtCore . Qt . SmoothTransformation ) kwds = { } kwds [ 'whatsThis' ] = widget . whatsThis ( ) kwds [ 'toolTip' ] = widget . toolTip ( ) kwds [ 'windowTitle' ] = widget . windowTitle ( ) kwds [ 'objectName' ] = widget . objectName ( ) self . setProperty ( 'caption' , self . property ( 'caption' , '' ) . format ( * * kwds ) ) self . setProperty ( 'pixmap' , pixmap ) self . addPixmap ( pixmap ) return super ( XWalkthroughSnapshot , self ) . prepare ( ) | 11,172 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xwalkthroughwidget/xwalkthroughgraphics.py#L280-L342 | [
"def",
"insert_seperator_results",
"(",
"results",
")",
":",
"sepbench",
"=",
"BenchmarkResult",
"(",
"*",
"[",
"' '",
"*",
"w",
"for",
"w",
"in",
"COLUMN_WIDTHS",
"]",
")",
"last_bm",
"=",
"None",
"for",
"r",
"in",
"results",
":",
"if",
"last_bm",
"is",
"None",
":",
"last_bm",
"=",
"r",
".",
"benchmark",
"elif",
"last_bm",
"!=",
"r",
".",
"benchmark",
":",
"yield",
"sepbench",
"last_bm",
"=",
"r",
".",
"benchmark",
"yield",
"r"
] |
Get the path the actual layer file . | def get_real_layer_path ( self , path ) : filename = path . split ( '/' ) [ - 1 ] local_path = path filetype = os . path . splitext ( filename ) [ 1 ] # Url if re . match ( r'^[a-zA-Z]+://' , path ) : local_path = os . path . join ( DATA_DIRECTORY , filename ) if not os . path . exists ( local_path ) : sys . stdout . write ( '* Downloading %s...\n' % filename ) self . download_file ( path , local_path ) elif self . args . redownload : os . remove ( local_path ) sys . stdout . write ( '* Redownloading %s...\n' % filename ) self . download_file ( path , local_path ) # Non-existant file elif not os . path . exists ( local_path ) : raise Exception ( '%s does not exist' % local_path ) real_path = path # Zip files if filetype == '.zip' : slug = os . path . splitext ( filename ) [ 0 ] real_path = os . path . join ( DATA_DIRECTORY , slug ) if not os . path . exists ( real_path ) : sys . stdout . write ( '* Unzipping...\n' ) self . unzip_file ( local_path , real_path ) return real_path | 11,173 | https://github.com/nprapps/mapturner/blob/fc9747c9d1584af2053bff3df229a460ef2a5f62/mapturner/__init__.py#L122-L157 | [
"def",
"_DeleteClientStats",
"(",
"self",
",",
"limit",
",",
"retention_time",
",",
"cursor",
"=",
"None",
")",
":",
"cursor",
".",
"execute",
"(",
"\"DELETE FROM client_stats WHERE timestamp < FROM_UNIXTIME(%s) LIMIT %s\"",
",",
"[",
"mysql_utils",
".",
"RDFDatetimeToTimestamp",
"(",
"retention_time",
")",
",",
"limit",
"]",
")",
"return",
"cursor",
".",
"rowcount"
] |
Download a file from a remote host . | def download_file ( self , url , local_path ) : response = requests . get ( url , stream = True ) with open ( local_path , 'wb' ) as f : for chunk in tqdm ( response . iter_content ( chunk_size = 1024 ) , unit = 'KB' ) : if chunk : # filter out keep-alive new chunks f . write ( chunk ) f . flush ( ) | 11,174 | https://github.com/nprapps/mapturner/blob/fc9747c9d1584af2053bff3df229a460ef2a5f62/mapturner/__init__.py#L159-L169 | [
"def",
"total_rated_level",
"(",
"octave_frequencies",
")",
":",
"sums",
"=",
"0.0",
"for",
"band",
"in",
"OCTAVE_BANDS",
".",
"keys",
"(",
")",
":",
"if",
"band",
"not",
"in",
"octave_frequencies",
":",
"continue",
"if",
"octave_frequencies",
"[",
"band",
"]",
"is",
"None",
":",
"continue",
"if",
"octave_frequencies",
"[",
"band",
"]",
"==",
"0",
":",
"continue",
"sums",
"+=",
"pow",
"(",
"10.0",
",",
"(",
"(",
"float",
"(",
"octave_frequencies",
"[",
"band",
"]",
")",
"+",
"OCTAVE_BANDS",
"[",
"band",
"]",
"[",
"1",
"]",
")",
"/",
"10.0",
")",
")",
"level",
"=",
"10.0",
"*",
"math",
".",
"log10",
"(",
"sums",
")",
"return",
"level"
] |
Unzip a local file into a specified directory . | def unzip_file ( self , zip_path , output_path ) : with zipfile . ZipFile ( zip_path , 'r' ) as z : z . extractall ( output_path ) | 11,175 | https://github.com/nprapps/mapturner/blob/fc9747c9d1584af2053bff3df229a460ef2a5f62/mapturner/__init__.py#L171-L176 | [
"def",
"get_rng",
"(",
"obj",
"=",
"None",
")",
":",
"seed",
"=",
"(",
"id",
"(",
"obj",
")",
"+",
"os",
".",
"getpid",
"(",
")",
"+",
"int",
"(",
"datetime",
".",
"now",
"(",
")",
".",
"strftime",
"(",
"\"%Y%m%d%H%M%S%f\"",
")",
")",
")",
"%",
"4294967295",
"if",
"_RNG_SEED",
"is",
"not",
"None",
":",
"seed",
"=",
"_RNG_SEED",
"return",
"np",
".",
"random",
".",
"RandomState",
"(",
"seed",
")"
] |
Process a layer using ogr2ogr . | def process_ogr2ogr ( self , name , layer , input_path ) : output_path = os . path . join ( TEMP_DIRECTORY , '%s.json' % name ) if os . path . exists ( output_path ) : os . remove ( output_path ) ogr2ogr_cmd = [ 'ogr2ogr' , '-f' , 'GeoJSON' , '-clipsrc' , self . config [ 'bbox' ] ] if 'where' in layer : ogr2ogr_cmd . extend ( [ '-where' , '"%s"' % layer [ 'where' ] ] ) ogr2ogr_cmd . extend ( [ output_path , input_path ] ) sys . stdout . write ( '* Running ogr2ogr\n' ) if self . args . verbose : sys . stdout . write ( ' %s\n' % ' ' . join ( ogr2ogr_cmd ) ) r = envoy . run ( ' ' . join ( ogr2ogr_cmd ) ) if r . status_code != 0 : sys . stderr . write ( r . std_err ) return output_path | 11,176 | https://github.com/nprapps/mapturner/blob/fc9747c9d1584af2053bff3df229a460ef2a5f62/mapturner/__init__.py#L193-L228 | [
"def",
"_update_axes_color",
"(",
"self",
",",
"color",
")",
":",
"prop_x",
"=",
"self",
".",
"axes_actor",
".",
"GetXAxisCaptionActor2D",
"(",
")",
".",
"GetCaptionTextProperty",
"(",
")",
"prop_y",
"=",
"self",
".",
"axes_actor",
".",
"GetYAxisCaptionActor2D",
"(",
")",
".",
"GetCaptionTextProperty",
"(",
")",
"prop_z",
"=",
"self",
".",
"axes_actor",
".",
"GetZAxisCaptionActor2D",
"(",
")",
".",
"GetCaptionTextProperty",
"(",
")",
"if",
"color",
"is",
"None",
":",
"color",
"=",
"rcParams",
"[",
"'font'",
"]",
"[",
"'color'",
"]",
"color",
"=",
"parse_color",
"(",
"color",
")",
"for",
"prop",
"in",
"[",
"prop_x",
",",
"prop_y",
",",
"prop_z",
"]",
":",
"prop",
".",
"SetColor",
"(",
"color",
"[",
"0",
"]",
",",
"color",
"[",
"1",
"]",
",",
"color",
"[",
"2",
"]",
")",
"prop",
".",
"SetShadow",
"(",
"False",
")",
"return"
] |
Process layer using topojson . | def process_topojson ( self , name , layer , input_path ) : output_path = os . path . join ( TEMP_DIRECTORY , '%s.topojson' % name ) # Use local topojson binary topojson_binary = 'node_modules/bin/topojson' if not os . path . exists ( topojson_binary ) : # try with global topojson binary topojson_binary = 'topojson' topo_cmd = [ topojson_binary , '-o' , output_path ] if 'id-property' in layer : topo_cmd . extend ( [ '--id-property' , layer [ 'id-property' ] ] ) if layer . get ( 'all-properties' , False ) : topo_cmd . append ( '-p' ) elif 'properties' in layer : topo_cmd . extend ( [ '-p' , ',' . join ( layer [ 'properties' ] ) ] ) topo_cmd . extend ( [ '--' , input_path ] ) sys . stdout . write ( '* Running TopoJSON\n' ) if self . args . verbose : sys . stdout . write ( ' %s\n' % ' ' . join ( topo_cmd ) ) r = envoy . run ( ' ' . join ( topo_cmd ) ) if r . status_code != 0 : sys . stderr . write ( r . std_err ) return output_path | 11,177 | https://github.com/nprapps/mapturner/blob/fc9747c9d1584af2053bff3df229a460ef2a5f62/mapturner/__init__.py#L230-L275 | [
"def",
"delete_group",
"(",
"group_id",
",",
"purge_data",
",",
"*",
"*",
"kwargs",
")",
":",
"user_id",
"=",
"kwargs",
".",
"get",
"(",
"'user_id'",
")",
"try",
":",
"group_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"ResourceGroup",
")",
".",
"filter",
"(",
"ResourceGroup",
".",
"id",
"==",
"group_id",
")",
".",
"one",
"(",
")",
"except",
"NoResultFound",
":",
"raise",
"ResourceNotFoundError",
"(",
"\"Group %s not found\"",
"%",
"(",
"group_id",
")",
")",
"group_items",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"ResourceGroupItem",
")",
".",
"filter",
"(",
"ResourceGroupItem",
".",
"group_id",
"==",
"group_id",
")",
".",
"all",
"(",
")",
"for",
"gi",
"in",
"group_items",
":",
"db",
".",
"DBSession",
".",
"delete",
"(",
"gi",
")",
"if",
"purge_data",
"==",
"'Y'",
":",
"_purge_datasets_unique_to_resource",
"(",
"'GROUP'",
",",
"group_id",
")",
"log",
".",
"info",
"(",
"\"Deleting group %s, id=%s\"",
",",
"group_i",
".",
"name",
",",
"group_id",
")",
"group_i",
".",
"network",
".",
"check_write_permission",
"(",
"user_id",
")",
"db",
".",
"DBSession",
".",
"delete",
"(",
"group_i",
")",
"db",
".",
"DBSession",
".",
"flush",
"(",
")"
] |
Merge data layers into a single topojson file . | def merge ( self , paths ) : # Use local topojson binary topojson_binary = 'node_modules/bin/topojson' if not os . path . exists ( topojson_binary ) : # try with global topojson binary topojson_binary = 'topojson' merge_cmd = '%(binary)s -o %(output_path)s --bbox -p -- %(paths)s' % { 'output_path' : self . args . output_path , 'paths' : ' ' . join ( paths ) , 'binary' : topojson_binary } sys . stdout . write ( 'Merging layers\n' ) if self . args . verbose : sys . stdout . write ( ' %s\n' % merge_cmd ) r = envoy . run ( merge_cmd ) if r . status_code != 0 : sys . stderr . write ( r . std_err ) | 11,178 | https://github.com/nprapps/mapturner/blob/fc9747c9d1584af2053bff3df229a460ef2a5f62/mapturner/__init__.py#L277-L303 | [
"def",
"delete_unused_subjects",
"(",
")",
":",
"# This causes Django to create a single join (check with query.query)",
"query",
"=",
"d1_gmn",
".",
"app",
".",
"models",
".",
"Subject",
".",
"objects",
".",
"all",
"(",
")",
"query",
"=",
"query",
".",
"filter",
"(",
"scienceobject_submitter__isnull",
"=",
"True",
")",
"query",
"=",
"query",
".",
"filter",
"(",
"scienceobject_rights_holder__isnull",
"=",
"True",
")",
"query",
"=",
"query",
".",
"filter",
"(",
"eventlog__isnull",
"=",
"True",
")",
"query",
"=",
"query",
".",
"filter",
"(",
"permission__isnull",
"=",
"True",
")",
"query",
"=",
"query",
".",
"filter",
"(",
"whitelistforcreateupdatedelete__isnull",
"=",
"True",
")",
"logger",
".",
"debug",
"(",
"'Deleting {} unused subjects:'",
".",
"format",
"(",
"query",
".",
"count",
"(",
")",
")",
")",
"for",
"s",
"in",
"query",
".",
"all",
"(",
")",
":",
"logging",
".",
"debug",
"(",
"' {}'",
".",
"format",
"(",
"s",
".",
"subject",
")",
")",
"query",
".",
"delete",
"(",
")"
] |
Creates a new menu with the given name . | def createMenu ( self ) : name , accepted = QInputDialog . getText ( self , 'Create Menu' , 'Name: ' ) if ( accepted ) : self . addMenuItem ( self . createMenuItem ( name ) , self . uiMenuTREE . currentItem ( ) ) | 11,179 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xmenutemplatewidget/xmenutemplatewidget.py#L120-L130 | [
"def",
"_read_body_by_chunk",
"(",
"self",
",",
"response",
",",
"file",
",",
"raw",
"=",
"False",
")",
":",
"reader",
"=",
"ChunkedTransferReader",
"(",
"self",
".",
"_connection",
")",
"file_is_async",
"=",
"hasattr",
"(",
"file",
",",
"'drain'",
")",
"while",
"True",
":",
"chunk_size",
",",
"data",
"=",
"yield",
"from",
"reader",
".",
"read_chunk_header",
"(",
")",
"self",
".",
"_data_event_dispatcher",
".",
"notify_read",
"(",
"data",
")",
"if",
"raw",
":",
"file",
".",
"write",
"(",
"data",
")",
"if",
"not",
"chunk_size",
":",
"break",
"while",
"True",
":",
"content",
",",
"data",
"=",
"yield",
"from",
"reader",
".",
"read_chunk_body",
"(",
")",
"self",
".",
"_data_event_dispatcher",
".",
"notify_read",
"(",
"data",
")",
"if",
"not",
"content",
":",
"if",
"raw",
":",
"file",
".",
"write",
"(",
"data",
")",
"break",
"content",
"=",
"self",
".",
"_decompress_data",
"(",
"content",
")",
"if",
"file",
":",
"file",
".",
"write",
"(",
"content",
")",
"if",
"file_is_async",
":",
"yield",
"from",
"file",
".",
"drain",
"(",
")",
"content",
"=",
"self",
".",
"_flush_decompressor",
"(",
")",
"if",
"file",
":",
"file",
".",
"write",
"(",
"content",
")",
"if",
"file_is_async",
":",
"yield",
"from",
"file",
".",
"drain",
"(",
")",
"trailer_data",
"=",
"yield",
"from",
"reader",
".",
"read_trailer",
"(",
")",
"self",
".",
"_data_event_dispatcher",
".",
"notify_read",
"(",
"trailer_data",
")",
"if",
"file",
"and",
"raw",
":",
"file",
".",
"write",
"(",
"trailer_data",
")",
"if",
"file_is_async",
":",
"yield",
"from",
"file",
".",
"drain",
"(",
")",
"response",
".",
"fields",
".",
"parse",
"(",
"trailer_data",
")"
] |
Removes the item from the menu . | def removeItem ( self ) : item = self . uiMenuTREE . currentItem ( ) if ( not item ) : return opts = QMessageBox . Yes | QMessageBox . No answer = QMessageBox . question ( self , 'Remove Item' , 'Are you sure you want to remove this ' ' item?' , opts ) if ( answer == QMessageBox . Yes ) : parent = item . parent ( ) if ( parent ) : parent . takeChild ( parent . indexOfChild ( item ) ) else : tree = self . uiMenuTREE tree . takeTopLevelItem ( tree . indexOfTopLevelItem ( item ) ) | 11,180 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xmenutemplatewidget/xmenutemplatewidget.py#L248-L269 | [
"def",
"compare_documents",
"(",
"self",
",",
"file_1",
",",
"file_2",
",",
"file_1_content_type",
"=",
"None",
",",
"file_2_content_type",
"=",
"None",
",",
"file_1_label",
"=",
"None",
",",
"file_2_label",
"=",
"None",
",",
"model",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"file_1",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'file_1 must be provided'",
")",
"if",
"file_2",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'file_2 must be provided'",
")",
"headers",
"=",
"{",
"}",
"if",
"'headers'",
"in",
"kwargs",
":",
"headers",
".",
"update",
"(",
"kwargs",
".",
"get",
"(",
"'headers'",
")",
")",
"sdk_headers",
"=",
"get_sdk_headers",
"(",
"'compare-comply'",
",",
"'V1'",
",",
"'compare_documents'",
")",
"headers",
".",
"update",
"(",
"sdk_headers",
")",
"params",
"=",
"{",
"'version'",
":",
"self",
".",
"version",
",",
"'file_1_label'",
":",
"file_1_label",
",",
"'file_2_label'",
":",
"file_2_label",
",",
"'model'",
":",
"model",
"}",
"form_data",
"=",
"{",
"}",
"form_data",
"[",
"'file_1'",
"]",
"=",
"(",
"None",
",",
"file_1",
",",
"file_1_content_type",
"or",
"'application/octet-stream'",
")",
"form_data",
"[",
"'file_2'",
"]",
"=",
"(",
"None",
",",
"file_2",
",",
"file_2_content_type",
"or",
"'application/octet-stream'",
")",
"url",
"=",
"'/v1/comparison'",
"response",
"=",
"self",
".",
"request",
"(",
"method",
"=",
"'POST'",
",",
"url",
"=",
"url",
",",
"headers",
"=",
"headers",
",",
"params",
"=",
"params",
",",
"files",
"=",
"form_data",
",",
"accept_json",
"=",
"True",
")",
"return",
"response"
] |
Prompts the user to supply a new name for the menu . | def renameMenu ( self ) : item = self . uiMenuTREE . currentItem ( ) name , accepted = QInputDialog . getText ( self , 'Rename Menu' , 'Name:' , QLineEdit . Normal , item . text ( 0 ) ) if ( accepted ) : item . setText ( 0 , name ) | 11,181 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xmenutemplatewidget/xmenutemplatewidget.py#L271-L283 | [
"def",
"delete_dimension",
"(",
"dimension_id",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"dimension",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Dimension",
")",
".",
"filter",
"(",
"Dimension",
".",
"id",
"==",
"dimension_id",
")",
".",
"one",
"(",
")",
"db",
".",
"DBSession",
".",
"query",
"(",
"Unit",
")",
".",
"filter",
"(",
"Unit",
".",
"dimension_id",
"==",
"dimension",
".",
"id",
")",
".",
"delete",
"(",
")",
"db",
".",
"DBSession",
".",
"delete",
"(",
"dimension",
")",
"db",
".",
"DBSession",
".",
"flush",
"(",
")",
"return",
"True",
"except",
"NoResultFound",
":",
"raise",
"ResourceNotFoundError",
"(",
"\"Dimension (dimension_id=%s) does not exist\"",
"%",
"(",
"dimension_id",
")",
")"
] |
Creates a menu to display for the editing of template information . | def showMenu ( self ) : item = self . uiMenuTREE . currentItem ( ) menu = QMenu ( self ) act = menu . addAction ( 'Add Menu...' ) act . setIcon ( QIcon ( projexui . resources . find ( 'img/folder.png' ) ) ) act . triggered . connect ( self . createMenu ) if ( item and item . data ( 0 , Qt . UserRole ) == 'menu' ) : act = menu . addAction ( 'Rename Menu...' ) ico = QIcon ( projexui . resources . find ( 'img/edit.png' ) ) act . setIcon ( ico ) act . triggered . connect ( self . renameMenu ) act = menu . addAction ( 'Add Separator' ) act . setIcon ( QIcon ( projexui . resources . find ( 'img/ui/splitter.png' ) ) ) act . triggered . connect ( self . createSeparator ) menu . addSeparator ( ) act = menu . addAction ( 'Remove Item' ) act . setIcon ( QIcon ( projexui . resources . find ( 'img/remove.png' ) ) ) act . triggered . connect ( self . removeItem ) act . setEnabled ( item is not None ) menu . exec_ ( QCursor . pos ( ) ) | 11,182 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xmenutemplatewidget/xmenutemplatewidget.py#L350-L378 | [
"def",
"store_vector",
"(",
"self",
",",
"v",
",",
"data",
"=",
"None",
")",
":",
"# We will store the normalized vector (used during retrieval)",
"nv",
"=",
"unitvec",
"(",
"v",
")",
"# Store vector in each bucket of all hashes",
"for",
"lshash",
"in",
"self",
".",
"lshashes",
":",
"for",
"bucket_key",
"in",
"lshash",
".",
"hash_vector",
"(",
"v",
")",
":",
"#print 'Storying in bucket %s one vector' % bucket_key",
"self",
".",
"storage",
".",
"store_vector",
"(",
"lshash",
".",
"hash_name",
",",
"bucket_key",
",",
"nv",
",",
"data",
")"
] |
Inititialise the extension with the app object . | def init_app ( self , app ) : host = app . config . get ( 'STATS_HOSTNAME' , 'localhost' ) port = app . config . get ( 'STATS_PORT' , 8125 ) base_key = app . config . get ( 'STATS_BASE_KEY' , app . name ) client = _StatsClient ( host = host , port = port , prefix = base_key , ) app . before_request ( client . flask_time_start ) app . after_request ( client . flask_time_end ) if not hasattr ( app , 'extensions' ) : app . extensions = { } app . extensions . setdefault ( 'stats' , { } ) app . extensions [ 'stats' ] [ self ] = client return client | 11,183 | https://github.com/solarnz/Flask-Stats/blob/de9e476a30a98c9aa0eec4b9a18b150c905c382e/flask_stats/__init__.py#L50-L73 | [
"def",
"clean_cache",
"(",
"self",
")",
":",
"now",
"=",
"int",
"(",
"time",
".",
"time",
"(",
")",
")",
"t_to_del",
"=",
"[",
"]",
"for",
"timestamp",
"in",
"self",
".",
"cache",
":",
"if",
"timestamp",
"<",
"now",
":",
"t_to_del",
".",
"append",
"(",
"timestamp",
")",
"for",
"timestamp",
"in",
"t_to_del",
":",
"del",
"self",
".",
"cache",
"[",
"timestamp",
"]",
"# same for the invalid cache",
"t_to_del",
"=",
"[",
"]",
"for",
"timestamp",
"in",
"self",
".",
"invalid_cache",
":",
"if",
"timestamp",
"<",
"now",
":",
"t_to_del",
".",
"append",
"(",
"timestamp",
")",
"for",
"timestamp",
"in",
"t_to_del",
":",
"del",
"self",
".",
"invalid_cache",
"[",
"timestamp",
"]"
] |
Decorator to specify test dependencies | def depends ( func = None , after = None , before = None , priority = None ) : if not ( func is None or inspect . ismethod ( func ) or inspect . isfunction ( func ) ) : raise ValueError ( "depends decorator can only be used on functions or methods" ) if not ( after or before or priority ) : raise ValueError ( "depends decorator needs at least one argument" ) # This avoids some nesting in the decorator # If called without func the decorator was called with optional args # so we'll return a function with those args filled in. if func is None : return partial ( depends , after = after , before = before , priority = priority ) def self_check ( a , b ) : if a == b : raise ValueError ( "Test '{}' cannot depend on itself" . format ( a ) ) def handle_dep ( conditions , _before = True ) : if conditions : if type ( conditions ) is not list : conditions = [ conditions ] for cond in conditions : if hasattr ( cond , '__call__' ) : cond = cond . __name__ self_check ( func . __name__ , cond ) if _before : soft_dependencies [ cond ] . add ( func . __name__ ) else : dependencies [ func . __name__ ] . add ( cond ) handle_dep ( before ) handle_dep ( after , False ) if priority : priorities [ func . __name__ ] = priority @ wraps ( func ) def inner ( * args , * * kwargs ) : return func ( * args , * * kwargs ) return inner | 11,184 | https://github.com/Zitrax/nose-dep/blob/fd29c95e0e5eb2dbd821f6566b72dfcf42631226/nosedep.py#L84-L127 | [
"def",
"_read_columns_file",
"(",
"f",
")",
":",
"try",
":",
"columns",
"=",
"json",
".",
"loads",
"(",
"open",
"(",
"f",
",",
"'r'",
")",
".",
"read",
"(",
")",
",",
"object_pairs_hook",
"=",
"collections",
".",
"OrderedDict",
")",
"except",
"Exception",
"as",
"err",
":",
"raise",
"InvalidColumnsFileError",
"(",
"\"There was an error while reading {0}: {1}\"",
".",
"format",
"(",
"f",
",",
"err",
")",
")",
"# Options are not supported yet:",
"if",
"'__options'",
"in",
"columns",
":",
"del",
"columns",
"[",
"'__options'",
"]",
"return",
"columns"
] |
Split a sequence into two iterables without looping twice | def split_on_condition ( seq , condition ) : l1 , l2 = tee ( ( condition ( item ) , item ) for item in seq ) return ( i for p , i in l1 if p ) , ( i for p , i in l2 if not p ) | 11,185 | https://github.com/Zitrax/nose-dep/blob/fd29c95e0e5eb2dbd821f6566b72dfcf42631226/nosedep.py#L195-L198 | [
"def",
"exclude",
"(",
"requestContext",
",",
"seriesList",
",",
"pattern",
")",
":",
"regex",
"=",
"re",
".",
"compile",
"(",
"pattern",
")",
"return",
"[",
"s",
"for",
"s",
"in",
"seriesList",
"if",
"not",
"regex",
".",
"search",
"(",
"s",
".",
"name",
")",
"]"
] |
Prepare suite and determine test ordering | def prepare_suite ( self , suite ) : all_tests = { } for s in suite : m = re . match ( r'(\w+)\s+\(.+\)' , str ( s ) ) if m : name = m . group ( 1 ) else : name = str ( s ) . split ( '.' ) [ - 1 ] all_tests [ name ] = s return self . orderTests ( all_tests , suite ) | 11,186 | https://github.com/Zitrax/nose-dep/blob/fd29c95e0e5eb2dbd821f6566b72dfcf42631226/nosedep.py#L268-L279 | [
"def",
"public_broadcaster",
"(",
")",
":",
"while",
"__websocket_server_running__",
":",
"pipein",
"=",
"open",
"(",
"PUBLIC_PIPE",
",",
"'r'",
")",
"line",
"=",
"pipein",
".",
"readline",
"(",
")",
".",
"replace",
"(",
"'\\n'",
",",
"''",
")",
".",
"replace",
"(",
"'\\r'",
",",
"''",
")",
"if",
"line",
"!=",
"''",
":",
"WebSocketHandler",
".",
"broadcast",
"(",
"line",
")",
"print",
"line",
"remaining_lines",
"=",
"pipein",
".",
"read",
"(",
")",
"pipein",
".",
"close",
"(",
")",
"pipeout",
"=",
"open",
"(",
"PUBLIC_PIPE",
",",
"'w'",
")",
"pipeout",
".",
"write",
"(",
"remaining_lines",
")",
"pipeout",
".",
"close",
"(",
")",
"else",
":",
"pipein",
".",
"close",
"(",
")",
"time",
".",
"sleep",
"(",
"0.05",
")"
] |
Returns an error string if any of the dependencies did not run | def dependency_ran ( self , test ) : for d in ( self . test_name ( i ) for i in dependencies [ test ] ) : if d not in self . ok_results : return "Required test '{}' did not run (does it exist?)" . format ( d ) return None | 11,187 | https://github.com/Zitrax/nose-dep/blob/fd29c95e0e5eb2dbd821f6566b72dfcf42631226/nosedep.py#L332-L337 | [
"def",
"is_registration_possible",
"(",
"self",
",",
"user_info",
")",
":",
"return",
"self",
".",
"get_accessibility",
"(",
")",
".",
"is_open",
"(",
")",
"and",
"self",
".",
"_registration",
".",
"is_open",
"(",
")",
"and",
"self",
".",
"is_user_accepted_by_access_control",
"(",
"user_info",
")"
] |
Return the path to the source file of the given class . | def class_path ( cls ) : if cls . __module__ == '__main__' : path = None else : path = os . path . dirname ( inspect . getfile ( cls ) ) if not path : path = os . getcwd ( ) return os . path . realpath ( path ) | 11,188 | https://github.com/xflr6/fileconfig/blob/473d65f6442eb1ac49ada0b6e56cab45f8018c15/fileconfig/tools.py#L10-L20 | [
"def",
"cancelRealTimeBars",
"(",
"self",
",",
"bars",
":",
"RealTimeBarList",
")",
":",
"self",
".",
"client",
".",
"cancelRealTimeBars",
"(",
"bars",
".",
"reqId",
")",
"self",
".",
"wrapper",
".",
"endSubscription",
"(",
"bars",
")"
] |
Return the path to the source file of the current frames caller . | def caller_path ( steps = 1 ) : frame = sys . _getframe ( steps + 1 ) try : path = os . path . dirname ( frame . f_code . co_filename ) finally : del frame if not path : path = os . getcwd ( ) return os . path . realpath ( path ) | 11,189 | https://github.com/xflr6/fileconfig/blob/473d65f6442eb1ac49ada0b6e56cab45f8018c15/fileconfig/tools.py#L23-L35 | [
"def",
"split",
"(",
"self",
",",
"amount",
")",
":",
"split_objs",
"=",
"list",
"(",
"self",
".",
"all",
"(",
")",
")",
"if",
"not",
"split_objs",
":",
"raise",
"NoSplitsFoundForRecurringCost",
"(",
")",
"portions",
"=",
"[",
"split_obj",
".",
"portion",
"for",
"split_obj",
"in",
"split_objs",
"]",
"split_amounts",
"=",
"ratio_split",
"(",
"amount",
",",
"portions",
")",
"return",
"[",
"(",
"split_objs",
"[",
"i",
"]",
",",
"split_amount",
")",
"for",
"i",
",",
"split_amount",
"in",
"enumerate",
"(",
"split_amounts",
")",
"]"
] |
Resource builder with resources url | def resource ( self , * resources ) : resources = tuple ( self . resources ) + resources return Resource ( self . client , resources ) | 11,190 | https://github.com/viatoriche/microservices/blob/3510563edd15dc6131b8a948d6062856cd904ac7/microservices/http/client.py#L57-L64 | [
"def",
"_get_exception_class_from_status_code",
"(",
"status_code",
")",
":",
"if",
"status_code",
"==",
"'100'",
":",
"return",
"None",
"exc_class",
"=",
"STATUS_CODE_MAPPING",
".",
"get",
"(",
"status_code",
")",
"if",
"not",
"exc_class",
":",
"# No status code match, return the \"I don't know wtf this is\"",
"# exception class.",
"return",
"STATUS_CODE_MAPPING",
"[",
"'UNKNOWN'",
"]",
"else",
":",
"# Match found, yay.",
"return",
"exc_class"
] |
Match version with the constraint . | def match ( self , version ) : if isinstance ( version , basestring ) : version = Version . parse ( version ) return self . operator ( version , self . version ) | 11,191 | https://github.com/pmuller/versions/blob/951bc3fd99b6a675190f11ee0752af1d7ff5b440/versions/constraint.py#L61-L72 | [
"async",
"def",
"stream",
"(",
"self",
",",
"version",
"=",
"\"1.1\"",
",",
"keep_alive",
"=",
"False",
",",
"keep_alive_timeout",
"=",
"None",
")",
":",
"headers",
"=",
"self",
".",
"get_headers",
"(",
"version",
",",
"keep_alive",
"=",
"keep_alive",
",",
"keep_alive_timeout",
"=",
"keep_alive_timeout",
",",
")",
"self",
".",
"protocol",
".",
"push_data",
"(",
"headers",
")",
"await",
"self",
".",
"protocol",
".",
"drain",
"(",
")",
"await",
"self",
".",
"streaming_fn",
"(",
"self",
")",
"self",
".",
"protocol",
".",
"push_data",
"(",
"b\"0\\r\\n\\r\\n\"",
")"
] |
build Arduino sketch and display results | def warnings ( filename , board = 'pro' , hwpack = 'arduino' , mcu = '' , f_cpu = '' , extra_lib = '' , ver = '' , # home='auto', backend = 'arscons' , ) : cc = Arduino ( board = board , hwpack = hwpack , mcu = mcu , f_cpu = f_cpu , extra_lib = extra_lib , ver = ver , # home=home, backend = backend , ) cc . build ( filename ) print 'backend:' , cc . backend print 'MCU:' , cc . mcu_compiler ( ) # print 'avr-gcc:', AvrGcc().version() print print ( '=============================================' ) print ( 'SIZE' ) print ( '=============================================' ) print 'program:' , cc . size ( ) . program_bytes print 'data:' , cc . size ( ) . data_bytes core_warnings = [ x for x in cc . warnings if 'gcc' in x ] + [ x for x in cc . warnings if 'core' in x ] lib_warnings = [ x for x in cc . warnings if 'lib_' in x ] notsketch_warnings = core_warnings + lib_warnings sketch_warnings = [ x for x in cc . warnings if x not in notsketch_warnings ] print print ( '=============================================' ) print ( 'WARNINGS' ) print ( '=============================================' ) print print ( 'core' ) print ( '-------------------' ) print ( '\n' . join ( core_warnings ) ) print print ( 'lib' ) print ( '-------------------' ) print ( '\n' . join ( lib_warnings ) ) print print ( 'sketch' ) print ( '-------------------' ) print ( '\n' . join ( sketch_warnings ) ) | 11,192 | https://github.com/ponty/pyavrutils/blob/7a396a25b3ac076ede07b5cd5cbd416ebb578a28/pyavrutils/cli/arduino/build.py#L7-L64 | [
"def",
"on_balance_volume",
"(",
"close_data",
",",
"volume",
")",
":",
"catch_errors",
".",
"check_for_input_len_diff",
"(",
"close_data",
",",
"volume",
")",
"obv",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"volume",
")",
")",
"obv",
"[",
"0",
"]",
"=",
"1",
"for",
"idx",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"obv",
")",
")",
":",
"if",
"close_data",
"[",
"idx",
"]",
">",
"close_data",
"[",
"idx",
"-",
"1",
"]",
":",
"obv",
"[",
"idx",
"]",
"=",
"obv",
"[",
"idx",
"-",
"1",
"]",
"+",
"volume",
"[",
"idx",
"]",
"elif",
"close_data",
"[",
"idx",
"]",
"<",
"close_data",
"[",
"idx",
"-",
"1",
"]",
":",
"obv",
"[",
"idx",
"]",
"=",
"obv",
"[",
"idx",
"-",
"1",
"]",
"-",
"volume",
"[",
"idx",
"]",
"elif",
"close_data",
"[",
"idx",
"]",
"==",
"close_data",
"[",
"idx",
"-",
"1",
"]",
":",
"obv",
"[",
"idx",
"]",
"=",
"obv",
"[",
"idx",
"-",
"1",
"]",
"return",
"obv"
] |
Saves the current settings for the actions in the list and exits the dialog . | def accept ( self ) : if ( not self . save ( ) ) : return for i in range ( self . uiActionTREE . topLevelItemCount ( ) ) : item = self . uiActionTREE . topLevelItem ( i ) action = item . action ( ) action . setShortcut ( QKeySequence ( item . text ( 1 ) ) ) super ( XShortcutDialog , self ) . accept ( ) | 11,193 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/dialogs/xshortcutdialog/xshortcutdialog.py#L77-L90 | [
"def",
"create_weight",
"(",
"self",
",",
"weight",
",",
"date",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"_build_url",
"(",
"'my'",
",",
"'body'",
",",
"'weight'",
")",
"data",
"=",
"{",
"'weightInKilograms'",
":",
"weight",
"}",
"if",
"date",
":",
"if",
"not",
"date",
".",
"is_aware",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"provided date is not timezone aware\"",
")",
"data",
".",
"update",
"(",
"date",
"=",
"date",
".",
"isoformat",
"(",
")",
")",
"headers",
"=",
"{",
"'Content-Type'",
":",
"'application/json; charset=utf8'",
"}",
"r",
"=",
"self",
".",
"session",
".",
"post",
"(",
"url",
",",
"data",
"=",
"json",
".",
"dumps",
"(",
"data",
")",
",",
"headers",
"=",
"headers",
")",
"r",
".",
"raise_for_status",
"(",
")",
"return",
"r"
] |
Clears the current settings for the current action . | def clear ( self ) : item = self . uiActionTREE . currentItem ( ) if ( not item ) : return self . uiShortcutTXT . setText ( '' ) item . setText ( 1 , '' ) | 11,194 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/dialogs/xshortcutdialog/xshortcutdialog.py#L103-L112 | [
"async",
"def",
"list_keys",
"(",
"request",
":",
"web",
".",
"Request",
")",
"->",
"web",
".",
"Response",
":",
"keys_dir",
"=",
"CONFIG",
"[",
"'wifi_keys_dir'",
"]",
"keys",
":",
"List",
"[",
"Dict",
"[",
"str",
",",
"str",
"]",
"]",
"=",
"[",
"]",
"# TODO(mc, 2018-10-24): add last modified info to keys for sort purposes",
"for",
"path",
"in",
"os",
".",
"listdir",
"(",
"keys_dir",
")",
":",
"full_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"keys_dir",
",",
"path",
")",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"full_path",
")",
":",
"in_path",
"=",
"os",
".",
"listdir",
"(",
"full_path",
")",
"if",
"len",
"(",
"in_path",
")",
">",
"1",
":",
"log",
".",
"warning",
"(",
"\"Garbage in key dir for key {}\"",
".",
"format",
"(",
"path",
")",
")",
"keys",
".",
"append",
"(",
"{",
"'uri'",
":",
"'/wifi/keys/{}'",
".",
"format",
"(",
"path",
")",
",",
"'id'",
":",
"path",
",",
"'name'",
":",
"os",
".",
"path",
".",
"basename",
"(",
"in_path",
"[",
"0",
"]",
")",
"}",
")",
"else",
":",
"log",
".",
"warning",
"(",
"\"Garbage in wifi keys dir: {}\"",
".",
"format",
"(",
"full_path",
")",
")",
"return",
"web",
".",
"json_response",
"(",
"{",
"'keys'",
":",
"keys",
"}",
",",
"status",
"=",
"200",
")"
] |
Updates the action to edit based on the current item . | def updateAction ( self ) : item = self . uiActionTREE . currentItem ( ) if ( item ) : action = item . action ( ) else : action = QAction ( ) self . uiShortcutTXT . setText ( action . shortcut ( ) . toString ( ) ) | 11,195 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/dialogs/xshortcutdialog/xshortcutdialog.py#L181-L191 | [
"def",
"get_namespaces",
"(",
"self",
")",
":",
"cursor",
"=",
"self",
".",
"cursor",
"cursor",
".",
"execute",
"(",
"'SELECT DISTINCT namespace FROM gauged_statistics'",
")",
"return",
"[",
"namespace",
"for",
"namespace",
",",
"in",
"cursor",
"]"
] |
flatten the return values of the mite api . | def declassify ( to_remove , * args , * * kwargs ) : def argdecorate ( fn ) : """ enable the to_remove argument to the decorator. """ # wrap the function to get the original docstring @ wraps ( fn ) def declassed ( * args , * * kwargs ) : # call the method ret = fn ( * args , * * kwargs ) # catch errors that are thrown by the api try : # ensure that ret is a list if type ( ret ) is list : return [ r [ to_remove ] for r in ret ] return ret [ to_remove ] except KeyError : return ret return declassed return argdecorate | 11,196 | https://github.com/damnit/pymite/blob/1e9b9bf6aef790af2d8781f9f77c098c54ca0342/pymite/utils.py#L13-L32 | [
"def",
"set_sqlite_pragmas",
"(",
"self",
")",
":",
"def",
"_pragmas_on_connect",
"(",
"dbapi_con",
",",
"con_record",
")",
":",
"dbapi_con",
".",
"execute",
"(",
"\"PRAGMA journal_mode = WAL;\"",
")",
"event",
".",
"listen",
"(",
"self",
".",
"engine",
",",
"\"connect\"",
",",
"_pragmas_on_connect",
")"
] |
remove the keys with None values . | def clean_dict ( d ) : ktd = list ( ) for k , v in d . items ( ) : if not v : ktd . append ( k ) elif type ( v ) is dict : d [ k ] = clean_dict ( v ) for k in ktd : d . pop ( k ) return d | 11,197 | https://github.com/damnit/pymite/blob/1e9b9bf6aef790af2d8781f9f77c098c54ca0342/pymite/utils.py#L35-L45 | [
"def",
"_orthogonalize",
"(",
"X",
")",
":",
"if",
"X",
".",
"size",
"==",
"X",
".",
"shape",
"[",
"0",
"]",
":",
"return",
"X",
"from",
"scipy",
".",
"linalg",
"import",
"pinv",
",",
"norm",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"X",
".",
"shape",
"[",
"1",
"]",
")",
":",
"X",
"[",
":",
",",
"i",
"]",
"-=",
"np",
".",
"dot",
"(",
"np",
".",
"dot",
"(",
"X",
"[",
":",
",",
"i",
"]",
",",
"X",
"[",
":",
",",
":",
"i",
"]",
")",
",",
"pinv",
"(",
"X",
"[",
":",
",",
":",
"i",
"]",
")",
")",
"# X[:, i] /= norm(X[:, i])",
"return",
"X"
] |
Loads the children for this item . | def load ( self ) : if self . _loaded : return self . setChildIndicatorPolicy ( self . DontShowIndicatorWhenChildless ) self . _loaded = True column = self . schemaColumn ( ) if not column . isReference ( ) : return ref = column . referenceModel ( ) if not ref : return columns = sorted ( ref . schema ( ) . columns ( ) , key = lambda x : x . name ( ) . strip ( '_' ) ) for column in columns : XOrbColumnItem ( self , column ) | 11,198 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbcolumnnavigator.py#L49-L70 | [
"def",
"start_vm",
"(",
"access_token",
",",
"subscription_id",
",",
"resource_group",
",",
"vm_name",
")",
":",
"endpoint",
"=",
"''",
".",
"join",
"(",
"[",
"get_rm_endpoint",
"(",
")",
",",
"'/subscriptions/'",
",",
"subscription_id",
",",
"'/resourceGroups/'",
",",
"resource_group",
",",
"'/providers/Microsoft.Compute/virtualMachines/'",
",",
"vm_name",
",",
"'/start'",
",",
"'?api-version='",
",",
"COMP_API",
"]",
")",
"return",
"do_post",
"(",
"endpoint",
",",
"''",
",",
"access_token",
")"
] |
Resets the data for this navigator . | def refresh ( self ) : self . setUpdatesEnabled ( False ) self . blockSignals ( True ) self . clear ( ) tableType = self . tableType ( ) if not tableType : self . setUpdatesEnabled ( True ) self . blockSignals ( False ) return schema = tableType . schema ( ) columns = list ( sorted ( schema . columns ( ) , key = lambda x : x . name ( ) . strip ( '_' ) ) ) for column in columns : XOrbColumnItem ( self , column ) self . setUpdatesEnabled ( True ) self . blockSignals ( False ) | 11,199 | https://github.com/bitesofcode/projexui/blob/f18a73bec84df90b034ca69b9deea118dbedfc4d/projexui/widgets/xorbcolumnnavigator.py#L185-L205 | [
"def",
"Close",
"(",
"self",
")",
":",
"self",
".",
"schema",
"=",
"{",
"}",
"if",
"self",
".",
"_is_open",
":",
"self",
".",
"_database",
".",
"close",
"(",
")",
"self",
".",
"_database",
"=",
"None",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"_temp_db_file_path",
")",
":",
"try",
":",
"os",
".",
"remove",
"(",
"self",
".",
"_temp_db_file_path",
")",
"except",
"(",
"OSError",
",",
"IOError",
")",
"as",
"exception",
":",
"logger",
".",
"warning",
"(",
"(",
"'Unable to remove temporary copy: {0:s} of SQLite database: '",
"'{1:s} with error: {2!s}'",
")",
".",
"format",
"(",
"self",
".",
"_temp_db_file_path",
",",
"self",
".",
"_filename",
",",
"exception",
")",
")",
"self",
".",
"_temp_db_file_path",
"=",
"''",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"_temp_wal_file_path",
")",
":",
"try",
":",
"os",
".",
"remove",
"(",
"self",
".",
"_temp_wal_file_path",
")",
"except",
"(",
"OSError",
",",
"IOError",
")",
"as",
"exception",
":",
"logger",
".",
"warning",
"(",
"(",
"'Unable to remove temporary copy: {0:s} of SQLite database: '",
"'{1:s} with error: {2!s}'",
")",
".",
"format",
"(",
"self",
".",
"_temp_wal_file_path",
",",
"self",
".",
"_filename",
",",
"exception",
")",
")",
"self",
".",
"_temp_wal_file_path",
"=",
"''",
"self",
".",
"_is_open",
"=",
"False"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.