Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm not exactly sure what these modules are used for. I get that they split the respective url into its components, but why would that be useful, or what is an example of when to use urlparse?
Use urlparse only if you need parameter. I have explained below why do you need parameter for.
Reference
urllib.parse.urlsplit(urlstring, scheme='', allow_fragments=True)
This is similar to urlparse(), but does not split the params from the
URL. This should generally be used instead of urlparse() if the more
recent URL syntax allowing parameters to be applied to each segment of
the path portion of the URL (see RFC 2396) is wanted.
Hostname is always useful to store in variable to use it later or adding parameter, query to hostname to get the web page you want while scraping.
Regarding Parameter:
FYI: According to RFC2396, parameter in url
Extensive testing of current client applications demonstrated that the
majority of deployed systems do not use the ";" character to indicate
trailing parameter information, and that the presence of a semicolon
in a path segment does not affect the relative parsing of that
segment. Therefore, parameters have been removed as a separate
component and may now appear in any path segment. Their influence has
been removed from the algorithm for resolving a relative URI
reference.
Parameter are useful in scraping,
e.g. if the url is http://www.example.com/products/women?color=green
When you use urlparse, you will get parameter. Now You have to change it to men so it will be http://www.example.com/products/men?color=green and kids, girl, boy so on.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
So there's PRAGMA application_id meant to identify a SQLite database that is used as the file format of a program as this specific file format. The docs say one should choose a unique signed 32 bit integer for this and link https://www.sqlite.org/src/artifact?ci=trunk&filename=magic.txt as a list of registered types. But in this file, there are only a few entries.
So I have two questions:
Is it meaningful and common to actually run this pragma when using SQLite as the file format for a program?
If so, how should that number be chosen? Simply a random number? Or somehow derived from the program's name, homepage or whatever?
Edit:
In addition to the MikeT's answer, I want to add that using this feature, a file can be identified by the file (1) using a magic definition, also including the user_version. For e. g. 123 like so:
0 string SQLite\ format\ 3
>68 belong =int(0x0000007b) Program 123 file (using SQLite)
>>60 belong x \b, Version %d
which actually might be a nice use-case, as one can simply distinguish the file from a "plain" SQLite datase in this way.
Is it meaningful and common to actually run this pragma when using
SQLite as the file format for a program?
It is a rarely used feature and would only be meaningful to a specific application which would handle it in it's own way. It's basically a variable that can be set/changed to indicate to the specific application.
Say for example the application wanted to handle encrypted/non encrypted data the value could be set to indicate an encrypted database (or be a value to indicate one of a set of different encryption methods) or a non-encrypted, thus you could have a single easily and efficiently obtained value to determine which type.
Of course other methods could be used e.g. if the user_version isn't otherwise utilised that could be used.
If so, how should that number be chosen? Simply a random number? Or
somehow derived from the program's name, homepage or whatever?
The number, if used, should probably be set simply as it would need to be interpreted into a meaningful value. A random value would probably not be of any use.
In short it's a 4 byte field in the header that can be used as desired, similar to the user version field. However, it has the advantage that is less likely to alreadey be used, as an example if using the Android SDK/API's then the user_version is utilised for versioning and should not be used (or used with great care).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
How can I set the default language based on Country and/or keyboard using the sitecore framework?
I take your point that you would expect an out of the box solution, but in fact the requirements are often perculiar to the project. That said, here are some thoughts
Creating a custom language resolver is probably the best approach.
First Attempt
I normally start by trying to use the the browser language preferences (HttpRequest.UserLanguages), which might supply the whole 2-part language 'en-GB', or sometimes just the basic language 'en'.
If this gave you the whole language, then your're done. Just get the system language with the with the same name.
If it gave you the basic language only, you need to get the country somehow.
If it didn't give you anything. You need to get the country, and find a default language for that country.
Getting the Country
If you go with the MaxMind option, you should probably use the the GeoLite version locally, as you can't rely on the DMS Geo IP lookup being performed in a timely manner.
If the lookup is successful, and you already had a basic language then you should now have 2-part language to compare against your system languages.
If the lookup was successful, but you don't have basic language, then you need to get a default. In the past, I have created a 'Language Mapping' template with 2 fields. A 'Country code' text field, and a 'Language' droplink source to the list of system language. When you have obtained the country code, you simply look it up in your mapping items, and set the context language accordingly.
Some things to consider
Remember you need to have some sort of fallback for when the lookups haven't worked.
Perhaps store the language as a cookie, so the lookup is not done every time.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is necessary to call wordpress functions(in template) unique names? I think if I call them simple names, they may conflict with plugins(if user will install in future them). Is it true?
Sorry for stupid question..
you should read all naming conventions here http://code.tutsplus.com/articles/the-wordpress-coding-standards-naming-conventions-and-function-arguments--wp-31683
Function Names
As mentioned earlier, if classes are nouns that ideally represent a single idea or single purpose, then their methods should be the actions that they are able to take. As such, they should be verbs - they should indicate what action will be taken whenever they are called.
Furthermore, the arguments that they accept should also factor into the name of the function. For example, if a function is responsible for opening a file, then its parameter should be a file name. Since our goal should make it as easy as possible to read code, then it should read something like "have the local file manager read the file having the following file name."
Use lowercase letters in variable, action, and function names (never camelCase). Separate words via underscores. Don't abbreviate variable names un-necessarily; let the code be unambiguous and self-documenting.
Of course, there are always worse - some developers resort to using single characters for their variable names (which is generally only acceptable within loops.)
Just as the Coding Standards state: Don't abbreviate variable names un-necessarily. Let the code be unambiguous and self-documenting.
Now, the truth is, code can only be unambiguous to a point.
Anyway, the bottom line is to lower case your method names, avoid all camel casing, separate by spacing, and be as specific as possible when naming your variables and avoid duplicate names.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a hidden field in a xqy page. Now I want to get its value in the same page through xquery code. The page is not refreshing. I do not want to use javascript. Is there any way to get the value of the hidden field with xquery without submitting the page.
Instead of simple HTML and outputting it directly you could use XForms. Some extensive documentation about XForms is available at http://en.wikibooks.org/wiki/XForms
You can then use a XForms-Processor (e.g. XSLTForms or betterForms), which can be used server- and client-side. This allows you to get the value of any fields (not just hidden fields) with pure X-technologies. XForms also includes MVC by default, which is quite nice. However, depending on your project and the amount of code already existing you might have to change a lot, as it is a complete technology. But normally this is the way to go to avoid JavaScript and instead using X*
You would need XQuery capabilities within the browser. MarkLogic runs server-side, so needs a round-trip (e.g. a submit). But you could have a look at XQiB: http://www.xqib.org/
HTH!
This question is vague enough to be interpreted several different ways: you will get better answers if you ask better questions.
But I'll be a little more optimistic than Geert. If the form field is in an HTML form built by a server XQuery module, the data for it must be available to that module while it is building the form. Arrange your code so that you can use it for whatever is needed, before returning the completed page.
You might be looking for some magical way to write XPath against the half-complete results of the query that's actually running. That isn't possible without some work on your part. You could arrange your code so that the form or the hidden field is a node returned by some other function, and write XPath relative to it to retrieve its value. If the hidden field was built using a request parameter from the previous HTTP request, you could call xdmp:get-request-field again. The point is to arrange your code so that you have the data you need it, when you need it.
The XQuery code at https://github.com/mblakele/cq might have some useful examples. It plays all sorts of games with form fields, both with and without JavaScript.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have been searching for some best practice guidance when using the QueryString in ASP.NET and haven't really found any.
I have found a helpful optimization article: http://dotnetperls.com/querystring
But I am more interested in answering the following questions:
Case rules? All lowercase? Pascal Case? Camel Case?
My personal preference is all lowercase, but consistency is most important.
Avoiding special characters in parameter names?
Should parameters and values be obfuscated for security purposes?
etc...
Any more guidelines would be appreciated!
Whatever is in your query string is viewable and changeable by the end user. This means they have the potential to change it to view or access data they shouldn't, or to influence the behavior of your site/app. So it goes without saying that you trust nothing on the query string, and check everything before you use it. When you check it, don't check for things that are wrong with it (that could be an infinite list), instead check for things that are correct. If even one of your checks fails then you should discard the query string data, or treat it as suspect. If you have encrypted or encoded the data on the query string it can still have unintended side effects if the user messes with it and you blindly trust it, even if the user's changes were nonsensical due to the encoding.
The one approach I take with storing sensitive data in the query string is to not do it; instead I will store the sensitive data server side (in the Session, Cache or a table in the database), and then I will have a randomly generated key (usually a GUID) in the query string to identify it, so the URL would look like this:
http://myurl.com/myPage.aspx?secretKey=73FA4A5A85A44C75ABB5E323569628D3
It is rather difficult to brute force a GUID and the chances of a GUID collision are infinitesimally small, so if the end user messes with the query string then they end up getting nothing.
This approach also works well when I need to store many things and the querystring starts to become too long - the data needing to be tracked can be kept in an object which is then stored in Session or Cache, and once again a GUID is used as its key.
My 5 cents:
if you have a page that can be called by other people, like
http://myurl.com/myPage.aspx?secretKey=73FA4A5A85A44C75ABB5E323569628D3
then you don't want them to experience problems when they misspell the K in secretKey by not making it a capital letter.
So here my rules:
Do it all lowercase. Never uppercase, because there are some small letters that don't have a corresponding uppercase letter such as the German double s.
QueryString["mykey"].ToLower().Equals("73FA4A5A85A44C75ABB5E323569628D3")
is a bad idea, because QueryString["mykey"] might be NULL (Exception NULL reference).
No complicated things like if string.IsNullOrEmpty() if else if object.equals(querykey, "comparison"). Simply use StringComparer.OrdinalIgnoreCase.Equals(key, "73FA4A5A85A44C75ABB5E323569628D3"), this works on NULL, returns false, no additional null/emtpy check needed.
I think there is no better answer between slugster and Stefan. Best to do both referring to guids and using lower case, so the example above would actually read http://myurl.com/mypage.aspx?secretkey=73fa4a5a85a44c75abb5e323569628d3