How to use set_sort_key method in Slash

Best Python code snippet using slash

dhcp_objects.py

Source:dhcp_objects.py Github

copy

Full Screen

...19 self._sort_key < other._sort_key)20 def __str__(self):21 s = ''22 if hasattr(self, 'contents') and self.contents:23 map(lambda x: x.set_sort_key(), self.contents)24 if hasattr(self, 'comment') and self.comment:25 comment = ' # ' + self.comment26 else:27 comment = ''28 s += self.side + self.firstline + ' {' + comment + '\n'29 s += join_p(sorted(self.contents), prefix=self.side)30 s += self.side + '}\n'31 if hasattr(self, 'related') and self.related:32 map(lambda x: x.set_sort_key(), self.related)33 s += join_p(sorted(self.related), indent=0)34 # they print their own side35 return s36class Statement(DHCPMixin):37 TYPE = 138 def __init__(self, statement):39 self.statement = statement40 def set_sort_key(self):41 self._sort_key = self.statement42 def __eq__(self, other):43 return (isinstance(other, Statement)44 and self.statement == other.statement)45 def __hash__(self):46 return hash(self.statement)47 def __str__(self):48 return self.side + self.statement + ';\n'49class RangeStmt(Statement):50 TYPE = 051 def __init__(self, start, end):52 self.statement = 'range {0} {1}'.format(start, end)53 self.start = start54 self.end = end55 def set_sort_key(self):56 self._sort_key = (int(IPAddress(self.start)),57 int(IPAddress(self.end)))58 def __eq__(self, other):59 return (isinstance(other, RangeStmt) and self.start == other.start60 and self.end == other.end)61class Pool(DHCPMixin):62 TYPE = 263 def __init__(self, contents=None):64 self.contents = set(contents or [])65 self.firstline = 'pool'66 rs = next(ifilter(is_rangestmt, contents))67 self.start, self.end = rs.start, rs.end68 self.comment = '{} - {}'.format(self.start, self.end)69 def set_sort_key(self):70 self._sort_key = (int(IPAddress(self.start)),71 int(IPAddress(self.end)))72 def __eq__(self, other):73 return (isinstance(other, Pool) and self.start == other.start74 and self.end == other.end)75 def __hash__(self):76 return hash(self.start + self.end)77class Subnet(DHCPMixin):78 TYPE = 379 def __init__(self, netaddr, netmask, contents=None):80 self.netaddr = netaddr81 self.netmask = netmask82 self.contents = set(contents or [])83 self.firstline = 'subnet {0} netmask {1}'.format(self.netaddr,84 self.netmask)85 def set_sort_key(self):86 self._sort_key = (int(IPAddress(self.netaddr)),87 int(IPAddress(self.netmask)))88 def __eq__(self, other):89 return (isinstance(other, Subnet) and self.netaddr == other.netaddr90 and self.netmask == other.netmask)91 def __hash__(self):92 return hash(self.netaddr + self.netmask)93class Subclass(DHCPMixin):94 TYPE = 495 def __init__(self, classname, match, contents=None):96 self.classname = classname97 self.match = match98 self.contents = set(contents or [])99 self.firstline = 'subclass "{0}" {1}'.format(self.classname,100 self.match)101 def set_sort_key(self):102 self._sort_key = self.classname + self.match103 def __eq__(self, other):104 return (isinstance(other, Subclass)105 and self.classname == other.classname106 and self.match == other.match)107 def __hash__(self):108 return hash(self.classname + self.match)109 def __str__(self):110 if self.contents:111 return super(Subclass, self).__str__()112 else:113 return self.side + self.firstline + ';\n'114class Class(DHCPMixin):115 TYPE = 5116 def __init__(self, name, contents=None, related=None):117 self.name = name118 self.contents = set(contents or [])119 self.related = set(related or [])120 self.firstline = 'class "{0}"'.format(self.name)121 def set_sort_key(self):122 self._sort_key = self.name123 def __eq__(self, other):124 return isinstance(other, Class) and self.name == other.name125 def __hash__(self):126 return hash(self.name)127 def add_subclass(self, match, contents):128 self.related.add(Subclass(self.name, match, contents))129class Group(DHCPMixin):130 TYPE = 6131 def __init__(self, name, contents=None):132 self.name = name133 self.contents = set(contents or [])134 self.firstline = 'group'135 self.comment = self.name136 def set_sort_key(self):137 self._sort_key = self.name138 def __eq__(self, other):139 return isinstance(other, Group) and self.name == other.name140 def __hash__(self):141 return hash(self.name)142class Host(DHCPMixin):143 TYPE = 7144 def __init__(self, name, contents=None):145 self.name = name146 self.contents = set(contents or [])147 self.firstline = 'host ' + self.name148 def set_sort_key(self):149 self._sort_key = self.name150 def __eq__(self, other):151 return isinstance(other, Host) and self.name == other.name152 def __hash__(self):153 return hash(self.name)154class ConfigFile(DHCPMixin):155 def __init__(self, related=None):156 self.related = set(related or [])157 def add(self, obj):158 if obj:159 self.related.add(obj)160 def get_class(self, name):161 classes = ifilter(lambda x: isinstance(x, Class) and x.name == name,162 self.related)...

Full Screen

Full Screen

d90e201594dbb20b27ae18c67b5f1de57a4f7371.svn-base

Source:d90e201594dbb20b27ae18c67b5f1de57a4f7371.svn-base Github

copy

Full Screen

...28 :param param:29 :return:30 """31 self.param = param32 def set_sort_key(self, key):33 """34 :param key:35 :return:36 """37 self.sort_key = key38 def check_param(self):39 """40 检查 参数41 :return:42 """43 def parse_param(self):44 """45 解析 参数46 :return:47 """48 df = self.param49 self.mk = df.loc[Macf.Market].get(Macf.Value)50 self.fq = df.loc[Macf.Frequency].get(Macf.Value)51 print 'load param ok !'52 def get_datb_by_param(self):53 """54 根据 参数 获取 mg 句柄55 '日线': 'day',56 '周线': 'week',57 '月线': 'month',58 '季线': 'quarter',59 '年线': 'year',60 '1分钟': 'm1',61 '5分钟': 'm5',62 '15分钟': 'm15',63 '30分钟': 'm30',64 '60分钟': 'm60',65 :return:66 """67 if self.fq in Macf.QS_STOCK_DAILY:68 self.set_sort_key('date')69 else:70 self.set_sort_key('time')71 self.qttb = MongoSingleton.get_mgtb(self.mk, self.fq)72 return self.qttb73 def get_fqtb_by_param(self):74 """75 获取 复权表 句柄76 :return:77 """78 self.fqtb = MongoSingleton.get_fqtb(self.mk)79 return self.fqtb80 def get_iftb_by_param(self):81 """82 :return:83 """84 self.iftb = MongoSingleton.get_iftb(self.mk)...

Full Screen

Full Screen

load_data_base.py

Source:load_data_base.py Github

copy

Full Screen

...28 :param param:29 :return:30 """31 self.param = param32 def set_sort_key(self, key):33 """34 :param key:35 :return:36 """37 self.sort_key = key38 def check_param(self):39 """40 检查 参数41 :return:42 """43 def parse_param(self):44 """45 解析 参数46 :return:47 """48 df = self.param49 self.mk = df.loc[Macf.Market].get(Macf.Value)50 self.fq = df.loc[Macf.Frequency].get(Macf.Value)51 print 'load param ok !'52 def get_datb_by_param(self):53 """54 根据 参数 获取 mg 句柄55 '日线': 'day',56 '周线': 'week',57 '月线': 'month',58 '季线': 'quarter',59 '年线': 'year',60 '1分钟': 'm1',61 '5分钟': 'm5',62 '15分钟': 'm15',63 '30分钟': 'm30',64 '60分钟': 'm60',65 :return:66 """67 if self.fq in Macf.QS_STOCK_DAILY:68 self.set_sort_key('date')69 else:70 self.set_sort_key('time')71 self.qttb = MongoSingleton.get_mgtb(self.mk, self.fq)72 return self.qttb73 def get_fqtb_by_param(self):74 """75 获取 复权表 句柄76 :return:77 """78 self.fqtb = MongoSingleton.get_fqtb(self.mk)79 return self.fqtb80 def get_iftb_by_param(self):81 """82 :return:83 """84 self.iftb = MongoSingleton.get_iftb(self.mk)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful