How to use make_prop method in pyshould

Best Python code snippet using pyshould_python

oo_extract.py

Source:oo_extract.py Github

copy

Full Screen

...78 79 self.logger.debug(self.logprefix + "initialising new OOextracter")80 self.port = port81 self.get_desktop()82 self._load_props = ( self.make_prop("Hidden", True), )83 self._common_out_props = (84 self.make_prop("FilterFlags", "UTF-8"),85 )86 self._text_out_props = (87 (self.make_prop("FilterName", "Text (Encoded)"),) +88 self._common_out_props)89 self._csv_out_props = (90 (self.make_prop("FilterName", 'Text - txt - csv (StarCalc)'),) +91 self._common_out_props)92 self._html_out_props = (93 (self.make_prop("FilterName", 'impress_html_Export'),) +94 self._common_out_props)95 self._output_map = {96 "application/msword": self._text_out_props,97 "application/vnd.oasis.opendocument.text": self._text_out_props,98 99 "application/vnd.ms-excel" : self._csv_out_props,100 "application/vnd.oasis.opendocument.spreadsheet" : self._csv_out_props,101 "application/vnd.ms-powerpoint": self._html_out_props,102 "application/vnd.oasis.opendocument.presentation Open Office Impress": self._html_out_props,103 }104 def make_prop(self, name, value):105 prop = PropertyValue()106 prop.Name = name107 if isinstance(value, (list, tuple)):108 prop.Value = uno.Any("[]com.sun.star.beans.PropertyValue", value)109 else:110 prop.Value = value111 return prop112 113 def _filename_to_url(self, filename):114 # filename should be absolute.115 return systemPathToFileUrl(os.path.abspath(filename))116 def get_desktop(self):117 self.desktop = get_oo_desktop(self.logger, self.port)118 def _load_document(self, infile):119 props = self._load_props120 infile_url = self._filename_to_url(infile)121 try:122 return self.desktop.loadComponentFromURL(123 infile_url ,"_blank", 0, props)124 except DisposedException:125 self.logger.error(self.logprefix + "Disposed on loading: " + infile)126 self.get_desktop()127 def _unload_document(self, doc):128 try:129 doc.close(True)130 except DisposedException:131 self.logger.error(self.logprefix + 'Disposed on closing: FIXME doc name here')132 self.get_desktop()133 def _doc_text_to_stream(self, doc, contentstream, filename, mimetype):134 outprops = self._output_map.get(mimetype, self._text_out_props)135 outprops = (136 (self.make_prop("OutputStream", OutputStream(contentstream)),) +137 outprops)138 try:139 doc.storeToURL("private:stream", outprops)140 except IOException:141 self.logger.error(self.logprefix + "IOException, on storing, file is :" + 142 filename)143 self.logger.debug(self.logprefix + traceback.format_exc())144 145 def __call__(self, filename, mimetype):146 # FIXME: We want to do more - e.g. yield text in147 # e.g. paragraph blocks.148 if not self.desktop:149 self.get_desktop()150 doc = self._load_document(filename)...

Full Screen

Full Screen

policies.py

Source:policies.py Github

copy

Full Screen

...20 def __init_subclass__(cls, **kwargs):21 super().__init_subclass__(**kwargs)22 subcls_make_prop = cls.make_prop23 @functools.wraps(subcls_make_prop)24 def make_prop(self, cls, name, getter, setter, deleter):25 if self.parent and self._provide_mutators is None:26 is_enabled = getattr(self.parent, '_provide_mutators', False)27 else:28 is_enabled = self._provide_mutators29 if is_enabled:30 if not setter:31 def setter(self, value):32 set_cached_attr(self, name, value)33 if not deleter:34 def deleter(self):35 del_cached_attr(self, name)36 return subcls_make_prop(self, cls, name, getter, setter, deleter)37 cls.make_prop = make_prop38class Policy:39 wrap_getter = True40 def __init__(self):41 self.parent = None42 def __init_subclass__(cls, **kwargs):43 super().__init_subclass__(**kwargs)44 _KNOWN_POLICIES[cls.name] = cls45 def make_prop(self, cls, name, getter, setter, deleter):46 raise NotImplementedError47class DynamicPolicy(Policy):48 name = 'dynamic'49 wrap_getter = False50 def make_prop(self, cls, name, getter, setter, deleter):51 # Mark the getter as 'dynamic'. This won't have any affect on this 52 # class, but if a subclass with caching enabled incorporates this 53 # getter into an autoprop, this policy will ensure that the getter 54 # remains un-cached (as its author presumably intended).55 if getter:56 from .decorators import dynamic57 dynamic(getter)58 return property(getter, setter, deleter)59class OverwritePolicy(Policy):60 name = 'overwrite'61 def make_prop(self, cls, name, getter, setter, deleter):62 if setter:63 raise ValueError("\n".join([64 f"can't specify setter for property using the 'overwrite' cache policy",65 f"property: {cls.__qualname__}.{name}",66 f"getter: {getter or 'undefined'}",67 f"setter: {setter}",68 ]))69 if deleter:70 raise ValueError("\n".join([71 f"can't specify deleter for property using the 'overwrite' cache policy",72 f"property: {cls.__qualname__}.{name}",73 f"getter: {getter or 'undefined'}",74 f"deleter: {deleter}",75 ]))76 return cached_property(getter)77class ManualPolicy(ProvideMutatorsMixin, Policy):78 name = 'manual'79 def make_prop(self, cls, name, getter, setter, deleter):80 return CachedProperty(getter, setter, deleter)81class AutomaticPolicy(ProvideMutatorsMixin, Policy):82 name = 'automatic'83 class MemoManager:84 def __init__(self, watch):85 self._watchers = [86 _undefined_ok(attrgetter(w) if isinstance(w, str) else w)87 for w in watch88 ]89 def refresh(self, obj):90 return [id(f(obj)) for f in self._watchers]91 def is_fresh(self, prev_memo, curr_memo):92 return prev_memo == curr_memo93 def __init__(self, *, watch, **kwargs):94 super().__init__(**kwargs)95 self._manager = self.MemoManager(watch)96 def make_prop(self, cls, name, getter, setter, deleter):97 return ConditionalCachedProperty(getter, setter, deleter, self._manager)98class ImmutablePolicy(Policy):99 name = 'immutable'100 def make_prop(self, cls, name, getter, setter, deleter):101 if setter:102 raise ValueError("\n".join([103 f"can't specify setter for immutable property",104 f"property: {cls.__qualname__}.{name}",105 f"immutable getter: {getter or 'undefined'}",106 f"setter: {setter}",107 ]))108 if deleter:109 raise ValueError("\n".join([110 f"can't specify deleter for immutable property",111 f"property: {cls.__qualname__}.{name}",112 f"immutable getter: {getter or 'undefined'}",113 f"deleter: {deleter}",114 ]))...

Full Screen

Full Screen

export.py

Source:export.py Github

copy

Full Screen

...10from sqlalchemy.sql import select, func11sys.stdout = codecs.getwriter('utf8')(sys.stdout)12def make_obj(ident):13 return u"PT_OBJECT" + str(ident)14def make_prop(ident):15 return u"PT_PROPERTY" + str(ident)16class Exporter:17 database = Database()18 session = database.get_session()19 20 intro = u"<?xml version='1.0' encoding='UTF-8'?><palantir xmlns=\"http://www.palantirtech.com/pg/schema/import/\"><graph>\n\n"21 outro = u"</graph></palantir>"22 23 objects_start = u"<objectSet>"24 objects_end = u"</objectSet>"25 26 company_start = u"<object id='{}' type='com.palantir.object.business' baseType='com.palantir.object.entity'>\n" # PT_OBJECT127 company_end = u"</object>\n\n"28 29 properties_start = u"<propertySet>\n"30 properties_end= u"</propertySet>\n\n"31 32 company_name = \33 u"""<property id='{}' type='com.palantir.property.OrganizationName' linkType='com.palantir.link.Simple' role='com.palantir.role.none' keywordDisabled='false' >34 <propertyValue>35 <propertyData>{}</propertyData>36 </propertyValue>37 </property>\n\n""" # PT_PROPERTY4, name38 39 company_address = \40 u"""\n<property id='{}' type='com.palantir.property.Address' linkType='com.palantir.link.Simple' role='com.palantir.role.none' keywordDisabled='false'>41 <gisData >42 <point latitude='{}' longitude='{}' >43 </point>44 </gisData>45 <propertyValue>46 <propertyComponent type='ADDRESS1' >47 <propertyData>{}</propertyData>48 </propertyComponent>49 <propertyComponent type='CITY' >50 <propertyData>{}</propertyData>51 </propertyComponent>52 <propertyComponent type='ZIP' >53 <propertyData>{}</propertyData>54 </propertyComponent>55 </propertyValue>56 </property>\n\n""" # PT_PROPERTY3, lat, long, street + number, city, zipcode57 58 company_url = \59 u"""<property id='{}' type='com.palantir.property.URL' linkType='com.palantir.link.Simple' role='com.palantir.role.none' keywordDisabled='false' >60 <propertyValue>61 <propertyData>{}</propertyData>62 </propertyValue>63 </property>\n\n""" # PT_PROPERTY8, url64 65 def export(self, companies, filepath):66 pfile = codecs.open(filepath, "w", "utf-8")67 pfile.write(self.intro)68 pfile.write(self.objects_start)69 70 prop_id = 171 72 for i in range(len(companies)):73 pfile.write(self.company_start.format(make_obj(i+1)))74 pfile.write(self.properties_start)75 76 # company name77 pfile.write(self.company_name.format(make_prop(prop_id), companies[i].name))78 prop_id += 179 80 # address and gis data81 pfile.write(self.company_address.format(make_prop(prop_id), \82 companies[i].lat, companies[i].lng, companies[i].address, \83 companies[i].city, companies[i].zip_code))84 prop_id += 185 86 # www87 pfile.write(self.company_url.format(make_prop(prop_id), companies[i].www))88 prop_id += 189 90 pfile.write(self.properties_end)91 pfile.write(self.company_end)92 93 pfile.write(self.objects_end)94 95 # links96 97 pfile.write(self.outro)...

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 pyshould 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